-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathSSYBlocker.h
54 lines (43 loc) · 1.38 KB
/
SSYBlocker.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#import <Cocoa/Cocoa.h>
/*!
@brief This class exposes three methods to block a "waiter" thread
until a "worker" thread completes work.
@details The typical usage of an SSYBlocker is:
• Waiter or Worker sends +alloc -init.
• Worker sends -lockLock.
• Worker begins work.
• Waiter sends -blockForLock, which blocks.
• Worker completes work.
• Worker sends -unlockLock
• -blockForLock returns, and Waiter continues its execution
Memory management of an SSYBlocker instance can be dangerous
if you cannot guarantee the order in which the messages will
be sent, or edge cases in which they might be re-sent. If you
don't have too many of these things, you might want to be
conservative and retain them as instance variables of some
long-lived object.
*/
@interface SSYBlocker : NSObject {
NSConditionLock* m_lock ;
}
/*!
@brief Initializes the receiver and its condition lock.
*/
- (id)init ;
/*!
@brief Locks the receiver's condition lock.
*/
- (void)lockLock ;
/*!
@brief Blocks until the receiver's condition lock is unlocked
by -unlockLock.
*/
- (void)blockForLock ;
/*!
@brief Unlocks the receiver's condition lock.
@details Before unlocking the lock, this method checks to see that the
receiver's lock is still locked, so it is OK if, during some edge case
condition, you send this message more than once.
*/
- (void)unlockLock ;
@end