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