mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 05:28:49 +00:00
Use pthread_sigmask instead of sigprocmask
This commit is contained in:
parent
cd3ed71137
commit
36a91fc6ff
3 changed files with 17 additions and 12 deletions
|
@ -623,9 +623,9 @@ int read_blocked(int fd, void *buf, size_t count)
|
|||
|
||||
sigemptyset( &chldset );
|
||||
sigaddset( &chldset, SIGCHLD );
|
||||
sigprocmask(SIG_BLOCK, &chldset, &oldset);
|
||||
VOMIT_ON_FAILURE(pthread_sigmask(SIG_BLOCK, &chldset, &oldset));
|
||||
res = read( fd, buf, count );
|
||||
sigprocmask( SIG_SETMASK, &oldset, 0 );
|
||||
VOMIT_ON_FAILURE(pthread_sigmask(SIG_SETMASK, &oldset, NULL));
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
21
iothread.cpp
21
iothread.cpp
|
@ -96,12 +96,7 @@ static ThreadedRequest_t *dequeue_request(void) {
|
|||
static void *iothread_worker(void *threadPtr) {
|
||||
assert(threadPtr != NULL);
|
||||
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 */
|
||||
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();
|
||||
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;
|
||||
do {
|
||||
err = 0;
|
||||
|
@ -132,10 +132,15 @@ static void iothread_spawn_if_needed(void) {
|
|||
err = errno;
|
||||
}
|
||||
} while (err == EAGAIN);
|
||||
|
||||
/* Need better error handling - perhaps try again later. */
|
||||
assert(err == 0);
|
||||
|
||||
/* 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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -636,7 +636,7 @@ void signal_block()
|
|||
if( !block_count )
|
||||
{
|
||||
sigfillset( &chldset );
|
||||
sigprocmask(SIG_BLOCK, &chldset, 0);
|
||||
VOMIT_ON_FAILURE(pthread_sigmask(SIG_BLOCK, &chldset, NULL));
|
||||
}
|
||||
|
||||
block_count++;
|
||||
|
@ -660,7 +660,7 @@ void signal_unblock()
|
|||
if( !block_count )
|
||||
{
|
||||
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 );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue