BZ#18434: Fix sem_post EOVERFLOW check for [!__HAVE_64B_ATOMICS].
[glibc.git] / nptl / tst-cond-except.c
blob239403bd96f0f0410702bcb15aa7f4c66fe5650a
1 /* Verify that exception table for pthread_cond_wait is correct.
2 Copyright (C) 2012-2015 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <pthread.h>
20 #include <stdio.h>
21 #include <stdint.h>
22 #include <string.h>
23 #include <unistd.h>
25 pthread_mutex_t mutex;
26 pthread_cond_t cond;
28 #define CHECK_RETURN_VAL_OR_FAIL(ret,str) \
29 ({ if ((ret) != 0) \
30 { \
31 printf ("%s failed: %s\n", (str), strerror (ret)); \
32 ret = 1; \
33 goto out; \
34 } \
38 void
39 clean (void *arg)
41 puts ("clean: Unlocking mutex...");
42 pthread_mutex_unlock ((pthread_mutex_t *) arg);
43 puts ("clean: Mutex unlocked...");
46 void *
47 thr (void *arg)
49 int ret = 0;
50 pthread_mutexattr_t mutexAttr;
51 ret = pthread_mutexattr_init (&mutexAttr);
52 CHECK_RETURN_VAL_OR_FAIL (ret, "pthread_mutexattr_init");
54 ret = pthread_mutexattr_setprotocol (&mutexAttr, PTHREAD_PRIO_INHERIT);
55 CHECK_RETURN_VAL_OR_FAIL (ret, "pthread_mutexattr_setprotocol");
57 ret = pthread_mutex_init (&mutex, &mutexAttr);
58 CHECK_RETURN_VAL_OR_FAIL (ret, "pthread_mutex_init");
60 ret = pthread_cond_init (&cond, 0);
61 CHECK_RETURN_VAL_OR_FAIL (ret, "pthread_cond_init");
63 puts ("th: Init done, entering wait...");
65 pthread_cleanup_push (clean, (void *) &mutex);
66 ret = pthread_mutex_lock (&mutex);
67 CHECK_RETURN_VAL_OR_FAIL (ret, "pthread_mutex_lock");
68 while (1)
70 ret = pthread_cond_wait (&cond, &mutex);
71 CHECK_RETURN_VAL_OR_FAIL (ret, "pthread_cond_wait");
73 pthread_cleanup_pop (1);
75 out:
76 return (void *) (uintptr_t) ret;
79 int
80 do_test (void)
82 pthread_t thread;
83 int ret = 0;
84 void *thr_ret = 0;
85 ret = pthread_create (&thread, 0, thr, &thr_ret);
86 CHECK_RETURN_VAL_OR_FAIL (ret, "pthread_create");
88 puts ("main: Thread created, waiting a bit...");
89 sleep (2);
91 puts ("main: Cancelling thread...");
92 ret = pthread_cancel (thread);
93 CHECK_RETURN_VAL_OR_FAIL (ret, "pthread_cancel");
95 puts ("main: Joining th...");
96 ret = pthread_join (thread, NULL);
97 CHECK_RETURN_VAL_OR_FAIL (ret, "pthread_join");
99 if (thr_ret != NULL)
100 return 1;
102 puts ("main: Joined thread, done!");
104 out:
105 return ret;
108 #define TEST_FUNCTION do_test ()
109 #define TIMEOUT 5
110 #include "../test-skeleton.c"