NSConditionLock Class Reference
| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/Foundation.framework |
| Availability | Available in iOS 2.0 and later. |
| Companion guide | |
| Declared in | NSLock.h |
Overview
The NSConditionLock class defines objects whose locks can be associated with specific, user-defined conditions. Using an NSConditionLock object, you can ensure that a thread can acquire a lock only if a certain condition is met. Once it has acquired the lock and executed the critical section of code, the thread can relinquish the lock and set the associated condition to something new. The conditions themselves are arbitrary: you define them as needed for your application.
Adopted Protocols
Tasks
Initializing an NSConditionLock Object
Returning the Condition
Acquiring and Releasing a Lock
-
– lockBeforeDate: -
– lockWhenCondition: -
– lockWhenCondition:beforeDate: -
– tryLock -
– tryLockWhenCondition: -
– unlockWithCondition:
Accessor Methods
Instance Methods
condition
Returns the condition associated with the receiver.
Return Value
The condition associated with the receiver. If no condition has been set, returns 0.
Availability
- Available in iOS 2.0 and later.
Declared In
NSLock.hinitWithCondition:
Initializes a newly allocated NSConditionLock object and sets its condition.
Parameters
- condition
The user-defined condition for the lock. The value of condition is user-defined; see the class description for more information.
Return Value
An initialized condition lock object; may be different than the original receiver.
Availability
- Available in iOS 2.0 and later.
Declared In
NSLock.hlockBeforeDate:
Attempts to acquire a lock before a specified moment in time.
Parameters
- limit
The date by which the lock must be acquired or the attempt will time out.
Return Value
YES if the lock is acquired within the time limit, NO otherwise.
Discussion
The condition associated with the receiver isn’t taken into account in this operation. This method blocks the thread’s execution until the receiver acquires the lock or limit is reached.
Availability
- Available in iOS 2.0 and later.
See Also
Declared In
NSLock.hlockWhenCondition:
Attempts to acquire a lock.
Parameters
- condition
The condition to match on.
Discussion
The receiver’s condition must be equal to condition before the locking operation will succeed. This method blocks the thread’s execution until the lock can be acquired.
Availability
- Available in iOS 2.0 and later.
Declared In
NSLock.hlockWhenCondition:beforeDate:
Attempts to acquire a lock before a specified moment in time.
Parameters
- condition
The condition to match on.
- limit
The date by which the lock must be acquired or the attempt will time out.
Return Value
YES if the lock is acquired within the time limit, NO otherwise.
Discussion
The receiver’s condition must be equal to condition before the locking operation will succeed. This method blocks the thread’s execution until the lock can be acquired or limit is reached.
Availability
- Available in iOS 2.0 and later.
See Also
Declared In
NSLock.hname
Returns the name associated with the receiver.
Return Value
The name of the receiver.
Availability
- Available in iOS 2.0 and later.
See Also
Declared In
NSLock.hsetName:
Assigns a name to the receiver.
Parameters
- newName
The new name for the receiver. This method makes a copy of the specified string.
Discussion
You can use a name string to identify a condition lock within your code. Cocoa also uses this name as part of any error descriptions involving the receiver.
Availability
- Available in iOS 2.0 and later.
See Also
Declared In
NSLock.htryLock
Attempts to acquire a lock without regard to the receiver’s condition.
Return Value
YES if the lock could be acquired, NO otherwise.
Discussion
This method returns immediately.
Availability
- Available in iOS 2.0 and later.
See Also
Declared In
NSLock.htryLockWhenCondition:
Attempts to acquire a lock if the receiver’s condition is equal to the specified condition.
Return Value
YES if the lock could be acquired, NO otherwise.
Discussion
As part of its implementation, this method invokes lockWhenCondition:beforeDate:. This method returns immediately.
Availability
- Available in iOS 2.0 and later.
See Also
Declared In
NSLock.hunlockWithCondition:
Relinquishes the lock and sets the receiver’s condition.
Parameters
- condition
The user-defined condition for the lock. The value of condition is user-defined; see the class description for more information.
Availability
- Available in iOS 2.0 and later.
See Also
Declared In
NSLock.h© 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-01-15)