case VG_USERREQ__PRE_MUTEX_LOCK:
if (thread_enter_synchr(drd_tid) == 0)
- drd_pre_mutex_lock(arg[1], arg[2]);
+ drd_pre_mutex_lock(arg[1], arg[2], arg[3]);
break;
case VG_USERREQ__POST_MUTEX_LOCK:
/* args: Addr, MutexT */
/* to notify the drd tool of pthread_mutex_lock calls */
VG_USERREQ__PRE_MUTEX_LOCK,
- /* args: Addr, MutexT */
+ /* args: Addr, MutexT, Bool */
/* to notify the drd tool of pthread_mutex_lock calls */
VG_USERREQ__POST_MUTEX_LOCK,
/* args: Addr, Bool */
mutex_post_destroy(mutex);
}
-void drd_pre_mutex_lock(const Addr mutex, const MutexT mutex_type)
+void drd_pre_mutex_lock(const Addr mutex, const MutexT mutex_type,
+ const Bool trylock)
{
- mutex_pre_lock(mutex, mutex_type);
+ mutex_pre_lock(mutex, mutex_type, trylock);
}
void drd_post_mutex_lock(const Addr mutex, const Bool took_lock)
* an attempt is made to lock recursively a synchronization object that must
* not be locked recursively.
*/
-void mutex_pre_lock(const Addr mutex, MutexT mutex_type)
+void mutex_pre_lock(const Addr mutex, const MutexT mutex_type,
+ const Bool trylock)
{
struct mutex_info* p;
p = mutex_get_or_allocate(mutex, mutex_type);
-
- tl_assert(p);
-
if (s_trace_mutex)
{
VG_(message)(Vg_UserMsg,
thread_get_running_tid(),
mutex_get_typename(p),
mutex,
- p->recursion_count,
- p->owner);
+ p ? p->recursion_count : -1,
+ p ? p->owner : DRD_INVALID_THREADID);
+ }
+
+ if (p == 0)
+ {
+ GenericErrInfo GEI;
+ VG_(maybe_record_error)(VG_(get_running_tid)(),
+ GenericErr,
+ VG_(get_IP)(VG_(get_running_tid)()),
+ "Not a mutex",
+ &GEI);
+ return;
}
+ tl_assert(p);
+
if (mutex_type == mutex_type_invalid_mutex)
{
GenericErrInfo GEI;
return;
}
- if (p->owner == thread_get_running_tid()
+ if (! trylock
+ && p->owner == thread_get_running_tid()
&& p->recursion_count >= 1
&& mutex_type != mutex_type_recursive_mutex)
{
const MutexT mutex_type);
void mutex_post_destroy(const Addr mutex);
struct mutex_info* mutex_get(const Addr mutex);
-void mutex_pre_lock(const Addr mutex,
- const MutexT mutex_type);
+void mutex_pre_lock(const Addr mutex, const MutexT mutex_type,
+ const Bool trylock);
void mutex_post_lock(const Addr mutex, const Bool took_lock);
void mutex_unlock(const Addr mutex, const MutexT mutex_type);
const char* mutex_get_typename(struct mutex_info* const p);
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__PRE_MUTEX_LOCK,
- mutex, mutex_type(mutex), 0, 0, 0);
+ mutex, mutex_type(mutex), 1, 0, 0);
CALL_FN_W_W(ret, fn, mutex);
VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_LOCK,
mutex, ret == 0, 0, 0, 0);
void drd_pre_mutex_init(Addr mutex, const MutexT mutex_type);
void drd_post_mutex_destroy(Addr mutex, const MutexT mutex_type);
-void drd_pre_mutex_lock(const Addr mutex, const MutexT mutex_type);
+void drd_pre_mutex_lock(const Addr mutex, const MutexT mutex_type,
+ const Bool trylock);
void drd_post_mutex_lock(Addr mutex, const Bool took_lock);
void drd_pre_mutex_unlock(const Addr mutex, const MutexT mutex_type);