mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 08:21:25 +00:00
More simplification by using lazy locking
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@18559 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
4b431aa0cc
commit
5ffc526cbc
9 changed files with 37 additions and 350 deletions
|
@ -23,6 +23,7 @@
|
|||
|
||||
#include "config.h"
|
||||
#include "GNUstepBase/preface.h"
|
||||
#include "GNUstepBase/GSLock.h"
|
||||
#include "Foundation/NSArray.h"
|
||||
#include "Foundation/NSNotification.h"
|
||||
#include "Foundation/NSException.h"
|
||||
|
@ -104,8 +105,6 @@
|
|||
(sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path))
|
||||
#endif
|
||||
|
||||
static BOOL multi_threaded = NO;
|
||||
|
||||
/*
|
||||
* Largest chunk of data possible in DO
|
||||
*/
|
||||
|
@ -343,10 +342,7 @@ static Class runLoopClass;
|
|||
handle = (GSMessageHandle*)NSAllocateObject(self, 0, NSDefaultMallocZone());
|
||||
handle->desc = d;
|
||||
handle->wMsgs = [NSMutableArray new];
|
||||
if (multi_threaded == YES)
|
||||
{
|
||||
handle->myLock = [NSRecursiveLock new];
|
||||
}
|
||||
handle->myLock = [GSLazyRecursiveLock new];
|
||||
handle->valid = YES;
|
||||
return AUTORELEASE(handle);
|
||||
}
|
||||
|
@ -1167,54 +1163,6 @@ static void clean_up_sockets(void)
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* When the system becomes multithreaded, we set a flag to say so and
|
||||
* make sure that port and handle locking is enabled.
|
||||
*/
|
||||
+ (void) _becomeThreaded: (NSNotification*)notification
|
||||
{
|
||||
if (multi_threaded == NO)
|
||||
{
|
||||
NSMapEnumerator mEnum;
|
||||
NSMessagePort *p;
|
||||
void *dummy;
|
||||
|
||||
multi_threaded = YES;
|
||||
if (messagePortLock == nil)
|
||||
{
|
||||
messagePortLock = [NSRecursiveLock new];
|
||||
}
|
||||
mEnum = NSEnumerateMapTable(messagePortMap);
|
||||
while (NSNextMapEnumeratorPair(&mEnum, &dummy, (void**)&p))
|
||||
{
|
||||
if ([p isValid] == YES)
|
||||
{
|
||||
NSMapEnumerator hEnum;
|
||||
GSMessageHandle *h;
|
||||
|
||||
if (p->myLock == nil)
|
||||
{
|
||||
p->myLock = [NSRecursiveLock new];
|
||||
}
|
||||
hEnum = NSEnumerateMapTable(p->handles);
|
||||
while (NSNextMapEnumeratorPair(&hEnum, &dummy, (void**)&h))
|
||||
{
|
||||
if ([h isValid] == YES && h->myLock == nil)
|
||||
{
|
||||
h->myLock = [NSRecursiveLock new];
|
||||
}
|
||||
}
|
||||
NSEndMapTableEnumeration(&hEnum);
|
||||
}
|
||||
}
|
||||
NSEndMapTableEnumeration(&mEnum);
|
||||
}
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
removeObserver: self
|
||||
name: NSWillBecomeMultiThreadedNotification
|
||||
object: nil];
|
||||
}
|
||||
|
||||
#if NEED_WORD_ALIGNMENT
|
||||
static unsigned wordAlign;
|
||||
#endif
|
||||
|
@ -1230,18 +1178,7 @@ static unsigned wordAlign;
|
|||
messagePortMap = NSCreateMapTable(NSNonRetainedObjectMapKeyCallBacks,
|
||||
NSNonOwnedPointerMapValueCallBacks, 0);
|
||||
|
||||
if ([NSThread isMultiThreaded])
|
||||
{
|
||||
[self _becomeThreaded: nil];
|
||||
}
|
||||
else
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver: self
|
||||
selector: @selector(_becomeThreaded:)
|
||||
name: NSWillBecomeMultiThreadedNotification
|
||||
object: nil];
|
||||
}
|
||||
messagePortLock = [GSLazyRecursiveLock new];
|
||||
atexit(clean_up_sockets);
|
||||
}
|
||||
}
|
||||
|
@ -1294,10 +1231,7 @@ static int unique_index = 0;
|
|||
port->listener = -1;
|
||||
port->handles = NSCreateMapTable(NSIntMapKeyCallBacks,
|
||||
NSObjectMapValueCallBacks, 0);
|
||||
if (multi_threaded == YES)
|
||||
{
|
||||
port->myLock = [NSRecursiveLock new];
|
||||
}
|
||||
port->myLock = [GSLazyRecursiveLock new];
|
||||
port->_is_valid = YES;
|
||||
|
||||
if (shouldListen == YES)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue