2 * Copyright (c) 2003-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
32 #include <mach/boolean.h>
33 #include <mach/mach_types.h>
35 #include <kern/kern_types.h>
36 #include <kern/processor.h>
37 #include <kern/timer_call.h>
38 #include <kern/thread_call.h>
39 #include <kern/kalloc.h>
40 #include <kern/thread.h>
42 #include <machine/machine_routines.h>
43 #include <machine/cpu_data.h>
45 #include <chud/chud_xnu.h>
46 #include <chud/chud_xnu_private.h>
48 #pragma mark **** timer ****
49 __private_extern__ chud_timer_t
50 chudxnu_timer_alloc(chudxnu_timer_callback_func_t func
, uint32_t param0
)
52 return (chud_timer_t
)thread_call_allocate((thread_call_func_t
)func
, (thread_call_param_t
)param0
);
55 __private_extern__ kern_return_t
56 chudxnu_timer_callback_enter(
63 clock_interval_to_deadline(time
, units
, &t_delay
);
64 thread_call_enter1_delayed((thread_call_t
)timer
, (thread_call_param_t
)param1
, t_delay
);
68 __private_extern__ kern_return_t
69 chudxnu_timer_callback_cancel(chud_timer_t timer
)
71 thread_call_cancel((thread_call_t
)timer
);
75 __private_extern__ kern_return_t
76 chudxnu_timer_free(chud_timer_t timer
)
78 thread_call_cancel((thread_call_t
)timer
);
79 thread_call_free((thread_call_t
)timer
);
83 #pragma mark **** thread timer - DEPRECATED ****
85 static thread_call_t thread_timer_call
= NULL
;
86 static chudxnu_thread_timer_callback_func_t thread_timer_callback_fn
= NULL
;
88 static void chudxnu_private_thread_timer_callback(
89 thread_call_param_t param0
,
90 thread_call_param_t param1
)
92 #pragma unused (param1)
93 chudxnu_thread_timer_callback_func_t fn
= thread_timer_callback_fn
;
95 if(thread_timer_call
) {
96 thread_call_free(thread_timer_call
);
97 thread_timer_call
= NULL
;
100 (fn
)((uint32_t)param0
);
107 kern_return_t
chudxnu_thread_timer_callback_enter(
108 chudxnu_thread_timer_callback_func_t func
,
113 if(!thread_timer_call
) {
115 thread_timer_callback_fn
= func
;
117 thread_timer_call
= thread_call_allocate(
119 chudxnu_private_thread_timer_callback
,
120 (thread_call_param_t
)
122 clock_interval_to_deadline(time
, units
, &t_delay
);
123 thread_call_enter_delayed(thread_timer_call
, t_delay
);
126 return KERN_FAILURE
; // thread timer call already pending
132 kern_return_t
chudxnu_thread_timer_callback_cancel(void)
134 if(thread_timer_call
) {
135 thread_call_cancel(thread_timer_call
);
136 thread_call_free(thread_timer_call
);
137 thread_timer_call
= NULL
;
139 thread_timer_callback_fn
= NULL
;