ATATimerEventSource.cpp [plain text]
#include <sys/cdefs.h>
__BEGIN_DECLS
#include <kern/thread_call.h>
__END_DECLS
#include <IOKit/assert.h>
#include <IOKit/system.h>
#include <IOKit/IOLib.h>
#include <IOKit/IOTimerEventSource.h>
#include <IOKit/IOWorkLoop.h>
#include "ATATimerEventSource.h"
#define super IOTimerEventSource
OSDefineMetaClassAndStructors(ATATimerEventSource, IOTimerEventSource)
OSMetaClassDefineReservedUnused(ATATimerEventSource, 0);
OSMetaClassDefineReservedUnused(ATATimerEventSource, 1);
OSMetaClassDefineReservedUnused(ATATimerEventSource, 2);
OSMetaClassDefineReservedUnused(ATATimerEventSource, 3);
OSMetaClassDefineReservedUnused(ATATimerEventSource, 4);
OSMetaClassDefineReservedUnused(ATATimerEventSource, 5);
OSMetaClassDefineReservedUnused(ATATimerEventSource, 6);
OSMetaClassDefineReservedUnused(ATATimerEventSource, 7);
bool
ATATimerEventSource::hasTimedOut( void )
{
return (hasExpired == kTimedOutTrue);
}
void ATATimerEventSource::myTimeout(void *self)
{
ATATimerEventSource *me = (ATATimerEventSource *) self;
OSCompareAndSwap( kTimedOutFalse, kTimedOutTrue, &(me->hasExpired) );
if (me->enabled)
{
Action doit = (Action) me->action;
if (doit)
{
me->closeGate();
(*doit)(me->owner, me);
me->openGate();
}
}
}
void ATATimerEventSource::setTimeoutFunc()
{
calloutEntry = (void *) thread_call_allocate((thread_call_func_t) myTimeout,
(thread_call_param_t) this);
}
bool ATATimerEventSource::init(OSObject *inOwner, Action inAction)
{
if ( !super::init( (OSObject *)inOwner, (Action) inAction) )
return false;
hasExpired = kTimedOutFalse;
return true;
}
ATATimerEventSource *
ATATimerEventSource::ataTimerEventSource(OSObject *inOwner, Action inAction)
{
ATATimerEventSource *me = new ATATimerEventSource;
if (me && !me->init(inOwner, inAction)) {
me->free();
return 0;
}
return me;
}
void ATATimerEventSource::cancelTimeout()
{
hasExpired = kTimedOutFalse;
super::cancelTimeout();
}
void ATATimerEventSource::enable()
{
hasExpired = kTimedOutFalse;
super::enable();
}
void ATATimerEventSource::disable()
{
hasExpired = kTimedOutFalse;
super::disable();
}
IOReturn ATATimerEventSource::wakeAtTime(UnsignedWide inAbstime)
{
hasExpired = kTimedOutFalse;
#if ABSOLUTETIME_SCALAR_TYPE
UInt64 abstime = (UInt64)inAbstime.hi << 32 | (UInt64)inAbstime.lo;
return super::wakeAtTime( abstime );
#else
return super::wakeAtTime(inAbstime);
#endif
}