]> git.saurik.com Git - apple/xnu.git/blame - iokit/Kernel/IOPMPowerStateQueue.cpp
xnu-7195.81.3.tar.gz
[apple/xnu.git] / iokit / Kernel / IOPMPowerStateQueue.cpp
CommitLineData
55e303ae
A
1/*
2 * Copyright (c) 2001-2002 Apple Computer, Inc. All rights reserved.
3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
0a7de745 5 *
2d21ac55
A
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. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
0a7de745 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
0a7de745 17 *
2d21ac55
A
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
0a7de745 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
55e303ae 27 */
0a7de745 28
55e303ae 29#include "IOPMPowerStateQueue.h"
0c530ab8 30
b0d623f7
A
31#define super IOEventSource
32OSDefineMetaClassAndStructors( IOPMPowerStateQueue, IOEventSource )
0c530ab8 33
b0d623f7 34IOPMPowerStateQueue * IOPMPowerStateQueue::PMPowerStateQueue(
0a7de745 35 OSObject * inOwner, Action inAction )
55e303ae 36{
0a7de745 37 IOPMPowerStateQueue * me = new IOPMPowerStateQueue;
55e303ae 38
0a7de745
A
39 if (me && !me->init(inOwner, inAction)) {
40 me->release();
41 return NULL;
42 }
55e303ae 43
0a7de745 44 return me;
55e303ae
A
45}
46
0a7de745
A
47bool
48IOPMPowerStateQueue::init( OSObject * inOwner, Action inAction )
55e303ae 49{
0a7de745
A
50 if (!inAction || !(super::init(inOwner, inAction))) {
51 return false;
52 }
b0d623f7 53
0a7de745 54 queue_init( &queueHead );
b0d623f7 55
0a7de745
A
56 queueLock = IOLockAlloc();
57 if (!queueLock) {
58 return false;
59 }
55e303ae 60
0a7de745 61 return true;
55e303ae
A
62}
63
0a7de745
A
64bool
65IOPMPowerStateQueue::submitPowerEvent(
66 uint32_t eventType,
67 void * arg0,
68 uint64_t arg1 )
55e303ae 69{
0a7de745 70 PowerEventEntry * entry;
b0d623f7 71
0a7de745
A
72 entry = IONew(PowerEventEntry, 1);
73 if (!entry) {
74 return false;
75 }
b0d623f7 76
0a7de745
A
77 entry->eventType = eventType;
78 entry->arg0 = arg0;
79 entry->arg1 = arg1;
b0d623f7 80
0a7de745
A
81 IOLockLock(queueLock);
82 queue_enter(&queueHead, entry, PowerEventEntry *, chain);
83 IOLockUnlock(queueLock);
84 signalWorkAvailable();
2d21ac55 85
0a7de745 86 return true;
2d21ac55
A
87}
88
0a7de745
A
89bool
90IOPMPowerStateQueue::checkForWork( void )
2d21ac55 91{
0a7de745
A
92 IOPMPowerStateQueueAction queueAction = (IOPMPowerStateQueueAction) action;
93 PowerEventEntry * entry;
55e303ae 94
b0d623f7 95 IOLockLock(queueLock);
0a7de745
A
96 while (!queue_empty(&queueHead)) {
97 queue_remove_first(&queueHead, entry, PowerEventEntry *, chain);
b0d623f7 98 IOLockUnlock(queueLock);
55e303ae 99
0a7de745
A
100 (*queueAction)(owner, entry->eventType, entry->arg0, entry->arg1);
101 IODelete(entry, PowerEventEntry, 1);
2d21ac55 102
0a7de745 103 IOLockLock(queueLock);
b0d623f7
A
104 }
105 IOLockUnlock(queueLock);
106
0a7de745 107 return false;
55e303ae 108}