]> git.saurik.com Git - apple/xnu.git/blob - osfmk/chud/chud_osfmk_callback.c
7dc865a5a476f49d19d41fddb6c0ba5f8dec54f6
[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_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23 #include <stdint.h>
24 #include <mach/boolean.h>
25 #include <mach/mach_types.h>
26
27 #include <kern/kern_types.h>
28 #include <kern/processor.h>
29 #include <kern/timer_call.h>
30 #include <kern/thread_call.h>
31 #include <kern/kalloc.h>
32 #include <kern/thread.h>
33
34 #include <machine/machine_routines.h>
35 #include <machine/cpu_data.h>
36
37 #include <chud/chud_xnu.h>
38 #include <chud/chud_xnu_private.h>
39
40 #pragma mark **** timer ****
41 __private_extern__ chud_timer_t
42 chudxnu_timer_alloc(chudxnu_timer_callback_func_t func, uint32_t param0)
43 {
44 return (chud_timer_t)thread_call_allocate((thread_call_func_t)func, (thread_call_param_t)param0);
45 }
46
47 __private_extern__ kern_return_t
48 chudxnu_timer_callback_enter(
49 chud_timer_t timer,
50 uint32_t param1,
51 uint32_t time,
52 uint32_t units)
53 {
54 uint64_t t_delay;
55 clock_interval_to_deadline(time, units, &t_delay);
56 thread_call_enter1_delayed((thread_call_t)timer, (thread_call_param_t)param1, t_delay);
57 return KERN_SUCCESS;
58 }
59
60 __private_extern__ kern_return_t
61 chudxnu_timer_callback_cancel(chud_timer_t timer)
62 {
63 thread_call_cancel((thread_call_t)timer);
64 return KERN_SUCCESS;
65 }
66
67 __private_extern__ kern_return_t
68 chudxnu_timer_free(chud_timer_t timer)
69 {
70 thread_call_cancel((thread_call_t)timer);
71 thread_call_free((thread_call_t)timer);
72 return KERN_SUCCESS;
73 }
74
75 #pragma mark **** thread timer - DEPRECATED ****
76
77 static thread_call_t thread_timer_call = NULL;
78 static chudxnu_thread_timer_callback_func_t thread_timer_callback_fn = NULL;
79
80 static void chudxnu_private_thread_timer_callback(
81 thread_call_param_t param0,
82 thread_call_param_t param1)
83 {
84 #pragma unused (param1)
85 chudxnu_thread_timer_callback_func_t fn = thread_timer_callback_fn;
86
87 if(thread_timer_call) {
88 thread_call_free(thread_timer_call);
89 thread_timer_call = NULL;
90
91 if(fn) {
92 (fn)((uint32_t)param0);
93 }
94 }
95 }
96
97 // DEPRECATED
98 __private_extern__
99 kern_return_t chudxnu_thread_timer_callback_enter(
100 chudxnu_thread_timer_callback_func_t func,
101 uint32_t param,
102 uint32_t time,
103 uint32_t units)
104 {
105 if(!thread_timer_call) {
106 uint64_t t_delay;
107 thread_timer_callback_fn = func;
108
109 thread_timer_call = thread_call_allocate(
110 (thread_call_func_t)
111 chudxnu_private_thread_timer_callback,
112 (thread_call_param_t)
113 param);
114 clock_interval_to_deadline(time, units, &t_delay);
115 thread_call_enter_delayed(thread_timer_call, t_delay);
116 return KERN_SUCCESS;
117 } else {
118 return KERN_FAILURE; // thread timer call already pending
119 }
120 }
121
122 // DEPRECATED
123 __private_extern__
124 kern_return_t chudxnu_thread_timer_callback_cancel(void)
125 {
126 if(thread_timer_call) {
127 thread_call_cancel(thread_timer_call);
128 thread_call_free(thread_timer_call);
129 thread_timer_call = NULL;
130 }
131 thread_timer_callback_fn = NULL;
132 return KERN_SUCCESS;
133 }