Use pthread_sigmask instead of sigprocmask
This commit is contained in:
ridiculousfish 2012-07-09 14:15:55 -07:00
parent cd3ed71137
commit 36a91fc6ff
3 changed files with 17 additions and 12 deletions

View file

@ -623,9 +623,9 @@ int read_blocked(int fd, void *buf, size_t count)
sigemptyset( &chldset ); sigemptyset( &chldset );
sigaddset( &chldset, SIGCHLD ); sigaddset( &chldset, SIGCHLD );
sigprocmask(SIG_BLOCK, &chldset, &oldset); VOMIT_ON_FAILURE(pthread_sigmask(SIG_BLOCK, &chldset, &oldset));
res = read( fd, buf, count ); res = read( fd, buf, count );
sigprocmask( SIG_SETMASK, &oldset, 0 ); VOMIT_ON_FAILURE(pthread_sigmask(SIG_SETMASK, &oldset, NULL));
return res; return res;
} }

View file

@ -96,12 +96,7 @@ static ThreadedRequest_t *dequeue_request(void) {
static void *iothread_worker(void *threadPtr) { static void *iothread_worker(void *threadPtr) {
assert(threadPtr != NULL); assert(threadPtr != NULL);
struct WorkerThread_t *thread = (struct WorkerThread_t *)threadPtr; struct WorkerThread_t *thread = (struct WorkerThread_t *)threadPtr;
// We don't want to receive signals on this thread
sigset_t set;
sigfillset(&set);
VOMIT_ON_FAILURE(pthread_sigmask(SIG_SETMASK, &set, NULL));
/* Grab a request off of the queue */ /* Grab a request off of the queue */
struct ThreadedRequest_t *req = dequeue_request(); struct ThreadedRequest_t *req = dequeue_request();
@ -124,7 +119,12 @@ static void iothread_spawn_if_needed(void) {
struct WorkerThread_t *thread = next_vacant_thread_slot(); struct WorkerThread_t *thread = next_vacant_thread_slot();
assert(thread != NULL); assert(thread != NULL);
/* Spawn a thread */ /* The spawned thread inherits our signal mask. We don't want the thread to ever receive signals on the spawned thread, so temporarily block all signals, spawn the thread, and then restore it. */
sigset_t newSet, savedSet;
sigfillset(&newSet);
VOMIT_ON_FAILURE(pthread_sigmask(SIG_BLOCK, &newSet, &savedSet));
/* Spawn a thread. */
int err; int err;
do { do {
err = 0; err = 0;
@ -132,10 +132,15 @@ static void iothread_spawn_if_needed(void) {
err = errno; err = errno;
} }
} while (err == EAGAIN); } while (err == EAGAIN);
/* Need better error handling - perhaps try again later. */
assert(err == 0); assert(err == 0);
/* Note that we are spawned another thread */ /* Note that we are spawned another thread */
s_active_thread_count += 1; s_active_thread_count += 1;
/* Restore our sigmask */
VOMIT_ON_FAILURE(pthread_sigmask(SIG_SETMASK, &savedSet, NULL));
} }
} }

View file

@ -636,7 +636,7 @@ void signal_block()
if( !block_count ) if( !block_count )
{ {
sigfillset( &chldset ); sigfillset( &chldset );
sigprocmask(SIG_BLOCK, &chldset, 0); VOMIT_ON_FAILURE(pthread_sigmask(SIG_BLOCK, &chldset, NULL));
} }
block_count++; block_count++;
@ -660,7 +660,7 @@ void signal_unblock()
if( !block_count ) if( !block_count )
{ {
sigfillset( &chldset ); sigfillset( &chldset );
sigprocmask(SIG_UNBLOCK, &chldset, 0); VOMIT_ON_FAILURE(pthread_sigmask(SIG_UNBLOCK, &chldset, 0));
} }
// debug( 0, L"signal block level decreased to %d", block_count ); // debug( 0, L"signal block level decreased to %d", block_count );
} }