7 #include "testthreadcall.h"
9 #include <kern/thread_call.h>
10 #include <pexpert/pexpert.h>
12 #define super IOService
13 OSDefineMetaClassAndStructors(testthreadcall
, super
);
16 static void thread_call_test_func(thread_call_param_t param0
,
17 thread_call_param_t param1
);
19 static void thread_call_test_func2(thread_call_param_t param0
,
20 thread_call_param_t param1
);
26 testthreadcall::start( IOService
* provider
)
31 uint32_t kernel_configuration
;
33 IOLog("%s\n", __PRETTY_FUNCTION__
);
35 if (!super::start(provider
)) {
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");
47 IOLog("Attempting thread_call_allocate\n");
48 tcall
= thread_call_allocate(thread_call_test_func
, this);
49 IOLog("thread_call_t %p\n", tcall
);
51 tlock
= IOSimpleLockAlloc();
52 IOLog("tlock %p\n", tlock
);
54 clock_interval_to_deadline(5, NSEC_PER_SEC
, &deadline
);
55 IOLog("%d sec deadline is %llu\n", 5, deadline
);
57 ret
= thread_call_enter_delayed(tcall
, deadline
);
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
);
63 tlock2
= IOLockAlloc();
64 IOLog("tlock2 %p\n", tlock2
);
66 clock_interval_to_deadline(2, NSEC_PER_SEC
, &deadline
);
67 IOLog("%d sec deadline is %llu\n", 2, deadline
);
69 ret
= thread_call_enter_delayed(tcall2
, deadline
);
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
);
80 clock_interval_to_deadline(4, NSEC_PER_SEC
, &deadline
);
81 IOLog("%d sec deadline is %llu\n", 4, deadline
);
83 ret
= thread_call_enter_delayed(tcall2
, deadline
);
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
);
98 thread_call_test_func(thread_call_param_t param0
,
99 thread_call_param_t param1
)
101 testthreadcall
*self
= (testthreadcall
*)param0
;
103 IOLog("thread_call_test_func %p %p\n", param0
, param1
);
105 IOSimpleLockLock(self
->tlock
);
106 IOSimpleLockUnlock(self
->tlock
);
110 thread_call_test_func2(thread_call_param_t param0
,
111 thread_call_param_t param1
)
113 testthreadcall
*self
= (testthreadcall
*)param0
;
115 IOLog("thread_call_test_func2 %p %p\n", param0
, param1
);
117 IOLockWakeup(self
->tlock2
, &my_event
, false);