summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormtm <mtm@FreeBSD.org>2003-06-29 23:49:41 +0000
committermtm <mtm@FreeBSD.org>2003-06-29 23:49:41 +0000
commit39a4899732da552e6e0de76201566ee295c841fc (patch)
tree64f1269b5436d2c6956607712fa6593bb57219d1
parent65c6a689bc519fe51f539267d8fd8ec2f7139ed3 (diff)
downloadFreeBSD-src-39a4899732da552e6e0de76201566ee295c841fc.zip
FreeBSD-src-39a4899732da552e6e0de76201566ee295c841fc.tar.gz
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.
-rw-r--r--lib/libthr/thread/thr_private.h22
-rw-r--r--lib/libthr/thread/thr_spinlock.c4
2 files changed, 22 insertions, 4 deletions
diff --git a/lib/libthr/thread/thr_private.h b/lib/libthr/thread/thr_private.h
index 5e8da18..dd5f543 100644
--- a/lib/libthr/thread/thr_private.h
+++ b/lib/libthr/thread/thr_private.h
@@ -81,6 +81,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:
*/
#define PTHREAD_SET_STATE(thrd, newstate) do { \
@@ -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_
diff --git a/lib/libthr/thread/thr_spinlock.c b/lib/libthr/thread/thr_spinlock.c
index 53e9851..dcb6fac 100644
--- a/lib/libthr/thread/thr_spinlock.c
+++ b/lib/libthr/thread/thr_spinlock.c
@@ -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);
OpenPOWER on IntegriCloud