Close a window between unlocking a spinlock and changing the thread state.

This commit is contained in:
John Birrell 1998-11-15 09:58:26 +00:00
parent 18c434c8f2
commit e7b7b3f3de
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=41164
12 changed files with 93 additions and 63 deletions

View File

@ -654,6 +654,8 @@ void _thread_dump_info(void);
void _thread_init(void); void _thread_init(void);
void _thread_kern_sched(struct sigcontext *); void _thread_kern_sched(struct sigcontext *);
void _thread_kern_sched_state(enum pthread_state,char *fname,int lineno); 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_kern_set_timeout(struct timespec *);
void _thread_sig_handler(int, int, struct sigcontext *); void _thread_sig_handler(int, int, struct sigcontext *);
void _thread_start(void); void _thread_start(void);

View File

@ -165,12 +165,9 @@ pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex)
/* Unlock the condition variable structure: */ /* Unlock the condition variable structure: */
_SPINUNLOCK(&(*cond)->lock); _SPINUNLOCK(&(*cond)->lock);
} else { } else {
/* Unlock the condition variable structure: */
_SPINUNLOCK(&(*cond)->lock);
/* Schedule the next thread: */ /* Schedule the next thread: */
_thread_kern_sched_state(PS_COND_WAIT, _thread_kern_sched_state_unlock(PS_COND_WAIT,
__FILE__, __LINE__); &(*cond)->lock, __FILE__, __LINE__);
/* Lock the mutex: */ /* Lock the mutex: */
rval = pthread_mutex_lock(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: */ /* Unlock the condition variable structure: */
_SPINUNLOCK(&(*cond)->lock); _SPINUNLOCK(&(*cond)->lock);
} else { } else {
/* Unlock the condition variable structure: */
_SPINUNLOCK(&(*cond)->lock);
/* Schedule the next thread: */ /* Schedule the next thread: */
_thread_kern_sched_state(PS_COND_WAIT, _thread_kern_sched_state_unlock(PS_COND_WAIT,
__FILE__, __LINE__); &(*cond)->lock, __FILE__, __LINE__);
/* Lock the mutex: */ /* Lock the mutex: */
if ((rval = pthread_mutex_lock(mutex)) != 0) { if ((rval = pthread_mutex_lock(mutex)) != 0) {

View File

@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: uthread_kern.c,v 1.13 1998/09/30 06:36:56 jb Exp $ * $Id: uthread_kern.c,v 1.14 1998/10/09 19:01:30 dt Exp $
* *
*/ */
#include <errno.h> #include <errno.h>
@ -616,6 +616,22 @@ _thread_kern_sched_state(enum pthread_state state, char *fname, int lineno)
return; 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 static void
_thread_kern_select(int wait_reqd) _thread_kern_select(int wait_reqd)
{ {

View File

@ -257,11 +257,10 @@ pthread_mutex_lock(pthread_mutex_t * mutex)
*/ */
_thread_queue_enq(&(*mutex)->m_queue, _thread_run); _thread_queue_enq(&(*mutex)->m_queue, _thread_run);
/* Unlock the mutex structure: */ /* Wait for the mutex: */
_SPINUNLOCK(&(*mutex)->lock); _thread_kern_sched_state_unlock(
PS_MUTEX_WAIT, &(*mutex)->lock,
/* Block signals: */ __FILE__, __LINE__);
_thread_kern_sched_state(PS_MUTEX_WAIT, __FILE__, __LINE__);
/* Lock the mutex again: */ /* Lock the mutex again: */
_SPINLOCK(&(*mutex)->lock); _SPINLOCK(&(*mutex)->lock);
@ -290,11 +289,10 @@ pthread_mutex_lock(pthread_mutex_t * mutex)
*/ */
_thread_queue_enq(&(*mutex)->m_queue, _thread_run); _thread_queue_enq(&(*mutex)->m_queue, _thread_run);
/* Unlock the mutex structure: */ /* Wait for the mutex: */
_SPINUNLOCK(&(*mutex)->lock); _thread_kern_sched_state_unlock(
PS_MUTEX_WAIT, &(*mutex)->lock,
/* Block signals: */ __FILE__, __LINE__);
_thread_kern_sched_state(PS_MUTEX_WAIT, __FILE__, __LINE__);
/* Lock the mutex again: */ /* Lock the mutex again: */
_SPINLOCK(&(*mutex)->lock); _SPINLOCK(&(*mutex)->lock);

View File

@ -165,12 +165,9 @@ pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex)
/* Unlock the condition variable structure: */ /* Unlock the condition variable structure: */
_SPINUNLOCK(&(*cond)->lock); _SPINUNLOCK(&(*cond)->lock);
} else { } else {
/* Unlock the condition variable structure: */
_SPINUNLOCK(&(*cond)->lock);
/* Schedule the next thread: */ /* Schedule the next thread: */
_thread_kern_sched_state(PS_COND_WAIT, _thread_kern_sched_state_unlock(PS_COND_WAIT,
__FILE__, __LINE__); &(*cond)->lock, __FILE__, __LINE__);
/* Lock the mutex: */ /* Lock the mutex: */
rval = pthread_mutex_lock(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: */ /* Unlock the condition variable structure: */
_SPINUNLOCK(&(*cond)->lock); _SPINUNLOCK(&(*cond)->lock);
} else { } else {
/* Unlock the condition variable structure: */
_SPINUNLOCK(&(*cond)->lock);
/* Schedule the next thread: */ /* Schedule the next thread: */
_thread_kern_sched_state(PS_COND_WAIT, _thread_kern_sched_state_unlock(PS_COND_WAIT,
__FILE__, __LINE__); &(*cond)->lock, __FILE__, __LINE__);
/* Lock the mutex: */ /* Lock the mutex: */
if ((rval = pthread_mutex_lock(mutex)) != 0) { if ((rval = pthread_mutex_lock(mutex)) != 0) {

View File

@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: uthread_kern.c,v 1.13 1998/09/30 06:36:56 jb Exp $ * $Id: uthread_kern.c,v 1.14 1998/10/09 19:01:30 dt Exp $
* *
*/ */
#include <errno.h> #include <errno.h>
@ -616,6 +616,22 @@ _thread_kern_sched_state(enum pthread_state state, char *fname, int lineno)
return; 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 static void
_thread_kern_select(int wait_reqd) _thread_kern_select(int wait_reqd)
{ {

View File

@ -257,11 +257,10 @@ pthread_mutex_lock(pthread_mutex_t * mutex)
*/ */
_thread_queue_enq(&(*mutex)->m_queue, _thread_run); _thread_queue_enq(&(*mutex)->m_queue, _thread_run);
/* Unlock the mutex structure: */ /* Wait for the mutex: */
_SPINUNLOCK(&(*mutex)->lock); _thread_kern_sched_state_unlock(
PS_MUTEX_WAIT, &(*mutex)->lock,
/* Block signals: */ __FILE__, __LINE__);
_thread_kern_sched_state(PS_MUTEX_WAIT, __FILE__, __LINE__);
/* Lock the mutex again: */ /* Lock the mutex again: */
_SPINLOCK(&(*mutex)->lock); _SPINLOCK(&(*mutex)->lock);
@ -290,11 +289,10 @@ pthread_mutex_lock(pthread_mutex_t * mutex)
*/ */
_thread_queue_enq(&(*mutex)->m_queue, _thread_run); _thread_queue_enq(&(*mutex)->m_queue, _thread_run);
/* Unlock the mutex structure: */ /* Wait for the mutex: */
_SPINUNLOCK(&(*mutex)->lock); _thread_kern_sched_state_unlock(
PS_MUTEX_WAIT, &(*mutex)->lock,
/* Block signals: */ __FILE__, __LINE__);
_thread_kern_sched_state(PS_MUTEX_WAIT, __FILE__, __LINE__);
/* Lock the mutex again: */ /* Lock the mutex again: */
_SPINLOCK(&(*mutex)->lock); _SPINLOCK(&(*mutex)->lock);

View File

@ -654,6 +654,8 @@ void _thread_dump_info(void);
void _thread_init(void); void _thread_init(void);
void _thread_kern_sched(struct sigcontext *); void _thread_kern_sched(struct sigcontext *);
void _thread_kern_sched_state(enum pthread_state,char *fname,int lineno); 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_kern_set_timeout(struct timespec *);
void _thread_sig_handler(int, int, struct sigcontext *); void _thread_sig_handler(int, int, struct sigcontext *);
void _thread_start(void); void _thread_start(void);

View File

@ -165,12 +165,9 @@ pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex)
/* Unlock the condition variable structure: */ /* Unlock the condition variable structure: */
_SPINUNLOCK(&(*cond)->lock); _SPINUNLOCK(&(*cond)->lock);
} else { } else {
/* Unlock the condition variable structure: */
_SPINUNLOCK(&(*cond)->lock);
/* Schedule the next thread: */ /* Schedule the next thread: */
_thread_kern_sched_state(PS_COND_WAIT, _thread_kern_sched_state_unlock(PS_COND_WAIT,
__FILE__, __LINE__); &(*cond)->lock, __FILE__, __LINE__);
/* Lock the mutex: */ /* Lock the mutex: */
rval = pthread_mutex_lock(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: */ /* Unlock the condition variable structure: */
_SPINUNLOCK(&(*cond)->lock); _SPINUNLOCK(&(*cond)->lock);
} else { } else {
/* Unlock the condition variable structure: */
_SPINUNLOCK(&(*cond)->lock);
/* Schedule the next thread: */ /* Schedule the next thread: */
_thread_kern_sched_state(PS_COND_WAIT, _thread_kern_sched_state_unlock(PS_COND_WAIT,
__FILE__, __LINE__); &(*cond)->lock, __FILE__, __LINE__);
/* Lock the mutex: */ /* Lock the mutex: */
if ((rval = pthread_mutex_lock(mutex)) != 0) { if ((rval = pthread_mutex_lock(mutex)) != 0) {

View File

@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: uthread_kern.c,v 1.13 1998/09/30 06:36:56 jb Exp $ * $Id: uthread_kern.c,v 1.14 1998/10/09 19:01:30 dt Exp $
* *
*/ */
#include <errno.h> #include <errno.h>
@ -616,6 +616,22 @@ _thread_kern_sched_state(enum pthread_state state, char *fname, int lineno)
return; 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 static void
_thread_kern_select(int wait_reqd) _thread_kern_select(int wait_reqd)
{ {

View File

@ -257,11 +257,10 @@ pthread_mutex_lock(pthread_mutex_t * mutex)
*/ */
_thread_queue_enq(&(*mutex)->m_queue, _thread_run); _thread_queue_enq(&(*mutex)->m_queue, _thread_run);
/* Unlock the mutex structure: */ /* Wait for the mutex: */
_SPINUNLOCK(&(*mutex)->lock); _thread_kern_sched_state_unlock(
PS_MUTEX_WAIT, &(*mutex)->lock,
/* Block signals: */ __FILE__, __LINE__);
_thread_kern_sched_state(PS_MUTEX_WAIT, __FILE__, __LINE__);
/* Lock the mutex again: */ /* Lock the mutex again: */
_SPINLOCK(&(*mutex)->lock); _SPINLOCK(&(*mutex)->lock);
@ -290,11 +289,10 @@ pthread_mutex_lock(pthread_mutex_t * mutex)
*/ */
_thread_queue_enq(&(*mutex)->m_queue, _thread_run); _thread_queue_enq(&(*mutex)->m_queue, _thread_run);
/* Unlock the mutex structure: */ /* Wait for the mutex: */
_SPINUNLOCK(&(*mutex)->lock); _thread_kern_sched_state_unlock(
PS_MUTEX_WAIT, &(*mutex)->lock,
/* Block signals: */ __FILE__, __LINE__);
_thread_kern_sched_state(PS_MUTEX_WAIT, __FILE__, __LINE__);
/* Lock the mutex again: */ /* Lock the mutex again: */
_SPINLOCK(&(*mutex)->lock); _SPINLOCK(&(*mutex)->lock);

View File

@ -654,6 +654,8 @@ void _thread_dump_info(void);
void _thread_init(void); void _thread_init(void);
void _thread_kern_sched(struct sigcontext *); void _thread_kern_sched(struct sigcontext *);
void _thread_kern_sched_state(enum pthread_state,char *fname,int lineno); 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_kern_set_timeout(struct timespec *);
void _thread_sig_handler(int, int, struct sigcontext *); void _thread_sig_handler(int, int, struct sigcontext *);
void _thread_start(void); void _thread_start(void);