IOPMPowerStateQueue.cpp [plain text]
#include "IOPMPowerStateQueue.h"
#undef super
#define super IOEventSource
OSDefineMetaClassAndStructors(IOPMPowerStateQueue, IOEventSource);
IOPMPowerStateQueue *IOPMPowerStateQueue::PMPowerStateQueue(OSObject *inOwner)
{
IOPMPowerStateQueue *me = new IOPMPowerStateQueue;
if(me && !me->init(inOwner, 0) )
{
me->release();
return NULL;
}
return me;
}
bool IOPMPowerStateQueue::init(OSObject *owner, Action action)
{
if(!(super::init(owner, (IOEventSource::Action) action))) return false;
changes = NULL;
return true;
}
bool IOPMPowerStateQueue::unIdleOccurred(IOService *inTarget, unsigned long inState)
{
PowerChangeEntry *new_one = NULL;
new_one = (PowerChangeEntry *)IOMalloc(sizeof(PowerChangeEntry));
if(!new_one) return false;
new_one->actionType = IOPMPowerStateQueue::kUnIdle;
new_one->state = inState;
new_one->target = inTarget;
OSEnqueueAtomic((void **)&changes, (void *)new_one, 0);
signalWorkAvailable();
return true;
}
bool IOPMPowerStateQueue::checkForWork()
{
PowerChangeEntry *theNode;
int theState;
IOService *theTarget;
UInt16 theAction;
if((theNode = (PowerChangeEntry *)OSDequeueAtomic((void **)&changes, 0)))
{
theState = theNode->state;
theTarget = theNode->target;
theAction = theNode->actionType;
IOFree((void *)theNode, sizeof(PowerChangeEntry));
switch (theAction)
{
case kUnIdle:
theTarget->command_received(theState, 0, 0, 0);
break;
}
}
if(changes) return true;
else return false;
}