]> git.saurik.com Git - apple/xnu.git/blob - osfmk/chud/chud_osfmk_callback.c
30bc2ac9ac408c06112d6dde53a56bacadb4ab0e
[apple/xnu.git] / osfmk / chud / chud_osfmk_callback.c
1 /*
2 * Copyright (c) 2003-2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
5 *
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
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
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.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30
31 #include <stdint.h>
32 #include <mach/boolean.h>
33 #include <mach/mach_types.h>
34
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>
41
42 #include <machine/machine_routines.h>
43 #include <machine/cpu_data.h>
44
45 #include <chud/chud_xnu.h>
46 #include <chud/chud_xnu_private.h>
47
48 #pragma mark **** timer ****
49 __private_extern__ chud_timer_t
50 chudxnu_timer_alloc(chudxnu_timer_callback_func_t func, uint32_t param0)
51 {
52 return (chud_timer_t)thread_call_allocate((thread_call_func_t)func, (thread_call_param_t)param0);
53 }
54
55 __private_extern__ kern_return_t
56 chudxnu_timer_callback_enter(
57 chud_timer_t timer,
58 uint32_t param1,
59 uint32_t time,
60 uint32_t units)
61 {
62 uint64_t t_delay;
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);
65 return KERN_SUCCESS;
66 }
67
68 __private_extern__ kern_return_t
69 chudxnu_timer_callback_cancel(chud_timer_t timer)
70 {
71 thread_call_cancel((thread_call_t)timer);
72 return KERN_SUCCESS;
73 }
74
75 __private_extern__ kern_return_t
76 chudxnu_timer_free(chud_timer_t timer)
77 {
78 thread_call_cancel((thread_call_t)timer);
79 thread_call_free((thread_call_t)timer);
80 return KERN_SUCCESS;
81 }
82
83 #pragma mark **** thread timer - DEPRECATED ****
84
85 static thread_call_t thread_timer_call = NULL;
86 static chudxnu_thread_timer_callback_func_t thread_timer_callback_fn = NULL;
87
88 static void chudxnu_private_thread_timer_callback(
89 thread_call_param_t param0,
90 thread_call_param_t param1)
91 {
92 #pragma unused (param1)
93 chudxnu_thread_timer_callback_func_t fn = thread_timer_callback_fn;
94
95 if(thread_timer_call) {
96 thread_call_free(thread_timer_call);
97 thread_timer_call = NULL;
98
99 if(fn) {
100 (fn)((uint32_t)param0);
101 }
102 }
103 }
104
105 // DEPRECATED
106 __private_extern__
107 kern_return_t chudxnu_thread_timer_callback_enter(
108 chudxnu_thread_timer_callback_func_t func,
109 uint32_t param,
110 uint32_t time,
111 uint32_t units)
112 {
113 if(!thread_timer_call) {
114 uint64_t t_delay;
115 thread_timer_callback_fn = func;
116
117 thread_timer_call = thread_call_allocate(
118 (thread_call_func_t)
119 chudxnu_private_thread_timer_callback,
120 (thread_call_param_t)
121 param);
122 clock_interval_to_deadline(time, units, &t_delay);
123 thread_call_enter_delayed(thread_timer_call, t_delay);
124 return KERN_SUCCESS;
125 } else {
126 return KERN_FAILURE; // thread timer call already pending
127 }
128 }
129
130 // DEPRECATED
131 __private_extern__
132 kern_return_t chudxnu_thread_timer_callback_cancel(void)
133 {
134 if(thread_timer_call) {
135 thread_call_cancel(thread_timer_call);
136 thread_call_free(thread_timer_call);
137 thread_timer_call = NULL;
138 }
139 thread_timer_callback_fn = NULL;
140 return KERN_SUCCESS;
141 }