Locking primitives and operations in libthr should use struct umtx,

not spinlock_t. Spinlock_t and the associated functions and macros may
require blocking signals in order for async-safe libc functions to behave
appropriately in libthr. This is undesriable for libthr internal locking.
So, this is the first step in completely separating libthr from libc's
locking primitives.

Three new macros should be used for internal libthr locking from now on:
THR_LOCK, THR_TRYLOCK, THR_UNLOCK.
This commit is contained in:
mtm 2003-06-29 23:49:41 +00:00
parent 9e8da3090e
commit 2987dd3b2e
2 changed files with 22 additions and 4 deletions

View File

@ -80,6 +80,24 @@
*/
#define curthread _get_curthread()
/*
* Locking macros
*/
#define THR_LOCK(m) \
do { \
if (umtx_lock((m), curthread->thr_id) != 0) \
abort(); \
} while (0)
#define THR_TRYLOCK(m) _umtxtrylock((m))
#define THR_UNLOCK(m) \
do { \
if (umtx_unlock((m), curthread->thr_id) != 0) \
abort(); \
} while (0)
/*
* State change macro without scheduling queue change:
*/
@ -431,7 +449,7 @@ struct pthread {
/*
* Lock for accesses to this thread structure.
*/
spinlock_t lock;
struct umtx lock;
/* Queue entry for list of all threads: */
TAILQ_ENTRY(pthread) tle;
@ -748,7 +766,6 @@ int _pthread_mutexattr_settype(pthread_mutexattr_t *, int);
int _pthread_once(pthread_once_t *, void (*) (void));
pthread_t _pthread_self(void);
int _pthread_setspecific(pthread_key_t, const void *);
int _spintrylock(spinlock_t *);
void _thread_exit(char *, int, char *);
void _thread_exit_cleanup(void);
void *_thread_cleanup(pthread_t);
@ -768,6 +785,7 @@ void _thread_critical_enter(pthread_t);
void _thread_critical_exit(pthread_t);
void _thread_sigblock();
void _thread_sigunblock();
int _umtxtrylock(struct umtx *lck);
/* #include <sys/aio.h> */
#ifdef _SYS_AIO_H_

View File

@ -65,10 +65,10 @@ _spinlock(spinlock_t *lck)
}
int
_spintrylock(spinlock_t *lck)
_umtxtrylock(struct umtx *lck)
{
int error;
error = umtx_trylock((struct umtx *)lck, curthread->thr_id);
error = umtx_trylock(lck, curthread->thr_id);
if (error != 0 && error != EBUSY)
abort();
return (error);