Stop using signals for synchronizing threads. The performance penalty
was too much.
This commit is contained in:
parent
187bcb5eb3
commit
484c640d2f
@ -285,7 +285,7 @@ cond_wait_common(pthread_cond_t * cond, pthread_mutex_t * mutex,
|
||||
_thread_critical_exit(curthread);
|
||||
COND_UNLOCK(*cond);
|
||||
rval = _thread_suspend(curthread, (struct timespec *)abstime);
|
||||
if (rval != 0 && rval != EAGAIN && rval != EINTR) {
|
||||
if (rval != 0 && rval != ETIMEDOUT && rval != EINTR) {
|
||||
printf("foo");
|
||||
fflush(stdout);
|
||||
abort();
|
||||
|
@ -74,10 +74,6 @@ _thread_sigblock()
|
||||
* Block all signals.
|
||||
*/
|
||||
SIGFILLSET(set);
|
||||
SIGADDSET(set, SIGTHR);
|
||||
#ifdef _PTHREADS_INVARIANTS
|
||||
SIGDELSET(set, SIGABRT);
|
||||
#endif
|
||||
SIGDELSET(set, SIGTRAP);
|
||||
|
||||
/* If we have already blocked signals, just up the refcount */
|
||||
@ -121,7 +117,6 @@ _thread_suspend(pthread_t pthread, const struct timespec *abstime)
|
||||
{
|
||||
struct timespec remaining;
|
||||
struct timespec *ts;
|
||||
siginfo_t info;
|
||||
int error;
|
||||
|
||||
/*
|
||||
@ -139,19 +134,12 @@ _thread_suspend(pthread_t pthread, const struct timespec *abstime)
|
||||
ts = &remaining;
|
||||
|
||||
/*
|
||||
* If the absolute timeout has already passed set the
|
||||
* relative timeout to 0 sec. so that sigtimedwait()
|
||||
* returns immediately.
|
||||
* NOTE: timespecsub() makes sure the tv_nsec member >= 0.
|
||||
*/
|
||||
if (ts->tv_sec < 0) {
|
||||
ts->tv_sec = 0;
|
||||
ts->tv_nsec = 0;
|
||||
}
|
||||
if (ts->tv_sec < 0)
|
||||
return (ETIMEDOUT);
|
||||
} else
|
||||
ts = NULL;
|
||||
|
||||
error = sigtimedwait(&_thread_suspend_sigset, &info, ts);
|
||||
error = (error == -1) ? errno : 0;
|
||||
return (error);
|
||||
error = thr_suspend(ts);
|
||||
return (error == -1 ? errno : error);
|
||||
}
|
||||
|
@ -901,7 +901,7 @@ get_mcontested(pthread_mutex_t mutexp, const struct timespec *abstime)
|
||||
_thread_critical_exit(curthread);
|
||||
_SPINUNLOCK(&mutexp->lock);
|
||||
error = _thread_suspend(curthread, abstime);
|
||||
if (error != 0 && error != EAGAIN && error != EINTR)
|
||||
if (error != 0 && error != ETIMEDOUT && error != EINTR)
|
||||
PANIC("Cannot suspend on mutex.");
|
||||
_SPINLOCK(&mutexp->lock);
|
||||
_thread_critical_enter(curthread);
|
||||
|
@ -139,10 +139,8 @@
|
||||
} while (0)
|
||||
|
||||
#define PTHREAD_NEW_STATE(thrd, newstate) do { \
|
||||
if (newstate == PS_RUNNING) { \
|
||||
if (thr_kill(thrd->thr_id, SIGTHR)) \
|
||||
abort(); \
|
||||
} \
|
||||
if (newstate == PS_RUNNING) \
|
||||
thr_wake(thrd->thr_id); \
|
||||
PTHREAD_SET_STATE(thrd, newstate); \
|
||||
} while (0)
|
||||
|
||||
|
@ -84,6 +84,5 @@ static void
|
||||
resume_common(struct pthread *thread)
|
||||
{
|
||||
thread->flags &= ~PTHREAD_FLAGS_SUSPENDED;
|
||||
if (thr_kill(thread->thr_id, SIGTHR))
|
||||
abort();
|
||||
thr_wake(thread->thr_id);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user