]>
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 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* IOSyncer.cpp created by wgulland on 2000-02-02 */
24 #include <IOKit/IOLib.h>
25 #include <IOKit/IOSyncer.h>
27 OSDefineMetaClassAndStructors(IOSyncer
, OSObject
)
29 IOSyncer
* IOSyncer::create(bool twoRetains
)
31 IOSyncer
* me
= new IOSyncer
;
33 if (me
&& !me
->init(twoRetains
)) {
41 bool IOSyncer::init(bool twoRetains
)
43 if (!OSObject::init())
46 if (!(guardLock
= IOSimpleLockAlloc()) )
49 IOSimpleLockInit(guardLock
);
54 fResult
= kIOReturnSuccess
;
61 void IOSyncer::reinit()
63 IOInterruptState is
= IOSimpleLockLockDisableInterrupt(guardLock
);
64 threadMustStop
= true;
65 IOSimpleLockUnlockEnableInterrupt(guardLock
, is
);
70 // just in case a thread is blocked here:
73 if (guardLock
!= NULL
)
74 IOSimpleLockFree(guardLock
);
79 IOReturn
IOSyncer::wait(bool autoRelease
)
81 IOInterruptState is
= IOSimpleLockLockDisableInterrupt(guardLock
);
84 assert_wait((void *) &threadMustStop
, false);
85 IOSimpleLockUnlockEnableInterrupt(guardLock
, is
);
86 thread_block(THREAD_CONTINUE_NULL
);
89 IOSimpleLockUnlockEnableInterrupt(guardLock
, is
);
91 IOReturn result
= fResult
; // Pick up before auto deleting!
99 void IOSyncer::signal(IOReturn res
, bool autoRelease
)
107 void IOSyncer::privateSignal()
109 if (threadMustStop
) {
110 IOInterruptState is
= IOSimpleLockLockDisableInterrupt(guardLock
);
111 threadMustStop
= false;
112 thread_wakeup_one((void *) &threadMustStop
);
113 IOSimpleLockUnlockEnableInterrupt(guardLock
, is
);