More linking issues fixed.
[glibc.git] / nptl / tst-abstime.c
blobeb8e8aceb813852648c5cf554c8f33d0935f79eb
1 /* Copyright (C) 2010 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Andreas Schwab <schwab@redhat.com>, 2010.
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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <errno.h>
21 #include <pthread.h>
22 #include <semaphore.h>
23 #include <stdio.h>
25 static pthread_cond_t c = PTHREAD_COND_INITIALIZER;
26 static pthread_mutex_t m1 = PTHREAD_MUTEX_INITIALIZER;
27 static pthread_mutex_t m2 = PTHREAD_MUTEX_INITIALIZER;
28 static pthread_rwlock_t rw1 = PTHREAD_RWLOCK_INITIALIZER;
29 static pthread_rwlock_t rw2 = PTHREAD_RWLOCK_INITIALIZER;
30 static sem_t sem;
32 static void *
33 th (void *arg)
35 long int res = 0;
36 int r;
37 struct timespec t = { -2, 0 };
39 r = pthread_mutex_timedlock (&m1, &t);
40 if (r != ETIMEDOUT)
42 puts ("pthread_mutex_timedlock did not return ETIMEDOUT");
43 res = 1;
45 r = pthread_rwlock_timedrdlock (&rw1, &t);
46 if (r != ETIMEDOUT)
48 puts ("pthread_rwlock_timedrdlock did not return ETIMEDOUT");
49 res = 1;
51 r = pthread_rwlock_timedwrlock (&rw2, &t);
52 if (r != ETIMEDOUT)
54 puts ("pthread_rwlock_timedwrlock did not return ETIMEDOUT");
55 res = 1;
57 return (void *) res;
60 static int
61 do_test (void)
63 int res = 0;
64 int r;
65 struct timespec t = { -2, 0 };
66 pthread_t pth;
68 sem_init (&sem, 0, 0);
69 r = sem_timedwait (&sem, &t);
70 if (r != -1 || errno != ETIMEDOUT)
72 puts ("sem_timedwait did not fail with ETIMEDOUT");
73 res = 1;
76 pthread_mutex_lock (&m1);
77 pthread_rwlock_wrlock (&rw1);
78 pthread_rwlock_rdlock (&rw2);
79 pthread_mutex_lock (&m2);
80 pthread_create (&pth, 0, th, 0);
81 r = pthread_cond_timedwait (&c, &m2, &t);
82 if (r != ETIMEDOUT)
84 puts ("pthread_cond_timedwait did not return ETIMEDOUT");
85 res = 1;
87 void *thres;
88 pthread_join (pth, &thres);
89 return res | (thres != NULL);
93 #define TEST_FUNCTION do_test ()
94 #include "../test-skeleton.c"