semtimedop implementation for Linux/m68k.
[glibc.git] / linuxthreads / sysdeps / pthread / tst-timer.c
blob7417bcd5f02292febb2ac151efbc62db7ad1acbb
1 /* Tests for POSIX timer implementation.
2 Copyright (C) 2000, 2002 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Kaz Kylheku <kaz@ashi.footprints.net>.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 #include <errno.h>
22 #include <signal.h>
23 #include <stdio.h>
24 #include <time.h>
25 #include <unistd.h>
28 static void
29 notify_func (union sigval sigval)
31 puts ("notify_func");
35 static void
36 signal_func (int sig)
38 static const char text[] = "signal_func\n";
39 signal (sig, signal_func);
40 write (STDOUT_FILENO, text, sizeof text - 1);
43 static void
44 intr_sleep (int sec)
46 struct timespec ts;
48 ts.tv_sec = sec;
49 ts.tv_nsec = 0;
51 while (nanosleep (&ts, &ts) == -1 && errno == EINTR)
55 #define ZSIGALRM 14
58 int
59 main (void)
61 struct timespec ts;
62 timer_t timer_sig, timer_thr1, timer_thr2;
63 int retval;
64 struct sigevent sigev1 =
66 .sigev_notify = SIGEV_SIGNAL,
67 .sigev_signo = ZSIGALRM
69 struct sigevent sigev2;
70 struct itimerspec itimer1 = { { 0, 200000000 }, { 0, 200000000 } };
71 struct itimerspec itimer2 = { { 0, 100000000 }, { 0, 500000000 } };
72 struct itimerspec itimer3 = { { 0, 150000000 }, { 0, 300000000 } };
73 struct itimerspec old;
75 retval = clock_gettime (CLOCK_REALTIME, &ts);
77 sigev2.sigev_notify = SIGEV_THREAD;
78 sigev2.sigev_notify_function = notify_func;
79 sigev2.sigev_notify_attributes = NULL;
81 setvbuf (stdout, 0, _IOLBF, 0);
83 printf ("clock_gettime returned %d, timespec = { %ld, %ld }\n",
84 retval, ts.tv_sec, ts.tv_nsec);
86 retval = clock_getres (CLOCK_REALTIME, &ts);
88 printf ("clock_getres returned %d, timespec = { %ld, %ld }\n",
89 retval, ts.tv_sec, ts.tv_nsec);
91 timer_create (CLOCK_REALTIME, &sigev1, &timer_sig);
92 timer_create (CLOCK_REALTIME, &sigev2, &timer_thr1);
93 timer_create (CLOCK_REALTIME, &sigev2, &timer_thr2);
95 timer_settime (timer_thr1, 0, &itimer2, &old);
96 timer_settime (timer_thr2, 0, &itimer3, &old);
98 signal (ZSIGALRM, signal_func);
100 timer_settime (timer_sig, 0, &itimer1, &old);
102 timer_delete (-1);
104 intr_sleep (3);
106 timer_delete (timer_sig);
107 timer_delete (timer_thr1);
109 intr_sleep (3);
111 timer_delete (timer_thr2);
113 return 0;