]>
git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/IOSyncer.cpp
9099daa5711d22ee6c5ae589644b9befefebfdb3
2 * Copyright (c) 1998-2000 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@
23 /* IOSyncer.cpp created by wgulland on 2000-02-02 */
25 #include <IOKit/IOLib.h>
26 #include <IOKit/IOSyncer.h>
28 OSDefineMetaClassAndStructors(IOSyncer
, OSObject
)
30 IOSyncer
* IOSyncer::create(bool twoRetains
)
32 IOSyncer
* me
= new IOSyncer
;
34 if (me
&& !me
->init(twoRetains
)) {
42 bool IOSyncer::init(bool twoRetains
)
44 if (!OSObject::init())
47 if (!(guardLock
= IOSimpleLockAlloc()) )
50 IOSimpleLockInit(guardLock
);
55 fResult
= kIOReturnSuccess
;
62 void IOSyncer::reinit()
64 IOInterruptState is
= IOSimpleLockLockDisableInterrupt(guardLock
);
65 threadMustStop
= true;
66 IOSimpleLockUnlockEnableInterrupt(guardLock
, is
);
71 // just in case a thread is blocked here:
74 if (guardLock
!= NULL
)
75 IOSimpleLockFree(guardLock
);
80 IOReturn
IOSyncer::wait(bool autoRelease
)
82 IOInterruptState is
= IOSimpleLockLockDisableInterrupt(guardLock
);
85 assert_wait((void *) &threadMustStop
, false);
86 IOSimpleLockUnlockEnableInterrupt(guardLock
, is
);
87 thread_block(THREAD_CONTINUE_NULL
);
90 IOSimpleLockUnlockEnableInterrupt(guardLock
, is
);
92 IOReturn result
= fResult
; // Pick up before auto deleting!
100 void IOSyncer::signal(IOReturn res
, bool autoRelease
)
108 void IOSyncer::privateSignal()
110 if (threadMustStop
) {
111 IOInterruptState is
= IOSimpleLockLockDisableInterrupt(guardLock
);
112 threadMustStop
= false;
113 thread_wakeup_one((void *) &threadMustStop
);
114 IOSimpleLockUnlockEnableInterrupt(guardLock
, is
);