diff options
| author | thorpej <thorpej@NetBSD.org> | 2008-12-19 07:57:28 +0000 |
|---|---|---|
| committer | thorpej <thorpej@NetBSD.org> | 2008-12-19 07:57:28 +0000 |
| commit | 4730b27d42335cd3ca3909c1936705d948094225 (patch) | |
| tree | d9caf5429e1b74388e9bcb8748299ae78328cb8c /sys | |
| parent | abc88641ada985880e3646e7b7346cbe284b7576 (diff) | |
Make condvars really opaque -- hide the wait message member from consumers
of the API.
Diffstat (limited to 'sys')
| -rw-r--r-- | sys/kern/kern_condvar.c | 33 | ||||
| -rw-r--r-- | sys/sys/condvar.h | 12 |
2 files changed, 27 insertions, 18 deletions
diff --git a/sys/kern/kern_condvar.c b/sys/kern/kern_condvar.c index 7268d38c670..540223eec44 100644 --- a/sys/kern/kern_condvar.c +++ b/sys/kern/kern_condvar.c @@ -1,4 +1,4 @@ -/* $NetBSD: kern_condvar.c,v 1.25 2008/06/16 12:03:01 ad Exp $ */ +/* $NetBSD: kern_condvar.c,v 1.26 2008/12/19 07:57:28 thorpej Exp $ */ /*- * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -34,7 +34,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: kern_condvar.c,v 1.25 2008/06/16 12:03:01 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_condvar.c,v 1.26 2008/12/19 07:57:28 thorpej Exp $"); #include <sys/param.h> #include <sys/proc.h> @@ -47,8 +47,25 @@ __KERNEL_RCSID(0, "$NetBSD: kern_condvar.c,v 1.25 2008/06/16 12:03:01 ad Exp $") #include <uvm/uvm_extern.h> -#define CV_SLEEPQ(cv) ((sleepq_t *)(cv)->cv_opaque) -#define CV_DEBUG_P(cv) ((cv)->cv_wmesg != nodebug) +/* + * Accessors for the private contents of the kcondvar_t data type. + * + * cv_opaque[0] sleepq... + * cv_opaque[1] ...pointers + * cv_opaque[2] description for ps(1) + * + * cv_opaque[0..1] is protected by the interlock passed to cv_wait() (enqueue + * only), and the sleep queue lock acquired with sleeptab_lookup() (enqueue + * and dequeue). + * + * cv_opaque[2] (the wmesg) is static and does not change throughout the life + * of the CV. + */ +#define CV_SLEEPQ(cv) ((sleepq_t *)(cv)->cv_opaque) +#define CV_WMESG(cv) ((const char *)(cv)->cv_opaque[2]) +#define CV_SET_WMESG(cv, v) (cv)->cv_opaque[2] = __UNCONST(v) + +#define CV_DEBUG_P(cv) (CV_WMESG(cv) != nodebug) #define CV_RA ((uintptr_t)__builtin_return_address(0)) static u_int cv_unsleep(lwp_t *, bool); @@ -91,7 +108,7 @@ cv_init(kcondvar_t *cv, const char *wmesg) } #endif KASSERT(wmesg != NULL); - cv->cv_wmesg = wmesg; + CV_SET_WMESG(cv, wmesg); sleepq_init(CV_SLEEPQ(cv)); } @@ -107,7 +124,7 @@ cv_destroy(kcondvar_t *cv) LOCKDEBUG_FREE(CV_DEBUG_P(cv), cv); #ifdef DIAGNOSTIC KASSERT(cv_is_valid(cv)); - cv->cv_wmesg = deadcv; + CV_SET_WMESG(cv, deadcv); #endif } @@ -133,7 +150,7 @@ cv_enter(kcondvar_t *cv, kmutex_t *mtx, lwp_t *l) mp = sleepq_hashlock(cv); sq = CV_SLEEPQ(cv); sleepq_enter(sq, l, mp); - sleepq_enqueue(sq, cv, cv->cv_wmesg, &cv_syncobj); + sleepq_enqueue(sq, cv, CV_WMESG(cv), &cv_syncobj); mutex_exit(mtx); KASSERT(cv_has_waiters(cv)); } @@ -402,5 +419,5 @@ bool cv_is_valid(kcondvar_t *cv) { - return cv->cv_wmesg != deadcv && cv->cv_wmesg != NULL; + return CV_WMESG(cv) != deadcv && CV_WMESG(cv) != NULL; } diff --git a/sys/sys/condvar.h b/sys/sys/condvar.h index 38eee123283..a2ba3e1fc6e 100644 --- a/sys/sys/condvar.h +++ b/sys/sys/condvar.h @@ -1,4 +1,4 @@ -/* $NetBSD: condvar.h,v 1.10 2008/05/31 13:36:25 ad Exp $ */ +/* $NetBSD: condvar.h,v 1.11 2008/12/19 07:57:28 thorpej Exp $ */ /*- * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -34,16 +34,8 @@ #include <sys/mutex.h> -/* - * The condition variable implementation is private to kern_condvar.c but - * the size of a kcondvar_t must remain constant. cv_opaque is protected - * both by the interlock passed to cv_wait() (enqueue only), and the sleep - * queue lock acquired with sleeptab_lookup() (enqueue and dequeue). - * cv_wmesg is static and does not change throughout the life of the CV. - */ typedef struct kcondvar { - void *cv_opaque[2]; /* sleep queue */ - const char *cv_wmesg; /* description for /bin/ps */ + void *cv_opaque[3]; } kcondvar_t; #ifdef _KERNEL |
