]>
Commit | Line | Data |
---|---|---|
6d2010ae A |
1 | /* |
2 | * testthreadcall.cpp | |
3 | * testkext | |
4 | * | |
5 | */ | |
6 | ||
6d2010ae A |
7 | #include "testthreadcall.h" |
8 | ||
9 | #include <kern/thread_call.h> | |
3e170ce0 | 10 | #include <pexpert/pexpert.h> |
6d2010ae A |
11 | |
12 | #define super IOService | |
13 | OSDefineMetaClassAndStructors(testthreadcall, super); | |
14 | ||
15 | extern "C" { | |
6d2010ae | 16 | static void thread_call_test_func(thread_call_param_t param0, |
0a7de745 | 17 | thread_call_param_t param1); |
6d2010ae | 18 | |
fe8ab488 | 19 | static void thread_call_test_func2(thread_call_param_t param0, |
0a7de745 | 20 | thread_call_param_t param1); |
6d2010ae A |
21 | } |
22 | ||
3e170ce0 A |
23 | static int my_event; |
24 | ||
6d2010ae A |
25 | bool |
26 | testthreadcall::start( IOService * provider ) | |
27 | { | |
0a7de745 A |
28 | boolean_t ret; |
29 | uint64_t deadline; | |
30 | int sleepret; | |
31 | uint32_t kernel_configuration; | |
32 | ||
33 | IOLog("%s\n", __PRETTY_FUNCTION__); | |
34 | ||
35 | if (!super::start(provider)) { | |
36 | return false; | |
37 | } | |
38 | ||
39 | kernel_configuration = PE_i_can_has_kernel_configuration(); | |
40 | IOLog("%s: Assertions %s\n", __PRETTY_FUNCTION__, | |
41 | (kernel_configuration & kPEICanHasAssertions) ? "enabled" : "disabled"); | |
42 | IOLog("%s: Statistics %s\n", __PRETTY_FUNCTION__, | |
43 | (kernel_configuration & kPEICanHasStatistics) ? "enabled" : "disabled"); | |
44 | IOLog("%s: Diagnostic API %s\n", __PRETTY_FUNCTION__, | |
45 | (kernel_configuration & kPEICanHasDiagnosticAPI) ? "enabled" : "disabled"); | |
46 | ||
47 | IOLog("Attempting thread_call_allocate\n"); | |
6d2010ae | 48 | tcall = thread_call_allocate(thread_call_test_func, this); |
0a7de745 A |
49 | IOLog("thread_call_t %p\n", tcall); |
50 | ||
6d2010ae A |
51 | tlock = IOSimpleLockAlloc(); |
52 | IOLog("tlock %p\n", tlock); | |
0a7de745 | 53 | |
6d2010ae A |
54 | clock_interval_to_deadline(5, NSEC_PER_SEC, &deadline); |
55 | IOLog("%d sec deadline is %llu\n", 5, deadline); | |
0a7de745 | 56 | |
6d2010ae | 57 | ret = thread_call_enter_delayed(tcall, deadline); |
fe8ab488 | 58 | |
0a7de745 A |
59 | IOLog("Attempting thread_call_allocate\n"); |
60 | tcall2 = thread_call_allocate(thread_call_test_func2, this); | |
61 | IOLog("thread_call_t %p\n", tcall); | |
62 | ||
63 | tlock2 = IOLockAlloc(); | |
64 | IOLog("tlock2 %p\n", tlock2); | |
65 | ||
66 | clock_interval_to_deadline(2, NSEC_PER_SEC, &deadline); | |
67 | IOLog("%d sec deadline is %llu\n", 2, deadline); | |
68 | ||
69 | ret = thread_call_enter_delayed(tcall2, deadline); | |
fe8ab488 | 70 | |
0a7de745 | 71 | IOLockLock(tlock2); |
fe8ab488 | 72 | |
0a7de745 A |
73 | clock_interval_to_deadline(3, NSEC_PER_SEC, &deadline); |
74 | IOLog("%d sec deadline is %llu\n", 3, deadline); | |
75 | sleepret = IOLockSleepDeadline(tlock2, &my_event, deadline, THREAD_INTERRUPTIBLE); | |
76 | IOLog("IOLockSleepDeadline(&my_event, %llu) returned %d, expected 0\n", deadline, sleepret); | |
fe8ab488 | 77 | |
0a7de745 | 78 | IOLockUnlock(tlock2); |
fe8ab488 | 79 | |
0a7de745 A |
80 | clock_interval_to_deadline(4, NSEC_PER_SEC, &deadline); |
81 | IOLog("%d sec deadline is %llu\n", 4, deadline); | |
fe8ab488 | 82 | |
0a7de745 | 83 | ret = thread_call_enter_delayed(tcall2, deadline); |
fe8ab488 | 84 | |
0a7de745 | 85 | IOLockLock(tlock2); |
fe8ab488 | 86 | |
0a7de745 A |
87 | clock_interval_to_deadline(3, NSEC_PER_SEC, &deadline); |
88 | IOLog("%d sec deadline is %llu\n", 3, deadline); | |
89 | sleepret = IOLockSleepDeadline(tlock2, &my_event, deadline, THREAD_INTERRUPTIBLE); | |
90 | IOLog("IOLockSleepDeadline(&my_event, %llu) returned %d, expected 1\n", deadline, sleepret); | |
fe8ab488 | 91 | |
0a7de745 A |
92 | IOLockUnlock(tlock2); |
93 | ||
94 | return true; | |
6d2010ae A |
95 | } |
96 | ||
0a7de745 A |
97 | static void |
98 | thread_call_test_func(thread_call_param_t param0, | |
99 | thread_call_param_t param1) | |
6d2010ae A |
100 | { |
101 | testthreadcall *self = (testthreadcall *)param0; | |
0a7de745 | 102 | |
6d2010ae | 103 | IOLog("thread_call_test_func %p %p\n", param0, param1); |
0a7de745 | 104 | |
6d2010ae A |
105 | IOSimpleLockLock(self->tlock); |
106 | IOSimpleLockUnlock(self->tlock); | |
fe8ab488 | 107 | } |
6d2010ae | 108 | |
0a7de745 A |
109 | static void |
110 | thread_call_test_func2(thread_call_param_t param0, | |
111 | thread_call_param_t param1) | |
fe8ab488 A |
112 | { |
113 | testthreadcall *self = (testthreadcall *)param0; | |
0a7de745 | 114 | |
fe8ab488 | 115 | IOLog("thread_call_test_func2 %p %p\n", param0, param1); |
0a7de745 | 116 | |
3e170ce0 | 117 | IOLockWakeup(self->tlock2, &my_event, false); |
6d2010ae | 118 | } |