1 // commit: 9d5251f72b627974bcf438501e07ad42c24d94be 2011-03-08
2 // disallow cpu time clocks in condattr
9 #define T(r,f) if ((r=(f))) t_error(#f " failed: %s\n", strerror(r))
21 T(r,pthread_condattr_init(&a));
22 r = pthread_condattr_setclock(&a, CLOCK_PROCESS_CPUTIME_ID);
24 t_error("pthread_condattr_setclock CLOCK_PROCESS_CPUTIME_ID should fail with EINVAL, got %s\n", strerror(r));
25 r = pthread_condattr_setclock(&a, CLOCK_THREAD_CPUTIME_ID);
27 t_error("pthread_condattr_setclock CLOCK_THREAD_CPUTIME_ID should fail with EINVAL, got %s\n", strerror(r));
28 T(r,pthread_condattr_getclock(&a, &clk));
29 if (clk != CLOCK_REALTIME)
30 t_error("condattr default clock is %d, wanted CLOCK_REALTIME (%d)\n", (int)clk, (int)CLOCK_REALTIME);
32 T(r,pthread_cond_init(&c, &a));
33 T(r,pthread_mutex_init(&m, 0));
34 T(r,pthread_mutex_lock(&m));
35 r = clock_gettime(CLOCK_REALTIME, &ts);
37 t_error("clock_gettime failed: %s\n", strerror(errno));
39 ts.tv_nsec += 10*1000*1000;
40 if (ts.tv_nsec >= 1000*1000*1000) {
41 ts.tv_nsec -= 1000*1000*1000;
44 r = pthread_cond_timedwait(&c, &m, &ts);
46 t_error("pthread_cond_timedwait did not timeout, returned %s\n", strerror(r));
47 T(r,pthread_mutex_unlock(&m));
49 T(r,pthread_mutex_destroy(&m));
50 T(r,pthread_cond_destroy(&c));
51 T(r,pthread_condattr_destroy(&a));