From def3aa64618f21b8362f7b00a977bb48c430b6e6 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 7 Jul 2008 08:10:56 +0000 Subject: [PATCH] Made spinlocks work again. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@8372 --- drd/drd_clientreq.c | 10 +++++++--- drd/drd_clientreq.h | 8 ++++++-- drd/drd_pthread_intercepts.c | 12 +++++++++--- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/drd/drd_clientreq.c b/drd/drd_clientreq.c index e83d0e67d9..9a267e541d 100644 --- a/drd/drd_clientreq.c +++ b/drd/drd_clientreq.c @@ -247,9 +247,13 @@ static Bool drd_handle_client_request(ThreadId vg_tid, UWord* arg, UWord* ret) thread_leave_synchr(drd_tid); break; - case VG_USERREQ__SPIN_INIT_OR_UNLOCK: - tl_assert(thread_get_synchr_nesting_count(drd_tid) == 0); - drd_spin_init_or_unlock(arg[1]); + case VG_USERREQ__PRE_SPIN_INIT_OR_UNLOCK: + if (thread_enter_synchr(drd_tid) == 0) + drd_spin_init_or_unlock(arg[1]); + break; + + case VG_USERREQ__POST_SPIN_INIT_OR_UNLOCK: + thread_leave_synchr(drd_tid); break; case VG_USERREQ__PRE_COND_INIT: diff --git a/drd/drd_clientreq.h b/drd/drd_clientreq.h index 57bd9d13d3..24033827ad 100644 --- a/drd/drd_clientreq.h +++ b/drd/drd_clientreq.h @@ -83,8 +83,12 @@ enum { /* to notify the drd tool of pthread_mutex_unlock calls */ VG_USERREQ__POST_MUTEX_UNLOCK, /* args: Addr */ - VG_USERREQ__SPIN_INIT_OR_UNLOCK, - /* args: Addr spinlock */ + /* to notify the drd tool of a pthread_spin_init/pthread_spin_unlock call */ + VG_USERREQ__PRE_SPIN_INIT_OR_UNLOCK, + /* args: Addr */ + /* to notify the drd tool of a pthread_spin_init/pthread_spin_unlock call */ + VG_USERREQ__POST_SPIN_INIT_OR_UNLOCK, + /* args: Addr */ /* to notify the drd tool of a pthread_cond_init call. */ diff --git a/drd/drd_pthread_intercepts.c b/drd/drd_pthread_intercepts.c index cd642f1a37..62dd1d9d56 100644 --- a/drd/drd_pthread_intercepts.c +++ b/drd/drd_pthread_intercepts.c @@ -550,9 +550,11 @@ PTH_FUNC(int, pthreadZuspinZuinit, // pthread_spin_init int res; OrigFn fn; VALGRIND_GET_ORIG_FN(fn); - VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SPIN_INIT_OR_UNLOCK, - spinlock, mutex_type_spinlock, 0, 0, 0); + VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SPIN_INIT_OR_UNLOCK, + spinlock, 0, 0, 0, 0); CALL_FN_W_WW(ret, fn, spinlock, pshared); + VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SPIN_INIT_OR_UNLOCK, + spinlock, 0, 0, 0, 0); return ret; } @@ -564,6 +566,8 @@ PTH_FUNC(int, pthreadZuspinZudestroy, // pthread_spin_destroy int res; OrigFn fn; VALGRIND_GET_ORIG_FN(fn); + VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_MUTEX_DESTROY, + spinlock, 0, 0, 0, 0); CALL_FN_W_W(ret, fn, spinlock); VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_DESTROY, spinlock, mutex_type_spinlock, 0, 0, 0); @@ -610,9 +614,11 @@ PTH_FUNC(int, pthreadZuspinZuunlock, // pthread_spin_unlock int res; OrigFn fn; VALGRIND_GET_ORIG_FN(fn); - VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SPIN_INIT_OR_UNLOCK, + VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_SPIN_INIT_OR_UNLOCK, spinlock, mutex_type_spinlock, 0, 0, 0); CALL_FN_W_W(ret, fn, spinlock); + VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_SPIN_INIT_OR_UNLOCK, + spinlock, 0, 0, 0, 0); return ret; } -- 2.47.2