]>
git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/IOSyncer.cpp
2 * Copyright (c) 1998-2000 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@
25 /* IOSyncer.cpp created by wgulland on 2000-02-02 */
27 #include <IOKit/IOLib.h>
28 #include <IOKit/IOSyncer.h>
30 OSDefineMetaClassAndStructors(IOSyncer
, OSObject
)
32 IOSyncer
* IOSyncer::create(bool twoRetains
)
34 IOSyncer
* me
= new IOSyncer
;
36 if (me
&& !me
->init(twoRetains
)) {
44 bool IOSyncer::init(bool twoRetains
)
46 if (!OSObject::init())
49 if (!(guardLock
= IOSimpleLockAlloc()) )
52 IOSimpleLockInit(guardLock
);
57 fResult
= kIOReturnSuccess
;
64 void IOSyncer::reinit()
66 IOInterruptState is
= IOSimpleLockLockDisableInterrupt(guardLock
);
67 threadMustStop
= true;
68 IOSimpleLockUnlockEnableInterrupt(guardLock
, is
);
73 // just in case a thread is blocked here:
76 if (guardLock
!= NULL
)
77 IOSimpleLockFree(guardLock
);
82 IOReturn
IOSyncer::wait(bool autoRelease
= true)
84 IOInterruptState is
= IOSimpleLockLockDisableInterrupt(guardLock
);
87 assert_wait((void *) &threadMustStop
, false);
88 IOSimpleLockUnlockEnableInterrupt(guardLock
, is
);
89 thread_block(THREAD_CONTINUE_NULL
);
92 IOSimpleLockUnlockEnableInterrupt(guardLock
, is
);
94 IOReturn result
= fResult
; // Pick up before auto deleting!
102 void IOSyncer::signal(IOReturn res
= kIOReturnSuccess
,
103 bool autoRelease
= true)
111 void IOSyncer::privateSignal()
113 if (threadMustStop
) {
114 IOInterruptState is
= IOSimpleLockLockDisableInterrupt(guardLock
);
115 threadMustStop
= false;
116 thread_wakeup_one((void *) &threadMustStop
);
117 IOSimpleLockUnlockEnableInterrupt(guardLock
, is
);