Author: sewardj Date: 2008-02-25 12:10:07 +0000 (Mon, 25 Feb 2008) New Revision: 7454
Log: Intercept pthread_rwlock_try{rd,wr}lock. Fixes #158212. Modified: trunk/helgrind/hg_intercepts.c trunk/helgrind/hg_main.c Modified: trunk/helgrind/hg_intercepts.c =================================================================== --- trunk/helgrind/hg_intercepts.c 2008-02-25 00:11:05 UTC (rev 7453) +++ trunk/helgrind/hg_intercepts.c 2008-02-25 12:10:07 UTC (rev 7454) @@ -790,6 +790,7 @@ } +// pthread_rwlock_wrlock PTH_FUNC(int, pthreadZurwlockZuwrlock, // pthread_rwlock_wrlock pthread_rwlock_t* rwlock) { @@ -800,8 +801,9 @@ fprintf(stderr, "<< pthread_rwl_wlk %p", rwlock); fflush(stderr); } - DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_PRE, - pthread_rwlock_t*,rwlock, long,1/*isW*/); + DO_CREQ_v_WWW(_VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_PRE, + pthread_rwlock_t*,rwlock, + long,1/*isW*/, long,0/*!isTryLock*/); CALL_FN_W_W(ret, fn, rwlock); @@ -819,6 +821,7 @@ } +// pthread_rwlock_rdlock PTH_FUNC(int, pthreadZurwlockZurdlock, // pthread_rwlock_rdlock pthread_rwlock_t* rwlock) { @@ -829,8 +832,9 @@ fprintf(stderr, "<< pthread_rwl_rlk %p", rwlock); fflush(stderr); } - DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_PRE, - pthread_rwlock_t*,rwlock, long,0/*!isW*/); + DO_CREQ_v_WWW(_VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_PRE, + pthread_rwlock_t*,rwlock, + long,0/*!isW*/, long,0/*!isTryLock*/); CALL_FN_W_W(ret, fn, rwlock); @@ -848,6 +852,81 @@ } +// pthread_rwlock_trywrlock +PTH_FUNC(int, pthreadZurwlockZutrywrlock, // pthread_rwlock_trywrlock + pthread_rwlock_t* rwlock) +{ + int ret; + OrigFn fn; + VALGRIND_GET_ORIG_FN(fn); + if (TRACE_PTH_FNS) { + fprintf(stderr, "<< pthread_rwl_trywlk %p", rwlock); fflush(stderr); + } + + DO_CREQ_v_WWW(_VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_PRE, + pthread_rwlock_t*,rwlock, + long,1/*isW*/, long,1/*isTryLock*/); + + CALL_FN_W_W(ret, fn, rwlock); + + /* There's a hole here: libpthread now knows the lock is locked, + but the tool doesn't, so some other thread could run and detect + that the lock has been acquired by someone (this thread). Does + this matter? Not sure, but I don't think so. */ + + if (ret == 0 /*success*/) { + DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_POST, + pthread_rwlock_t*,rwlock, long,1/*isW*/); + } else { + if (ret != EBUSY) + DO_PthAPIerror( "pthread_rwlock_trywrlock", ret ); + } + + if (TRACE_PTH_FNS) { + fprintf(stderr, " :: rwl_trywlk -> %d >>\n", ret); + } + return ret; +} + + +// pthread_rwlock_tryrdlock +PTH_FUNC(int, pthreadZurwlockZutryrdlock, // pthread_rwlock_tryrdlock + pthread_rwlock_t* rwlock) +{ + int ret; + OrigFn fn; + VALGRIND_GET_ORIG_FN(fn); + if (TRACE_PTH_FNS) { + fprintf(stderr, "<< pthread_rwl_tryrlk %p", rwlock); fflush(stderr); + } + + DO_CREQ_v_WWW(_VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_PRE, + pthread_rwlock_t*,rwlock, + long,0/*!isW*/, long,1/*isTryLock*/); + + CALL_FN_W_W(ret, fn, rwlock); + + /* There's a hole here: libpthread now knows the lock is locked, + but the tool doesn't, so some other thread could run and detect + that the lock has been acquired by someone (this thread). Does + this matter? Not sure, but I don't think so. */ + + if (ret == 0 /*success*/) { + DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_POST, + pthread_rwlock_t*,rwlock, long,0/*!isW*/); + } else { + if (ret != EBUSY) + DO_PthAPIerror( "pthread_rwlock_tryrdlock", ret ); + } + + if (TRACE_PTH_FNS) { + fprintf(stderr, " :: rwl_tryrlk -> %d >>\n", ret); + } + return ret; +} + + +// pthread_rwlock_unlock PTH_FUNC(int, pthreadZurwlockZuunlock, // pthread_rwlock_unlock pthread_rwlock_t* rwlock) { @@ -1155,8 +1234,9 @@ fflush(stderr); } - DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_PRE, - void*,self, long,0/*!isW*/); + DO_CREQ_v_WWW(_VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_PRE, + void*,self, + long,0/*!isW*/, long,0/*!isTryLock*/); CALL_FN_v_W(fn, self); @@ -1181,8 +1261,9 @@ fflush(stderr); } - DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_PRE, - void*,self, long,1/*isW*/); + DO_CREQ_v_WWW(_VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_PRE, + void*,self, + long,1/*isW*/, long,0/*!isTryLock*/); CALL_FN_v_W(fn, self); Modified: trunk/helgrind/hg_main.c =================================================================== --- trunk/helgrind/hg_main.c 2008-02-25 00:11:05 UTC (rev 7453) +++ trunk/helgrind/hg_main.c 2008-02-25 12:10:07 UTC (rev 7454) @@ -6245,7 +6245,9 @@ } static -void evh__HG_PTHREAD_RWLOCK_LOCK_PRE ( ThreadId tid, void* rwl, Word isW ) +void evh__HG_PTHREAD_RWLOCK_LOCK_PRE ( ThreadId tid, + void* rwl, + Word isW, Word isTryLock ) { /* Just check the rwl is sane; nothing else to do. */ // 'rwl' may be invalid - not checked by wrapper @@ -6256,6 +6258,7 @@ (Int)tid, (Int)isW, (void*)rwl ); tl_assert(isW == 0 || isW == 1); /* assured us by wrapper */ + tl_assert(isTryLock == 0 || isTryLock == 1); /* assured us by wrapper */ thr = map_threads_maybe_lookup( tid ); tl_assert(thr); /* cannot fail - Thread* must already exist */ @@ -7652,9 +7655,10 @@ evh__HG_PTHREAD_RWLOCK_DESTROY_PRE( tid, (void*)args[1] ); break; - /* rwlock=arg[1], isW=arg[2] */ + /* rwlock=arg[1], isW=arg[2], isTryLock=arg[3] */ case _VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_PRE: - evh__HG_PTHREAD_RWLOCK_LOCK_PRE( tid, (void*)args[1], args[2] ); + evh__HG_PTHREAD_RWLOCK_LOCK_PRE( tid, (void*)args[1], + args[2], args[3] ); break; /* rwlock=arg[1], isW=arg[2] */ ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Valgrind-developers mailing list Valgrind-developers@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/valgrind-developers