try to make tread performer firing more robust

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@26856 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2008-09-18 08:22:53 +00:00
parent f78c6627de
commit 0ecc6aba60
2 changed files with 31 additions and 4 deletions

View file

@ -1,3 +1,8 @@
2008-09-18 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSThread.m: try to make firing of thread performers
more robust.
2008-09-14 13:20-EDT Gregory John Casamento <greg_casamento@yahoo.com> 2008-09-14 13:20-EDT Gregory John Casamento <greg_casamento@yahoo.com>
* install.sh: Install script for use by compile-all. * install.sh: Install script for use by compile-all.

View file

@ -51,8 +51,14 @@
#ifdef NeXT_RUNTIME #ifdef NeXT_RUNTIME
#include "thr-mach.h" #include "thr-mach.h"
#endif #endif
#include <errno.h> #include <errno.h>
#include <sys/fcntl.h>
#ifdef __POSIX_SOURCE
#define NBLK_OPT O_NONBLOCK
#else
#define NBLK_OPT FNDELAY
#endif
#include "Foundation/NSDebug.h" #include "Foundation/NSDebug.h"
#include "Foundation/NSException.h" #include "Foundation/NSException.h"
@ -862,7 +868,6 @@ pthread_detach(pthread_self());
{ {
[lock lock]; [lock lock];
[performers addObject: performer]; [performers addObject: performer];
[lock unlock];
#if defined(__MINGW32__) #if defined(__MINGW32__)
if (SetEvent(event) == 0) if (SetEvent(event) == 0)
{ {
@ -874,6 +879,7 @@ pthread_detach(pthread_self());
NSLog(@"Write to pipe failed - %@", [NSError _last]); NSLog(@"Write to pipe failed - %@", [NSError _last]);
} }
#endif #endif
[lock unlock];
} }
- (void) dealloc - (void) dealloc
@ -898,8 +904,24 @@ pthread_detach(pthread_self());
if (pipe(fd) == 0) if (pipe(fd) == 0)
{ {
int e;
inputFd = fd[0]; inputFd = fd[0];
outputFd = fd[1]; outputFd = fd[1];
if ((e = fcntl(inputFd, F_GETFL, 0)) >= 0)
{
e |= NBLK_OPT;
if (fcntl(inputFd, F_SETFL, e) < 0)
{
[NSException raise: NSInternalInconsistencyException
format: @"Failed to set non block flag for perform in thread"];
}
}
else
{
[NSException raise: NSInternalInconsistencyException
format: @"Failed to get non block flag for perform in thread"];
}
} }
else else
{ {
@ -918,7 +940,6 @@ pthread_detach(pthread_self());
[lock lock]; [lock lock];
[performers makeObjectsPerformSelector: @selector(invalidate)]; [performers makeObjectsPerformSelector: @selector(invalidate)];
[performers removeAllObjects]; [performers removeAllObjects];
[lock unlock];
#ifdef __MINGW32__ #ifdef __MINGW32__
if (event != INVALID_HANDLE_VALUE) if (event != INVALID_HANDLE_VALUE)
{ {
@ -936,6 +957,7 @@ pthread_detach(pthread_self());
outputFd = -1; outputFd = -1;
} }
#endif #endif
[lock unlock];
} }
- (void) fire - (void) fire
@ -944,6 +966,7 @@ pthread_detach(pthread_self());
unsigned int i; unsigned int i;
unsigned int c; unsigned int c;
[lock lock];
#if defined(__MINGW32__) #if defined(__MINGW32__)
if (event != INVALID_HANDLE_VALUE) if (event != INVALID_HANDLE_VALUE)
{ {
@ -962,7 +985,6 @@ pthread_detach(pthread_self());
} }
#endif #endif
[lock lock];
toDo = [NSArray arrayWithArray: performers]; toDo = [NSArray arrayWithArray: performers];
[performers removeAllObjects]; [performers removeAllObjects];
[lock unlock]; [lock unlock];