diff options
| author | Thomas Gellekum <tg@FreeBSD.org> | 1998-11-20 07:31:37 +0000 |
|---|---|---|
| committer | Thomas Gellekum <tg@FreeBSD.org> | 1998-11-20 07:31:37 +0000 |
| commit | e0a9f6cda954fa1c4999d9d205da3e8b11328f0f (patch) | |
| tree | b703836d5a3bc8cccc7ebeda9a47dfa4be47f7f7 /lib | |
| parent | f8db4c38dbe1f846760f657f2f72c0a999ff0fdd (diff) | |
Notes
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/libc_r/uthread/pthread_private.h | 2 | ||||
| -rw-r--r-- | lib/libc_r/uthread/uthread_cond.c | 14 | ||||
| -rw-r--r-- | lib/libc_r/uthread/uthread_kern.c | 18 | ||||
| -rw-r--r-- | lib/libc_r/uthread/uthread_kill.c | 20 | ||||
| -rw-r--r-- | lib/libc_r/uthread/uthread_mutex.c | 18 |
5 files changed, 51 insertions, 21 deletions
diff --git a/lib/libc_r/uthread/pthread_private.h b/lib/libc_r/uthread/pthread_private.h index 04600cfbb3be..e73f4f16381b 100644 --- a/lib/libc_r/uthread/pthread_private.h +++ b/lib/libc_r/uthread/pthread_private.h @@ -654,6 +654,8 @@ void _thread_dump_info(void); void _thread_init(void); void _thread_kern_sched(struct sigcontext *); void _thread_kern_sched_state(enum pthread_state,char *fname,int lineno); +void _thread_kern_sched_state_unlock(enum pthread_state state, + spinlock_t *lock, char *fname, int lineno); void _thread_kern_set_timeout(struct timespec *); void _thread_sig_handler(int, int, struct sigcontext *); void _thread_start(void); diff --git a/lib/libc_r/uthread/uthread_cond.c b/lib/libc_r/uthread/uthread_cond.c index e9b687d77e21..a085ea60fa89 100644 --- a/lib/libc_r/uthread/uthread_cond.c +++ b/lib/libc_r/uthread/uthread_cond.c @@ -165,12 +165,9 @@ pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex) /* Unlock the condition variable structure: */ _SPINUNLOCK(&(*cond)->lock); } else { - /* Unlock the condition variable structure: */ - _SPINUNLOCK(&(*cond)->lock); - /* Schedule the next thread: */ - _thread_kern_sched_state(PS_COND_WAIT, - __FILE__, __LINE__); + _thread_kern_sched_state_unlock(PS_COND_WAIT, + &(*cond)->lock, __FILE__, __LINE__); /* Lock the mutex: */ rval = pthread_mutex_lock(mutex); @@ -241,12 +238,9 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex, /* Unlock the condition variable structure: */ _SPINUNLOCK(&(*cond)->lock); } else { - /* Unlock the condition variable structure: */ - _SPINUNLOCK(&(*cond)->lock); - /* Schedule the next thread: */ - _thread_kern_sched_state(PS_COND_WAIT, - __FILE__, __LINE__); + _thread_kern_sched_state_unlock(PS_COND_WAIT, + &(*cond)->lock, __FILE__, __LINE__); /* Lock the mutex: */ if ((rval = pthread_mutex_lock(mutex)) != 0) { diff --git a/lib/libc_r/uthread/uthread_kern.c b/lib/libc_r/uthread/uthread_kern.c index 1e483ac42997..3fe471c67533 100644 --- a/lib/libc_r/uthread/uthread_kern.c +++ b/lib/libc_r/uthread/uthread_kern.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: uthread_kern.c,v 1.3.2.4 1998/04/30 22:26:30 jb Exp $ + * $Id: uthread_kern.c,v 1.3.2.5 1998/11/04 08:42:11 tg Exp $ * */ #include <errno.h> @@ -616,6 +616,22 @@ _thread_kern_sched_state(enum pthread_state state, char *fname, int lineno) return; } +void +_thread_kern_sched_state_unlock(enum pthread_state state, + spinlock_t *lock, char *fname, int lineno) +{ + /* Change the state of the current thread: */ + _thread_run->state = state; + _thread_run->fname = fname; + _thread_run->lineno = lineno; + + _SPINUNLOCK(lock); + + /* Schedule the next thread that is ready: */ + _thread_kern_sched(NULL); + return; +} + static void _thread_kern_select(int wait_reqd) { diff --git a/lib/libc_r/uthread/uthread_kill.c b/lib/libc_r/uthread/uthread_kill.c index 292ba5caf8f2..7572c05faff7 100644 --- a/lib/libc_r/uthread/uthread_kill.c +++ b/lib/libc_r/uthread/uthread_kill.c @@ -83,6 +83,26 @@ pthread_kill(pthread_t pthread, int sig) sigaddset(&pthread->sigpend,sig); break; + case PS_SELECT_WAIT: + case PS_FDR_WAIT: + case PS_FDW_WAIT: + case PS_SLEEP_WAIT: + if (!sigismember(&pthread->sigmask, sig) && + (_thread_sigact[sig - 1].sa_handler != SIG_IGN)) { + /* Flag the operation as interrupted: */ + pthread->interrupted = 1; + + /* Change the state of the thread to run: */ + PTHREAD_NEW_STATE(pthread,PS_RUNNING); + + /* Return the signal number: */ + pthread->signo = sig; + } else { + /* Increment the pending signal count: */ + sigaddset(&pthread->sigpend,sig); + } + break; + default: /* Increment the pending signal count: */ sigaddset(&pthread->sigpend,sig); diff --git a/lib/libc_r/uthread/uthread_mutex.c b/lib/libc_r/uthread/uthread_mutex.c index 4f4aa8af041e..a7e8dfee6b51 100644 --- a/lib/libc_r/uthread/uthread_mutex.c +++ b/lib/libc_r/uthread/uthread_mutex.c @@ -257,11 +257,10 @@ pthread_mutex_lock(pthread_mutex_t * mutex) */ _thread_queue_enq(&(*mutex)->m_queue, _thread_run); - /* Unlock the mutex structure: */ - _SPINUNLOCK(&(*mutex)->lock); - - /* Block signals: */ - _thread_kern_sched_state(PS_MUTEX_WAIT, __FILE__, __LINE__); + /* Wait for the mutex: */ + _thread_kern_sched_state_unlock( + PS_MUTEX_WAIT, &(*mutex)->lock, + __FILE__, __LINE__); /* Lock the mutex again: */ _SPINLOCK(&(*mutex)->lock); @@ -290,11 +289,10 @@ pthread_mutex_lock(pthread_mutex_t * mutex) */ _thread_queue_enq(&(*mutex)->m_queue, _thread_run); - /* Unlock the mutex structure: */ - _SPINUNLOCK(&(*mutex)->lock); - - /* Block signals: */ - _thread_kern_sched_state(PS_MUTEX_WAIT, __FILE__, __LINE__); + /* Wait for the mutex: */ + _thread_kern_sched_state_unlock( + PS_MUTEX_WAIT, &(*mutex)->lock, + __FILE__, __LINE__); /* Lock the mutex again: */ _SPINLOCK(&(*mutex)->lock); |
