2 * Copyright (c) 2003-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
30 #include <mach/boolean.h>
31 #include <mach/mach_types.h>
33 #include <kern/kern_types.h>
34 #include <kern/processor.h>
35 #include <kern/timer_call.h>
36 #include <kern/thread_call.h>
37 #include <kern/kalloc.h>
38 #include <kern/thread.h>
40 #include <machine/machine_routines.h>
41 #include <machine/cpu_data.h>
43 #include <chud/chud_xnu.h>
44 #include <chud/chud_xnu_private.h>
46 #pragma mark **** timer ****
47 __private_extern__ chud_timer_t
48 chudxnu_timer_alloc(chudxnu_timer_callback_func_t func
, uint32_t param0
)
50 return (chud_timer_t
)thread_call_allocate((thread_call_func_t
)func
, (thread_call_param_t
)param0
);
53 __private_extern__ kern_return_t
54 chudxnu_timer_callback_enter(
61 clock_interval_to_deadline(time
, units
, &t_delay
);
62 thread_call_enter1_delayed((thread_call_t
)timer
, (thread_call_param_t
)param1
, t_delay
);
66 __private_extern__ kern_return_t
67 chudxnu_timer_callback_cancel(chud_timer_t timer
)
69 thread_call_cancel((thread_call_t
)timer
);
73 __private_extern__ kern_return_t
74 chudxnu_timer_free(chud_timer_t timer
)
76 thread_call_cancel((thread_call_t
)timer
);
77 thread_call_free((thread_call_t
)timer
);
81 #pragma mark **** thread timer - DEPRECATED ****
83 static thread_call_t thread_timer_call
= NULL
;
84 static chudxnu_thread_timer_callback_func_t thread_timer_callback_fn
= NULL
;
86 static void chudxnu_private_thread_timer_callback(
87 thread_call_param_t param0
,
88 thread_call_param_t param1
)
90 #pragma unused (param1)
91 chudxnu_thread_timer_callback_func_t fn
= thread_timer_callback_fn
;
93 if(thread_timer_call
) {
94 thread_call_free(thread_timer_call
);
95 thread_timer_call
= NULL
;
98 (fn
)((uint32_t)param0
);
105 kern_return_t
chudxnu_thread_timer_callback_enter(
106 chudxnu_thread_timer_callback_func_t func
,
111 if(!thread_timer_call
) {
113 thread_timer_callback_fn
= func
;
115 thread_timer_call
= thread_call_allocate(
117 chudxnu_private_thread_timer_callback
,
118 (thread_call_param_t
)
120 clock_interval_to_deadline(time
, units
, &t_delay
);
121 thread_call_enter_delayed(thread_timer_call
, t_delay
);
124 return KERN_FAILURE
; // thread timer call already pending
130 kern_return_t
chudxnu_thread_timer_callback_cancel(void)
132 if(thread_timer_call
) {
133 thread_call_cancel(thread_timer_call
);
134 thread_call_free(thread_timer_call
);
135 thread_timer_call
= NULL
;
137 thread_timer_callback_fn
= NULL
;