]>
git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/IOPMPowerStateQueue.cpp
1fd0f6b9019b7b9a3dff7c696a82ecad152ebd49
2 * Copyright (c) 2001-2002 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 #include "IOPMPowerStateQueue.h"
26 #define super IOEventSource
27 OSDefineMetaClassAndStructors(IOPMPowerStateQueue
, IOEventSource
);
29 IOPMPowerStateQueue
*IOPMPowerStateQueue::PMPowerStateQueue(OSObject
*inOwner
)
31 IOPMPowerStateQueue
*me
= new IOPMPowerStateQueue
;
33 if(me
&& !me
->init(inOwner
, 0) )
42 bool IOPMPowerStateQueue::init(OSObject
*owner
, Action action
)
44 if(!(super::init(owner
, (IOEventSource::Action
) action
))) return false;
46 // Queue of powerstate changes
53 bool IOPMPowerStateQueue::unIdleOccurred(IOService
*inTarget
, unsigned long inState
)
55 PowerChangeEntry
*new_one
= NULL
;
57 new_one
= (PowerChangeEntry
*)IOMalloc(sizeof(PowerChangeEntry
));
58 if(!new_one
) return false;
60 new_one
->actionType
= IOPMPowerStateQueue::kUnIdle
;
61 new_one
->state
= inState
;
62 new_one
->target
= inTarget
;
65 OSEnqueueAtomic((void **)&changes
, (void *)new_one
, 0);
67 signalWorkAvailable();
72 // checkForWork() is called in a gated context
73 bool IOPMPowerStateQueue::checkForWork()
75 PowerChangeEntry
*theNode
;
80 // Dequeue and process the state change request
81 if((theNode
= (PowerChangeEntry
*)OSDequeueAtomic((void **)&changes
, 0)))
83 theState
= theNode
->state
;
84 theTarget
= theNode
->target
;
85 theAction
= theNode
->actionType
;
86 IOFree((void *)theNode
, sizeof(PowerChangeEntry
));
91 theTarget
->command_received(theState
, 0, 0, 0);
96 // Return true if there's more work to be done
97 if(changes
) return true;