7 #include "testthreadcall.h"
9 #include <kern/thread_call.h>
10 #include <pexpert/pexpert.h>
12 #define super IOService
13 OSDefineMetaClassAndStructors(testthreadcall
, super
);
17 static void thread_call_test_func(thread_call_param_t param0
,
18 thread_call_param_t param1
);
20 static void thread_call_test_func2(thread_call_param_t param0
,
21 thread_call_param_t param1
);
28 testthreadcall::start( IOService
* provider
)
33 uint32_t kernel_configuration
;
35 IOLog("%s\n", __PRETTY_FUNCTION__
);
37 if (!super::start(provider
)) {
41 kernel_configuration
= PE_i_can_has_kernel_configuration();
42 IOLog("%s: Assertions %s\n", __PRETTY_FUNCTION__
,
43 (kernel_configuration
& kPEICanHasAssertions
) ? "enabled" : "disabled");
44 IOLog("%s: Statistics %s\n", __PRETTY_FUNCTION__
,
45 (kernel_configuration
& kPEICanHasStatistics
) ? "enabled" : "disabled");
46 IOLog("%s: Diagnostic API %s\n", __PRETTY_FUNCTION__
,
47 (kernel_configuration
& kPEICanHasDiagnosticAPI
) ? "enabled" : "disabled");
49 IOLog("Attempting thread_call_allocate\n");
50 tcall
= thread_call_allocate(thread_call_test_func
, this);
51 IOLog("thread_call_t %p\n", tcall
);
53 tlock
= IOSimpleLockAlloc();
54 IOLog("tlock %p\n", tlock
);
56 clock_interval_to_deadline(5, NSEC_PER_SEC
, &deadline
);
57 IOLog("%d sec deadline is %llu\n", 5, deadline
);
59 ret
= thread_call_enter_delayed(tcall
, deadline
);
61 IOLog("Attempting thread_call_allocate\n");
62 tcall2
= thread_call_allocate(thread_call_test_func2
, this);
63 IOLog("thread_call_t %p\n", tcall
);
65 tlock2
= IOLockAlloc();
66 IOLog("tlock2 %p\n", tlock2
);
68 clock_interval_to_deadline(2, NSEC_PER_SEC
, &deadline
);
69 IOLog("%d sec deadline is %llu\n", 2, deadline
);
71 ret
= thread_call_enter_delayed(tcall2
, deadline
);
75 clock_interval_to_deadline(3, NSEC_PER_SEC
, &deadline
);
76 IOLog("%d sec deadline is %llu\n", 3, deadline
);
77 sleepret
= IOLockSleepDeadline(tlock2
, &my_event
, deadline
, THREAD_INTERRUPTIBLE
);
78 IOLog("IOLockSleepDeadline(&my_event, %llu) returned %d, expected 0\n", deadline
, sleepret
);
82 clock_interval_to_deadline(4, NSEC_PER_SEC
, &deadline
);
83 IOLog("%d sec deadline is %llu\n", 4, deadline
);
85 ret
= thread_call_enter_delayed(tcall2
, deadline
);
89 clock_interval_to_deadline(3, NSEC_PER_SEC
, &deadline
);
90 IOLog("%d sec deadline is %llu\n", 3, deadline
);
91 sleepret
= IOLockSleepDeadline(tlock2
, &my_event
, deadline
, THREAD_INTERRUPTIBLE
);
92 IOLog("IOLockSleepDeadline(&my_event, %llu) returned %d, expected 1\n", deadline
, sleepret
);
99 static void thread_call_test_func(thread_call_param_t param0
,
100 thread_call_param_t param1
)
102 testthreadcall
*self
= (testthreadcall
*)param0
;
104 IOLog("thread_call_test_func %p %p\n", param0
, param1
);
106 IOSimpleLockLock(self
->tlock
);
107 IOSimpleLockUnlock(self
->tlock
);
110 static void 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);