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. */
29 notify_func (union sigval sigval
)
38 static const char text
[] = "signal_func\n";
39 signal (sig
, signal_func
);
40 write (STDOUT_FILENO
, text
, sizeof text
- 1);
51 while (nanosleep (&ts
, &ts
) == -1 && errno
== EINTR
)
62 timer_t timer_sig
, timer_thr1
, timer_thr2
;
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
);
106 timer_delete (timer_sig
);
107 timer_delete (timer_thr1
);
111 timer_delete (timer_thr2
);