diff --git a/tools/regression/pthread/cv_cancel1/cv_cancel1.c b/tools/regression/pthread/cv_cancel1/cv_cancel1.c index 2ae94c5a9f1c..fdc50a866411 100644 --- a/tools/regression/pthread/cv_cancel1/cv_cancel1.c +++ b/tools/regression/pthread/cv_cancel1/cv_cancel1.c @@ -1,86 +1,87 @@ /*- * Copyright (c) 2006, David Xu * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice unmodified, this list of conditions, and the following * disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD$ * */ #include #include #include #define NLOOPS 10 -pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER; -pthread_cond_t cv = PTHREAD_COND_INITIALIZER; +static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER; +static pthread_cond_t cv = PTHREAD_COND_INITIALIZER; -int wake; -int stop; +static int wake; +static int stop; -void * -thr_routine(void *arg) +static void * +thr_routine(void *arg __unused) { pthread_mutex_lock(&m); while (wake == 0) pthread_cond_wait(&cv, &m); pthread_mutex_unlock(&m); while (stop == 0) pthread_yield(); return (NULL); } -int main(int argc, char **argv) +int +main(void) { pthread_t td; int i; void *result; pthread_setconcurrency(1); for (i = 0; i < NLOOPS; ++i) { stop = 0; wake = 0; pthread_create(&td, NULL, thr_routine, NULL); sleep(1); printf("trying: %d\n", i); pthread_mutex_lock(&m); wake = 1; pthread_cond_signal(&cv); pthread_cancel(td); pthread_mutex_unlock(&m); stop = 1; result = NULL; pthread_join(td, &result); if (result == PTHREAD_CANCELED) { printf("the condition variable implementation does not\n" "conform to SUSv3, a thread unblocked from\n" "condition variable still can be canceled.\n"); return (1); } } printf("OK\n"); return (0); } diff --git a/tools/regression/pthread/mutex_isowned_np/mutex_isowned_np.c b/tools/regression/pthread/mutex_isowned_np/mutex_isowned_np.c index 5c23568c33ac..381921c38a06 100644 --- a/tools/regression/pthread/mutex_isowned_np/mutex_isowned_np.c +++ b/tools/regression/pthread/mutex_isowned_np/mutex_isowned_np.c @@ -1,77 +1,77 @@ /*- * Copyright (c) 2008 Dag-Erling Coïdan Smørgrav * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer * in this position and unchanged. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #include #include #include #include static void * thread(void *arg) { pthread_mutex_t *mtx = arg; if (pthread_mutex_isowned_np(mtx) != 0) { printf("pthread_mutex_isowned_np() returned non-zero\n" "for a mutex held by another thread\n"); exit(1); } return (NULL); } int -main(int argc, char *argv[]) +main(void) { pthread_t thr; pthread_mutex_t mtx; pthread_mutex_init(&mtx, NULL); if (pthread_mutex_isowned_np(&mtx) != 0) { printf("pthread_mutex_isowned_np() returned non-zero\n" "for a mutex that is not held\n"); exit(1); } pthread_mutex_lock(&mtx); if (pthread_mutex_isowned_np(&mtx) == 0) { printf("pthread_mutex_isowned_np() returned zero\n" "for a mutex we hold ourselves\n"); exit(1); } pthread_create(&thr, NULL, thread, &mtx); pthread_join(thr, NULL); pthread_mutex_unlock(&mtx); if (pthread_mutex_isowned_np(&mtx) != 0) { printf("pthread_mutex_isowned_np() returned non-zero\n" "for a mutex that is not held\n"); exit(1); } printf("OK\n"); exit(0); } diff --git a/tools/regression/pthread/unwind/Test.cpp b/tools/regression/pthread/unwind/Test.cpp index 9322deff621e..46e451c390b6 100644 --- a/tools/regression/pthread/unwind/Test.cpp +++ b/tools/regression/pthread/unwind/Test.cpp @@ -1,37 +1,37 @@ /* $FreeBSD$ */ -int destructed; -int destructed2; +static int destructed; +static int destructed2; class Test { public: Test() { printf("Test::Test()\n"); } ~Test() { printf("Test::~Test()\n"); destructed = 1; } }; void -cleanup_handler(void *arg) +cleanup_handler(void *arg __unused) { destructed2 = 1; printf("%s()\n", __func__); } void check_destruct(void) { if (!destructed) printf("Bug, object destructor is not called\n"); else printf("OK\n"); } void check_destruct2(void) { if (!destructed) printf("Bug, object destructor is not called\n"); else if (!destructed2) printf("Bug, cleanup handler is not called\n"); else printf("OK\n"); } diff --git a/tools/regression/pthread/unwind/catch_pthread_exit.cpp b/tools/regression/pthread/unwind/catch_pthread_exit.cpp index 15abc20d1fea..db0e875ccaeb 100644 --- a/tools/regression/pthread/unwind/catch_pthread_exit.cpp +++ b/tools/regression/pthread/unwind/catch_pthread_exit.cpp @@ -1,35 +1,35 @@ /* $FreeBSD$ */ /* try to catch thread exiting, and rethrow the exception */ #include #include #include -int caught; +static int caught; -void * -thr_routine(void *arg) +static void * +thr_routine(void *arg __unused) { try { pthread_exit(NULL); } catch (...) { caught = 1; printf("thread exiting exception caught\n"); /* rethrow */ throw; } } int main() { pthread_t td; pthread_create(&td, NULL, thr_routine, NULL); pthread_join(td, NULL); if (caught) printf("OK\n"); else printf("failure\n"); return (0); } diff --git a/tools/regression/pthread/unwind/cond_wait_cancel.cpp b/tools/regression/pthread/unwind/cond_wait_cancel.cpp index 5975e028a5ca..4dfa57746552 100644 --- a/tools/regression/pthread/unwind/cond_wait_cancel.cpp +++ b/tools/regression/pthread/unwind/cond_wait_cancel.cpp @@ -1,39 +1,39 @@ /* $FreeBSD$ */ /* Test stack unwinding for pthread_cond_wait function */ #include #include #include #include #include "Test.cpp" -pthread_mutex_t mtx; -pthread_cond_t cv; +static pthread_mutex_t mtx; +static pthread_cond_t cv; -void * -thr(void *arg) +static void * +thr(void *arg __unused) { Test t; pthread_mutex_lock(&mtx); pthread_cond_wait(&cv, &mtx); pthread_mutex_unlock(&mtx); printf("Bug, thread shouldn't be here.\n"); return (0); } int main() { pthread_t td; pthread_mutex_init(&mtx, NULL); pthread_cond_init(&cv, NULL); pthread_create(&td, NULL, thr, NULL); sleep(1); pthread_cancel(td); pthread_join(td, NULL); check_destruct(); return (0); } diff --git a/tools/regression/pthread/unwind/cond_wait_cancel2.cpp b/tools/regression/pthread/unwind/cond_wait_cancel2.cpp index c781068918f1..ba71289fad98 100644 --- a/tools/regression/pthread/unwind/cond_wait_cancel2.cpp +++ b/tools/regression/pthread/unwind/cond_wait_cancel2.cpp @@ -1,56 +1,56 @@ /* * $FreeBSD$ * * Test stack unwinding for mixed pthread_cleanup_push/pop and C++ * object, both should work together. * */ #include #include #include #include #include "Test.cpp" -pthread_mutex_t mtx; -pthread_cond_t cv; +static pthread_mutex_t mtx; +static pthread_cond_t cv; -void f() +static void f() { Test t; pthread_mutex_lock(&mtx); pthread_cond_wait(&cv, &mtx); pthread_mutex_unlock(&mtx); printf("Bug, thread shouldn't be here.\n"); } -void g() +static void g() { f(); } -void * -thr(void *arg) +static void * +thr(void *arg __unused) { pthread_cleanup_push(cleanup_handler, NULL); g(); pthread_cleanup_pop(0); return (0); } int main() { pthread_t td; pthread_mutex_init(&mtx, NULL); pthread_cond_init(&cv, NULL); pthread_create(&td, NULL, thr, NULL); sleep(1); pthread_cancel(td); pthread_join(td, NULL); check_destruct2(); return (0); } diff --git a/tools/regression/pthread/unwind/sem_wait_cancel.cpp b/tools/regression/pthread/unwind/sem_wait_cancel.cpp index 019164cb3166..2086de6037cb 100644 --- a/tools/regression/pthread/unwind/sem_wait_cancel.cpp +++ b/tools/regression/pthread/unwind/sem_wait_cancel.cpp @@ -1,35 +1,35 @@ /* $FreeBSD$ */ /* Test stack unwinding for libc's sem */ #include #include #include #include #include "Test.cpp" -sem_t sem; +static sem_t sem; -void * -thr(void *arg) +static void * +thr(void *arg __unused) { Test t; sem_wait(&sem); printf("Bug, thread shouldn't be here.\n"); return (0); } int main() { pthread_t td; sem_init(&sem, 0, 0); pthread_create(&td, NULL, thr, NULL); sleep(1); pthread_cancel(td); pthread_join(td, NULL); check_destruct(); return (0); } diff --git a/tools/regression/pthread/unwind/thread_normal_exit.cpp b/tools/regression/pthread/unwind/thread_normal_exit.cpp index faf900e572c4..70768265be70 100644 --- a/tools/regression/pthread/unwind/thread_normal_exit.cpp +++ b/tools/regression/pthread/unwind/thread_normal_exit.cpp @@ -1,28 +1,28 @@ /* $FreeBSD$ */ /* test stack unwinding for a new thread */ #include #include #include #include "Test.cpp" -void * -thr_routine(void *arg) +static void * +thr_routine(void *arg __unused) { Test test; pthread_exit(NULL); printf("Bug, thread shouldn't be here\n"); } int main() { pthread_t td; pthread_create(&td, NULL, thr_routine, NULL); pthread_join(td, NULL); check_destruct(); return (0); }