Commit file accidentally omitted earlier.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@18039 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2003-11-03 06:27:52 +00:00
parent 6f9e959f46
commit 2d71ebd08f

View file

@ -34,6 +34,7 @@
#include "Foundation/NSException.h" #include "Foundation/NSException.h"
#include "Foundation/NSLock.h" #include "Foundation/NSLock.h"
#include "Foundation/NSThread.h" #include "Foundation/NSThread.h"
#include "GNUstepBase/GSLock.h"
/** /**
@ -208,6 +209,8 @@ static void obsFree(Observation *o);
#include "GNUstepBase/GSIMap.h" #include "GNUstepBase/GSIMap.h"
@class GSLazyRecursiveLock;
/* /*
* An NC table is used to keep track of memory allocated to store * An NC table is used to keep track of memory allocated to store
* Observation structures. When an Observation is removed from the * Observation structures. When an Observation is removed from the
@ -237,9 +240,7 @@ typedef struct NCTbl {
GSIMapTable named; /* Getting named messages only. */ GSIMapTable named; /* Getting named messages only. */
GSIArray array; /* Temp store during posting. */ GSIArray array; /* Temp store during posting. */
unsigned lockCount; /* Count recursive operations. */ unsigned lockCount; /* Count recursive operations. */
NSRecursiveLock *_lock; /* Lock out other threads. */ GSLazyRecursiveLock *_lock; /* Lock out other threads. */
IMP lImp;
IMP uImp;
BOOL lockingDisabled; BOOL lockingDisabled;
BOOL immutableInPost; BOOL immutableInPost;
@ -415,16 +416,16 @@ static NCTable *newNCTable(void)
static inline void lockNCTable(NCTable* t) static inline void lockNCTable(NCTable* t)
{ {
if (t->_lock != nil && t->lockingDisabled == NO) if (t->lockingDisabled == NO)
(*t->lImp)(t->_lock, @selector(lock)); [t->_lock lock];
t->lockCount++; t->lockCount++;
} }
static inline void unlockNCTable(NCTable* t) static inline void unlockNCTable(NCTable* t)
{ {
t->lockCount--; t->lockCount--;
if (t->_lock != nil && t->lockingDisabled == NO) if (t->lockingDisabled == NO)
(*t->uImp)(t->_lock, @selector(unlock)); [t->_lock unlock];
} }
static void obsFree(Observation *o) static void obsFree(Observation *o)
@ -582,42 +583,13 @@ static NSNotificationCenter *default_center = nil;
/* Initializing. */ /* Initializing. */
- (void) _becomeThreaded: (NSNotification*)notification
{
unsigned count;
TABLE->_lock = [NSRecursiveLock new];
TABLE->lImp = [TABLE->_lock methodForSelector: @selector(lock)];
TABLE->uImp = [TABLE->_lock methodForSelector: @selector(unlock)];
count = LOCKCOUNT;
/*
* If we start locking inside a method that would normally have been
* locked, we must lock the lock enough times so that when we leave
* the method the number of unlocks will match.
*/
while (count-- > 0)
{
(*TABLE->lImp)(TABLE->_lock, @selector(lock));
}
}
- (id) init - (id) init
{ {
[super init]; if ((self = [super init]) != nil)
TABLE = newNCTable();
if ([NSThread isMultiThreaded])
{ {
[self _becomeThreaded: nil]; TABLE = newNCTable();
TABLE->_lock = [GSLazyRecursiveLock new];
} }
else
{
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: @selector(_becomeThreaded:)
name: NSWillBecomeMultiThreadedNotification
object: nil];
}
return self; return self;
} }