Skip to content

Commit

Permalink
do not retry sem_wait and sem_timedwait on EINTR
Browse files Browse the repository at this point in the history
This is needed to make sem_wait interruptible (and sem_timedwait immediately
interruptible), which is used in libfuse to exit the main loop on a keyboard
interrupt: https://github.com/libfuse/libfuse/blob/fuse-3.3.0/lib/fuse_loop_mt.c#L332
  • Loading branch information
orivej committed Dec 5, 2018
1 parent 39ef612 commit c4c38aa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/thread/sem_timedwait.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ int sem_timedwait(sem_t *restrict sem, const struct timespec *restrict at)
pthread_cleanup_push(cleanup, (void *)(sem->__val+1));
r = __timedwait_cp(sem->__val, -1, CLOCK_REALTIME, at, sem->__val[2]);
pthread_cleanup_pop(1);
if (r && r != EINTR) {
if (r) {
errno = r;
return -1;
}
Expand Down
6 changes: 3 additions & 3 deletions src/thread/synccall.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ static void handler(int sig)
if (a_cas(&target_tid, ch.tid, 0) == (ch.tid | 0x80000000))
__syscall(SYS_futex, &target_tid, FUTEX_UNLOCK_PI|FUTEX_PRIVATE);

sem_wait(&ch.target_sem);
while (sem_wait(&ch.target_sem) && errno != EINTR);
callback(context);
sem_post(&ch.caller_sem);
sem_wait(&ch.target_sem);
while (sem_wait(&ch.target_sem) && errno != EINTR);

errno = old_errno;
}
Expand Down Expand Up @@ -153,7 +153,7 @@ void __synccall(void (*func)(void *), void *ctx)
/* Serialize execution of callback in caught threads. */
for (cp=head; cp; cp=cp->next) {
sem_post(&cp->target_sem);
sem_wait(&cp->caller_sem);
while (sem_wait(&cp->caller_sem) && errno != EINTR);
}

sa.sa_handler = SIG_IGN;
Expand Down

0 comments on commit c4c38aa

Please sign in to comment.