x86-64: Don't use SSE resolvers for ISA level 3 or above
[glibc.git] / sysdeps / pthread / tst-cond9.c
blob564f1ed0eece1f11254a1530ffebd5b854547f67
1 /* Copyright (C) 2003-2024 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
18 #include <errno.h>
19 #include <pthread.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <time.h>
23 #include <sys/time.h>
26 static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
27 static pthread_mutex_t mut = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
30 static void *
31 tf (void *arg)
33 int err = pthread_cond_wait (&cond, &mut);
34 if (err == 0)
36 puts ("cond_wait did not fail");
37 exit (1);
40 if (err != EPERM)
42 printf ("cond_wait didn't return EPERM but %d\n", err);
43 exit (1);
47 /* Current time. */
48 struct timeval tv;
49 (void) gettimeofday (&tv, NULL);
50 /* +1000 seconds in correct format. */
51 struct timespec ts;
52 TIMEVAL_TO_TIMESPEC (&tv, &ts);
53 ts.tv_sec += 1000;
55 err = pthread_cond_timedwait (&cond, &mut, &ts);
56 if (err == 0)
58 puts ("cond_timedwait did not fail");
59 exit (1);
62 if (err != EPERM)
64 printf ("cond_timedwait didn't return EPERM but %d\n", err);
65 exit (1);
68 return (void *) 1l;
72 static int
73 do_test (void)
75 pthread_t th;
76 int err;
78 printf ("&cond = %p\n&mut = %p\n", &cond, &mut);
80 err = pthread_cond_wait (&cond, &mut);
81 if (err == 0)
83 puts ("cond_wait did not fail");
84 exit (1);
87 if (err != EPERM)
89 printf ("cond_wait didn't return EPERM but %d\n", err);
90 exit (1);
94 /* Current time. */
95 struct timeval tv;
96 (void) gettimeofday (&tv, NULL);
97 /* +1000 seconds in correct format. */
98 struct timespec ts;
99 TIMEVAL_TO_TIMESPEC (&tv, &ts);
100 ts.tv_sec += 1000;
102 err = pthread_cond_timedwait (&cond, &mut, &ts);
103 if (err == 0)
105 puts ("cond_timedwait did not fail");
106 exit (1);
109 if (err != EPERM)
111 printf ("cond_timedwait didn't return EPERM but %d\n", err);
112 exit (1);
115 if (pthread_mutex_lock (&mut) != 0)
117 puts ("parent: mutex_lock failed");
118 exit (1);
121 puts ("creating thread");
123 if (pthread_create (&th, NULL, tf, NULL) != 0)
125 puts ("create failed");
126 exit (1);
129 void *r;
130 if (pthread_join (th, &r) != 0)
132 puts ("join failed");
133 exit (1);
135 if (r != (void *) 1l)
137 puts ("thread has wrong return value");
138 exit (1);
141 puts ("done");
143 return 0;
147 #define TEST_FUNCTION do_test ()
148 #include "../test-skeleton.c"