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