]> git.saurik.com Git - apple/xnu.git/blobdiff - iokit/Kernel/IOTimerEventSource.cpp
xnu-4903.231.4.tar.gz
[apple/xnu.git] / iokit / Kernel / IOTimerEventSource.cpp
index bb7acea43efec84572baca882b1cab561810fe2b..22987d8b82975c845759ca0cbacfff6e52050e2b 100644 (file)
@@ -45,6 +45,9 @@ __END_DECLS
 #include <mach/sdt.h>
 #endif
 
+#include <libkern/Block.h>
+
+
 #define super IOEventSource
 OSDefineMetaClassAndStructors(IOTimerEventSource, IOEventSource)
 OSMetaClassDefineReservedUsed(IOTimerEventSource, 0);
@@ -96,8 +99,8 @@ do { \
 // the timeout interval expires.
 //
 
-static __inline__ void
-InvokeAction(IOTimerEventSource::Action action, IOTimerEventSource * ts,
+__inline__ void
+IOTimerEventSource::invokeAction(IOTimerEventSource::Action action, IOTimerEventSource * ts,
             OSObject * owner, IOWorkLoop * workLoop)
 {
     bool    trace = (gIOKitTrace & kIOTraceTimers) ? true : false;
@@ -106,7 +109,8 @@ InvokeAction(IOTimerEventSource::Action action, IOTimerEventSource * ts,
        IOTimeStampStartConstant(IODBG_TIMES(IOTIMES_ACTION),
                                 VM_KERNEL_ADDRHIDE(action), VM_KERNEL_ADDRHIDE(owner));
 
-    (*action)(owner, ts);
+    if (kActionBlock & flags) ((IOTimerEventSource::ActionBlock) actionBlock)(ts);
+    else                      (*action)(owner, ts);
 
 #if CONFIG_DTRACE
     DTRACE_TMR3(iotescallout__expire, Action, action, OSObject, owner, void, workLoop);
@@ -135,7 +139,7 @@ void IOTimerEventSource::timeout(void *self)
             doit = (Action) me->action;
             if (doit && me->enabled && AbsoluteTime_to_scalar(&me->abstime))
             {
-                InvokeAction(doit, me, me->owner, me->workLoop);
+                me->invokeAction(doit, me, me->owner, me->workLoop);
             }
             IOStatisticsOpenGate();
             wl->openGate();
@@ -164,7 +168,7 @@ void IOTimerEventSource::timeoutAndRelease(void * self, void * c)
             doit = (Action) me->action;
             if (doit && (me->reserved->calloutGeneration == count))
             {
-                InvokeAction(doit, me, me->owner, me->workLoop);
+                me->invokeAction(doit, me, me->owner, me->workLoop);
             }
             IOStatisticsOpenGate();
             wl->openGate();
@@ -186,7 +190,7 @@ bool IOTimerEventSource::checkForWork()
      && enabled && (doit = (Action) action))
     {
        reserved->calloutGenerationSignaled = ~reserved->calloutGeneration;
-       InvokeAction(doit, this, owner, workLoop);
+       invokeAction(doit, this, owner, workLoop);
     }
 
     return false;
@@ -303,6 +307,16 @@ IOTimerEventSource::timerEventSource(uint32_t inOptions, OSObject *inOwner, Acti
     return me;
 }
 
+IOTimerEventSource *
+IOTimerEventSource::timerEventSource(uint32_t options, OSObject *inOwner, ActionBlock action)
+{
+    IOTimerEventSource * tes;
+    tes = IOTimerEventSource::timerEventSource(options, inOwner, (Action) NULL);
+    if (tes) tes->setActionBlock((IOEventSource::ActionBlock) action);
+
+    return tes;
+}
+
 #define _thread_call_cancel(tc)   ((kActive & flags) ? thread_call_cancel_wait((tc)) : thread_call_cancel((tc)))
 
 IOTimerEventSource *
@@ -412,9 +426,12 @@ IOReturn IOTimerEventSource::setTimeout(uint32_t options,
                                        AbsoluteTime abstime, AbsoluteTime leeway)
 {
     AbsoluteTime end;
-    clock_continuoustime_interval_to_deadline(abstime, &end);
-    return wakeAtTime(options, end, leeway);
+    if (options & kIOTimeOptionsContinuous)
+        clock_continuoustime_interval_to_deadline(abstime, &end);
+    else
+        clock_absolutetime_interval_to_deadline(abstime, &end);
 
+    return wakeAtTime(options, end, leeway);
 }
 
 IOReturn IOTimerEventSource::wakeAtTimeTicks(UInt32 ticks)