From 9481d0539ded5c181074110b4561003edab1a015 Mon Sep 17 00:00:00 2001 From: mtm Date: Sat, 27 Mar 2004 14:39:21 +0000 Subject: Stop using signals for synchronizing threads. The performance penalty was too much. --- lib/libthr/thread/thr_cond.c | 2 +- lib/libthr/thread/thr_kern.c | 20 ++++---------------- lib/libthr/thread/thr_mutex.c | 2 +- lib/libthr/thread/thr_private.h | 6 ++---- lib/libthr/thread/thr_resume_np.c | 3 +-- 5 files changed, 9 insertions(+), 24 deletions(-) (limited to 'lib/libthr') diff --git a/lib/libthr/thread/thr_cond.c b/lib/libthr/thread/thr_cond.c index 367a54e..e7e91d9 100644 --- a/lib/libthr/thread/thr_cond.c +++ b/lib/libthr/thread/thr_cond.c @@ -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(); diff --git a/lib/libthr/thread/thr_kern.c b/lib/libthr/thread/thr_kern.c index 1073ffd..0f0305e 100644 --- a/lib/libthr/thread/thr_kern.c +++ b/lib/libthr/thread/thr_kern.c @@ -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); } diff --git a/lib/libthr/thread/thr_mutex.c b/lib/libthr/thread/thr_mutex.c index 774527b..75d7323 100644 --- a/lib/libthr/thread/thr_mutex.c +++ b/lib/libthr/thread/thr_mutex.c @@ -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); diff --git a/lib/libthr/thread/thr_private.h b/lib/libthr/thread/thr_private.h index e42bb14..081a0eb 100644 --- a/lib/libthr/thread/thr_private.h +++ b/lib/libthr/thread/thr_private.h @@ -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) diff --git a/lib/libthr/thread/thr_resume_np.c b/lib/libthr/thread/thr_resume_np.c index 2699006..3f56b46 100644 --- a/lib/libthr/thread/thr_resume_np.c +++ b/lib/libthr/thread/thr_resume_np.c @@ -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); } -- cgit v1.1