4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
29 #include <sys/types.h>
33 #include "sigev_thread.h"
36 * System call wrappers found elsewhere in libc (common/sys/__clock_timer.s).
38 extern int __clock_getres(clockid_t
, timespec_t
*);
39 extern int __clock_gettime(clockid_t
, timespec_t
*);
40 extern int __clock_settime(clockid_t
, const timespec_t
*);
41 extern int __timer_create(clockid_t
, struct sigevent
*, timer_t
*);
42 extern int __timer_delete(timer_t
);
43 extern int __timer_getoverrun(timer_t
);
44 extern int __timer_gettime(timer_t
, itimerspec_t
*);
45 extern int __timer_settime(timer_t
, int, const itimerspec_t
*, itimerspec_t
*);
48 * Array of pointers to tcd's, indexed by timer id.
49 * No more than 'timer_max' timers can be created by any process.
52 thread_communication_data_t
**timer_tcd
;
53 static pthread_once_t timer_once
= PTHREAD_ONCE_INIT
;
58 timer_max
= (int)_sysconf(_SC_TIMER_MAX
);
59 timer_tcd
= malloc(timer_max
* sizeof (*timer_tcd
));
60 (void) memset(timer_tcd
, 0, timer_max
* sizeof (*timer_tcd
));
64 clock_getres(clockid_t clock_id
, timespec_t
*res
)
66 return (__clock_getres(clock_id
, res
));
70 clock_gettime(clockid_t clock_id
, timespec_t
*tp
)
72 return (__clock_gettime(clock_id
, tp
));
76 clock_settime(clockid_t clock_id
, const timespec_t
*tp
)
78 return (__clock_settime(clock_id
, tp
));
82 timer_create(clockid_t clock_id
, struct sigevent
*sigevp
, timer_t
*timerid
)
84 struct sigevent sigevent
;
85 port_notify_t port_notify
;
86 thread_communication_data_t
*tcdp
;
90 (void) pthread_once(&timer_once
, timer_init
);
93 sigevp
->sigev_notify
== SIGEV_THREAD
&&
94 sigevp
->sigev_notify_function
!= NULL
) {
96 tcdp
= setup_sigev_handler(sigevp
, TIMER
);
99 /* copy the sigevent structure so we can modify it */
102 port_notify
.portnfy_port
= tcdp
->tcd_port
;
103 port_notify
.portnfy_user
= NULL
;
104 sigevp
->sigev_value
.sival_ptr
= &port_notify
;
107 rc
= __timer_create(clock_id
, sigevp
, timerid
);
111 if ((rc
= launch_spawner(tcdp
)) != 0)
112 (void) __timer_delete(*timerid
);
114 timer_tcd
[*timerid
] = tcdp
;
117 free_sigev_handler(tcdp
);
124 timer_delete(timer_t timerid
)
128 if ((rc
= del_sigev_timer(timerid
)) == 0)
129 return (__timer_delete(timerid
));
135 timer_getoverrun(timer_t timerid
)
137 return (__timer_getoverrun(timerid
) + sigev_timer_getoverrun(timerid
));
141 timer_gettime(timer_t timerid
, itimerspec_t
*value
)
143 return (__timer_gettime(timerid
, value
));
147 timer_settime(timer_t timerid
, int flags
, const itimerspec_t
*value
,
148 itimerspec_t
*ovalue
)
150 return (__timer_settime(timerid
, flags
, value
, ovalue
));
154 * Cleanup after fork1() in the child process.
157 postfork1_child_sigev_timer(void)
159 thread_communication_data_t
*tcdp
;
162 for (timer
= 0; timer
< timer_max
; timer
++) {
163 if ((tcdp
= timer_tcd
[timer
]) != NULL
) {
164 timer_tcd
[timer
] = NULL
;