1996-02-13 15:40:05 +00:00
|
|
|
/*
|
|
|
|
NSLock.h
|
1995-04-03 20:49:14 +00:00
|
|
|
|
1996-02-13 15:40:05 +00:00
|
|
|
Definitions for locking protocol and classes
|
|
|
|
|
|
|
|
Copyright (C) 1996 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Author: Scott Christley <scottc@net-community.com>
|
|
|
|
Date: 1996
|
|
|
|
|
|
|
|
This file is part of the GNUstep Objective-C Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
If you are interested in a warranty or support for this source code,
|
|
|
|
contact Scott Christley <scottc@net-community.com> for more information.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
License along with this library; if not, write to the Free
|
1999-09-09 02:56:20 +00:00
|
|
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
1996-02-13 15:40:05 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _GNUstep_H_NSLock
|
|
|
|
#define _GNUstep_H_NSLock
|
|
|
|
|
|
|
|
#include <Foundation/NSObject.h>
|
2001-04-24 03:19:30 +00:00
|
|
|
#ifdef NeXT_RUNTIME
|
2003-07-31 23:49:32 +00:00
|
|
|
#include <GNUstepBase/thr-mach.h>
|
2001-04-12 17:16:55 +00:00
|
|
|
#endif
|
1996-02-13 15:40:05 +00:00
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
/*
|
|
|
|
* NSLocking protocol
|
|
|
|
*/
|
1995-04-03 20:49:14 +00:00
|
|
|
@protocol NSLocking
|
1996-02-13 15:40:05 +00:00
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
- (void) lock;
|
|
|
|
- (void) unlock;
|
1996-02-13 15:40:05 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
/*
|
|
|
|
* NSLock class
|
|
|
|
* Simplest lock for protecting critical sections of code
|
|
|
|
*/
|
2000-09-14 08:48:05 +00:00
|
|
|
@interface NSLock : NSObject <NSLocking, GCFinalization>
|
1996-02-13 15:40:05 +00:00
|
|
|
{
|
|
|
|
@private
|
1999-09-16 07:21:34 +00:00
|
|
|
objc_mutex_t _mutex;
|
1996-02-13 15:40:05 +00:00
|
|
|
}
|
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
- (BOOL) tryLock;
|
|
|
|
- (BOOL) lockBeforeDate: (NSDate*)limit;
|
1996-02-13 15:40:05 +00:00
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
- (void) lock;
|
|
|
|
- (void) unlock;
|
1996-02-13 15:40:05 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
/*
|
|
|
|
* NSConditionLock
|
|
|
|
* Allows locking and unlocking to be based upon a condition
|
|
|
|
*/
|
2000-09-14 08:48:05 +00:00
|
|
|
@interface NSConditionLock : NSObject <NSLocking, GCFinalization>
|
1996-02-13 15:40:05 +00:00
|
|
|
{
|
|
|
|
@private
|
1999-09-16 07:21:34 +00:00
|
|
|
objc_condition_t _condition;
|
|
|
|
objc_mutex_t _mutex;
|
|
|
|
int _condition_value;
|
1996-02-13 15:40:05 +00:00
|
|
|
}
|
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
/*
|
|
|
|
* Initialize lock with condition
|
|
|
|
*/
|
|
|
|
- (id) initWithCondition: (int)value;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the current condition of the lock
|
|
|
|
*/
|
|
|
|
- (int) condition;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Acquiring and release the lock
|
|
|
|
*/
|
|
|
|
- (void) lockWhenCondition: (int)value;
|
|
|
|
- (void) unlockWithCondition: (int)value;
|
|
|
|
- (BOOL) tryLock;
|
|
|
|
- (BOOL) tryLockWhenCondition: (int)value;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Acquiring the lock with a date condition
|
|
|
|
*/
|
|
|
|
- (BOOL) lockBeforeDate: (NSDate*)limit;
|
2001-12-17 14:31:42 +00:00
|
|
|
- (BOOL) lockWhenCondition: (int)condition_to_meet
|
|
|
|
beforeDate: (NSDate*)limitDate;
|
1999-09-16 07:21:34 +00:00
|
|
|
|
|
|
|
- (void) lock;
|
|
|
|
- (void) unlock;
|
1996-02-13 15:40:05 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
/*
|
|
|
|
* NSRecursiveLock
|
|
|
|
* Allows the lock to be recursively acquired by the same thread
|
|
|
|
*
|
|
|
|
* If the same thread locks the mutex (n) times then that same
|
|
|
|
* thread must also unlock it (n) times before another thread
|
|
|
|
* can acquire the lock.
|
|
|
|
*/
|
2000-09-14 08:48:05 +00:00
|
|
|
@interface NSRecursiveLock : NSObject <NSLocking, GCFinalization>
|
1996-02-13 15:40:05 +00:00
|
|
|
{
|
|
|
|
@private
|
1999-09-16 07:21:34 +00:00
|
|
|
objc_mutex_t _mutex;
|
1996-02-13 15:40:05 +00:00
|
|
|
}
|
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
- (BOOL) tryLock;
|
|
|
|
- (BOOL) lockBeforeDate: (NSDate*)limit;
|
1996-02-13 15:40:05 +00:00
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
- (void) lock;
|
|
|
|
- (void) unlock;
|
1996-02-13 15:40:05 +00:00
|
|
|
|
1995-04-03 20:49:14 +00:00
|
|
|
@end
|
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
#endif /* _GNUstep_H_NSLock*/
|