]> git.saurik.com Git - apple/xnu.git/blob - iokit/IOKit/IOConditionLock.h
02c16e2647c9fe901c3337401f65957e1643c7a3
[apple/xnu.git] / iokit / IOKit / IOConditionLock.h
1 /*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
24 * Copyright (c) 1994-1996 NeXT Software, Inc. All rights reserved.
25 */
26
27 #ifndef _IOKIT_IOCONDITIONLOCK_H
28 #define _IOKIT_IOCONDITIONLOCK_H
29
30 #include <libkern/c++/OSObject.h>
31 #include <IOKit/IOLib.h>
32 #include <IOKit/system.h>
33
34 #include <IOKit/IOLocks.h>
35
36 class IOConditionLock : public OSObject
37 {
38 OSDeclareDefaultStructors(IOConditionLock)
39
40 private:
41 IOLock * cond_interlock; // condition var Simple lock
42 volatile int condition;
43
44 IOLock * sleep_interlock; // sleep lock Simple lock
45 unsigned char interruptible;
46 volatile bool want_lock;
47 volatile bool waiting;
48
49 public:
50 static IOConditionLock *withCondition(int condition, bool inIntr = true);
51 virtual bool initWithCondition(int condition, bool inIntr = true);
52 virtual void free();
53
54 virtual bool tryLock(); // acquire lock, no waiting
55 virtual int lock(); // acquire lock (enter critical section)
56 virtual void unlock(); // release lock (leave critical section)
57
58 virtual bool getInterruptible() const;
59 virtual int getCondition() const;
60 virtual int setCondition(int condition);
61
62 virtual int lockWhen(int condition); // acquire lock when condition
63 virtual void unlockWith(int condition); // set condition & release lock
64 };
65
66 #endif /* _IOKIT_IOCONDITIONLOCK_H */