PERFORCE change 74122 for review
John Baldwin
jhb at FreeBSD.org
Wed Mar 30 12:35:12 PST 2005
http://perforce.freebsd.org/chv.cgi?CH=74122
Change 74122 by jhb at jhb_slimer on 2005/03/30 20:34:35
Fix UP mutex code to work with uintptr_t for atomic_ptr().
Affected files ...
.. //depot/projects/smpng/sys/kern/kern_mutex.c#94 edit
.. //depot/projects/smpng/sys/sys/mutex.h#51 edit
Differences ...
==== //depot/projects/smpng/sys/kern/kern_mutex.c#94 (text+ko) ====
@@ -417,7 +417,7 @@
atomic_set_ptr(&m->mtx_lock, MTX_RECURSED);
rval = 1;
} else
- rval = _obtain_lock(m, curthread);
+ rval = _obtain_lock(m, (uintptr_t)curthread);
LOCK_LOG_TRY("LOCK", &m->mtx_object, opts, rval, file, line);
if (rval)
@@ -434,7 +434,7 @@
* sleep waiting for it), or if we need to recurse on it.
*/
void
-_mtx_lock_sleep(struct mtx *m, struct thread *td, int opts, const char *file,
+_mtx_lock_sleep(struct mtx *m, uintptr_t tid, int opts, const char *file,
int line)
{
#if defined(SMP) && !defined(NO_ADAPTIVE_MUTEXES)
@@ -467,7 +467,7 @@
#ifdef MUTEX_PROFILING
contested = 0;
#endif
- while (!_obtain_lock(m, td)) {
+ while (!_obtain_lock(m, tid)) {
#ifdef MUTEX_PROFILING
contested = 1;
atomic_add_int(&m->mtx_contest_holding, 1);
@@ -495,7 +495,7 @@
* necessary.
*/
if (v == MTX_CONTESTED) {
- m->mtx_lock = (uintptr_t)td | MTX_CONTESTED;
+ m->mtx_lock = tid | MTX_CONTESTED;
turnstile_claim(&m->mtx_object);
break;
}
@@ -507,8 +507,7 @@
* or the state of the MTX_RECURSED bit changed.
*/
if ((v & MTX_CONTESTED) == 0 &&
- !atomic_cmpset_ptr(&m->mtx_lock, (void *)v,
- (void *)(v | MTX_CONTESTED))) {
+ !atomic_cmpset_ptr(&m->mtx_lock, v, v | MTX_CONTESTED)) {
turnstile_release(&m->mtx_object);
cpu_spinwait();
continue;
@@ -542,7 +541,7 @@
if (!cont_logged) {
CTR6(KTR_CONTENTION,
"contention: %p at %s:%d wants %s, taken by %s:%d",
- td, file, line, m->mtx_object.lo_name,
+ (void *)tid, file, line, m->mtx_object.lo_name,
WITNESS_FILE(&m->mtx_object),
WITNESS_LINE(&m->mtx_object));
cont_logged = 1;
@@ -559,7 +558,7 @@
if (cont_logged) {
CTR4(KTR_CONTENTION,
"contention end: %s acquired by %p at %s:%d",
- m->mtx_object.lo_name, td, file, line);
+ m->mtx_object.lo_name, (void *)tid, file, line);
}
#endif
#ifdef MUTEX_PROFILING
@@ -578,7 +577,7 @@
* is handled inline.
*/
void
-_mtx_lock_spin(struct mtx *m, struct thread *td, int opts, const char *file,
+_mtx_lock_spin(struct mtx *m, uintptr_t tid, int opts, const char *file,
int line)
{
int i = 0;
@@ -590,7 +589,7 @@
CTR1(KTR_LOCK, "_mtx_lock_spin: %p spinning", m);
for (;;) {
- if (_obtain_lock(m, td))
+ if (_obtain_lock(m, tid))
break;
/* Give interrupts a chance while we spin. */
==== //depot/projects/smpng/sys/sys/mutex.h#51 (text+ko) ====
@@ -100,11 +100,11 @@
void mtx_destroy(struct mtx *m);
void mtx_sysinit(void *arg);
void mutex_init(void);
-void _mtx_lock_sleep(struct mtx *m, struct thread *td, int opts,
+void _mtx_lock_sleep(struct mtx *m, uintptr_t tid, int opts,
const char *file, int line);
void _mtx_unlock_sleep(struct mtx *m, int opts, const char *file, int line);
#ifdef SMP
-void _mtx_lock_spin(struct mtx *m, struct thread *td, int opts,
+void _mtx_lock_spin(struct mtx *m, uintptr_t tid, int opts,
const char *file, int line);
#endif
void _mtx_unlock_spin(struct mtx *m, int opts, const char *file, int line);
@@ -127,19 +127,19 @@
/* Try to obtain mtx_lock once. */
#ifndef _obtain_lock
#define _obtain_lock(mp, tid) \
- atomic_cmpset_acq_ptr(&(mp)->mtx_lock, (void *)MTX_UNOWNED, (tid))
+ atomic_cmpset_acq_ptr(&(mp)->mtx_lock, MTX_UNOWNED, (tid))
#endif
/* Try to release mtx_lock if it is unrecursed and uncontested. */
#ifndef _release_lock
#define _release_lock(mp, tid) \
- atomic_cmpset_rel_ptr(&(mp)->mtx_lock, (tid), (void *)MTX_UNOWNED)
+ atomic_cmpset_rel_ptr(&(mp)->mtx_lock, (tid), MTX_UNOWNED)
#endif
/* Release mtx_lock quickly, assuming we own it. */
#ifndef _release_lock_quick
#define _release_lock_quick(mp) \
- atomic_store_rel_ptr(&(mp)->mtx_lock, (void *)MTX_UNOWNED)
+ atomic_store_rel_ptr(&(mp)->mtx_lock, MTX_UNOWNED)
#endif
/*
@@ -148,7 +148,7 @@
*/
#ifndef _get_sleep_lock
#define _get_sleep_lock(mp, tid, opts, file, line) do { \
- struct thread *_tid = (tid); \
+ uintptr_t _tid = (uintptr_t)(tid); \
\
if (!_obtain_lock((mp), _tid)) \
_mtx_lock_sleep((mp), _tid, (opts), (file), (line)); \
@@ -165,11 +165,11 @@
#ifndef _get_spin_lock
#ifdef SMP
#define _get_spin_lock(mp, tid, opts, file, line) do { \
- struct thread *_tid = (tid); \
+ uintptr_t _tid = (uintptr_t)(tid); \
\
critical_enter(); \
if (!_obtain_lock((mp), _tid)) { \
- if ((mp)->mtx_lock == (uintptr_t)_tid) \
+ if ((mp)->mtx_lock == _tid) \
(mp)->mtx_recurse++; \
else \
_mtx_lock_spin((mp), _tid, (opts), (file), (line)); \
@@ -177,14 +177,14 @@
} while (0)
#else /* SMP */
#define _get_spin_lock(mp, tid, opts, file, line) do { \
- struct thread *_tid = (tid); \
+ uintptr_t _tid = (uintptr_t)(tid); \
\
critical_enter(); \
- if ((mp)->mtx_lock == (uintptr_t)_tid) \
+ if ((mp)->mtx_lock == _tid) \
(mp)->mtx_recurse++; \
else { \
KASSERT((mp)->mtx_lock == MTX_UNOWNED, ("corrupt spinlock")); \
- (mp)->mtx_lock = (uintptr_t)_tid; \
+ (mp)->mtx_lock = _tid; \
} \
} while (0)
#endif /* SMP */
@@ -196,7 +196,9 @@
*/
#ifndef _rel_sleep_lock
#define _rel_sleep_lock(mp, tid, opts, file, line) do { \
- if (!_release_lock((mp), (tid))) \
+ uintptr_t _tid = (uintptr_t)(tid); \
+ \
+ if (!_release_lock((mp), _tid)) \
_mtx_unlock_sleep((mp), (opts), (file), (line)); \
} while (0)
#endif
More information about the p4-projects
mailing list