From ad21368ee2f214331a8bc120e4ef17fca50377a0 Mon Sep 17 00:00:00 2001 From: rfm Date: Thu, 18 Sep 2008 08:22:53 +0000 Subject: [PATCH] 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 --- ChangeLog | 5 +++++ Source/NSThread.m | 30 ++++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index a565ae0f0..95871538a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-09-18 Richard Frith-Macdonald + + * Source/NSThread.m: try to make firing of thread performers + more robust. + 2008-09-14 13:20-EDT Gregory John Casamento * install.sh: Install script for use by compile-all. diff --git a/Source/NSThread.m b/Source/NSThread.m index fe5498457..b88d09384 100644 --- a/Source/NSThread.m +++ b/Source/NSThread.m @@ -51,8 +51,14 @@ #ifdef NeXT_RUNTIME #include "thr-mach.h" #endif - #include +#include + +#ifdef __POSIX_SOURCE +#define NBLK_OPT O_NONBLOCK +#else +#define NBLK_OPT FNDELAY +#endif #include "Foundation/NSDebug.h" #include "Foundation/NSException.h" @@ -862,7 +868,6 @@ pthread_detach(pthread_self()); { [lock lock]; [performers addObject: performer]; - [lock unlock]; #if defined(__MINGW32__) if (SetEvent(event) == 0) { @@ -874,6 +879,7 @@ pthread_detach(pthread_self()); NSLog(@"Write to pipe failed - %@", [NSError _last]); } #endif + [lock unlock]; } - (void) dealloc @@ -898,8 +904,24 @@ pthread_detach(pthread_self()); if (pipe(fd) == 0) { + int e; + inputFd = fd[0]; 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 { @@ -918,7 +940,6 @@ pthread_detach(pthread_self()); [lock lock]; [performers makeObjectsPerformSelector: @selector(invalidate)]; [performers removeAllObjects]; - [lock unlock]; #ifdef __MINGW32__ if (event != INVALID_HANDLE_VALUE) { @@ -936,6 +957,7 @@ pthread_detach(pthread_self()); outputFd = -1; } #endif + [lock unlock]; } - (void) fire @@ -944,6 +966,7 @@ pthread_detach(pthread_self()); unsigned int i; unsigned int c; + [lock lock]; #if defined(__MINGW32__) if (event != INVALID_HANDLE_VALUE) { @@ -962,7 +985,6 @@ pthread_detach(pthread_self()); } #endif - [lock lock]; toDo = [NSArray arrayWithArray: performers]; [performers removeAllObjects]; [lock unlock];