|
From: <sv...@va...> - 2010-05-29 18:43:29
|
Author: bart
Date: 2010-05-29 19:43:21 +0100 (Sat, 29 May 2010)
New Revision: 11139
Log:
Handle statically initialized condition variables properly.
Modified:
trunk/drd/drd_clientreq.c
trunk/drd/drd_clientreq.h
trunk/drd/drd_cond.c
trunk/drd/drd_cond.h
trunk/drd/drd_pthread_intercepts.c
Modified: trunk/drd/drd_clientreq.c
===================================================================
--- trunk/drd/drd_clientreq.c 2010-05-29 18:42:14 UTC (rev 11138)
+++ trunk/drd/drd_clientreq.c 2010-05-29 18:43:21 UTC (rev 11139)
@@ -174,6 +174,11 @@
DRD_(rwlock_pre_unlock)(arg[1], user_rwlock);
break;
+ case VG_USERREQ__SET_PTHREAD_COND_INITIALIZER:
+ DRD_(pthread_cond_initializer) = (Addr)arg[1];
+ DRD_(pthread_cond_initializer_size) = arg[2];
+ break;
+
case VG_USERREQ__DRD_START_NEW_SEGMENT:
DRD_(thread_new_segment)(DRD_(PtThreadIdToDrdThreadId)(arg[1]));
break;
Modified: trunk/drd/drd_clientreq.h
===================================================================
--- trunk/drd/drd_clientreq.h 2010-05-29 18:42:14 UTC (rev 11138)
+++ trunk/drd/drd_clientreq.h 2010-05-29 18:43:21 UTC (rev 11139)
@@ -45,8 +45,14 @@
* source files.
*/
enum {
+ /* Declare the address and size of a variable with value
+ * PTHREAD_COND_INITIALIZER.
+ */
+ VG_USERREQ__SET_PTHREAD_COND_INITIALIZER = VG_USERREQ_TOOL_BASE('D', 'r'),
+ /* args: address, size. */
+
/* To ask the drd tool to start a new segment in the specified thread. */
- VG_USERREQ__DRD_START_NEW_SEGMENT = VG_USERREQ_TOOL_BASE('D', 'r'),
+ VG_USERREQ__DRD_START_NEW_SEGMENT,
/* args: POSIX thread ID. */
/* Tell drd the pthread_t of the running thread. */
Modified: trunk/drd/drd_cond.c
===================================================================
--- trunk/drd/drd_cond.c 2010-05-29 18:42:14 UTC (rev 11138)
+++ trunk/drd/drd_cond.c 2010-05-29 18:43:21 UTC (rev 11139)
@@ -29,6 +29,7 @@
#include "drd_mutex.h"
#include "pub_tool_errormgr.h" /* VG_(maybe_record_error)() */
#include "pub_tool_libcassert.h" /* tl_assert() */
+#include "pub_tool_libcbase.h" /* VG_(memcmp)() */
#include "pub_tool_libcprint.h" /* VG_(printf)() */
#include "pub_tool_machine.h" /* VG_(get_IP)() */
#include "pub_tool_threadstate.h" /* VG_(get_running_tid)() */
@@ -45,6 +46,12 @@
static Bool DRD_(s_trace_cond);
+/* Global variables. */
+
+Addr DRD_(pthread_cond_initializer);
+int DRD_(pthread_cond_initializer_size);
+
+
/* Function definitions. */
void DRD_(cond_set_report_signal_unlocked)(const Bool r)
@@ -382,12 +389,17 @@
cond);
}
- if (!p)
+ tl_assert(DRD_(pthread_cond_initializer));
+ if (!p && VG_(memcmp)((void*)cond, (void*)DRD_(pthread_cond_initializer),
+ DRD_(pthread_cond_initializer_size)) != 0)
{
not_initialized(cond);
return;
}
+ if (!p)
+ p = cond_get_or_allocate(cond);
+
cond_signal(DRD_(thread_get_running_tid)(), p);
}
@@ -405,11 +417,16 @@
}
p = DRD_(cond_get)(cond);
- if (!p)
+ tl_assert(DRD_(pthread_cond_initializer));
+ if (!p && VG_(memcmp)((void*)cond, (void*)DRD_(pthread_cond_initializer),
+ DRD_(pthread_cond_initializer_size)) != 0)
{
not_initialized(cond);
return;
}
+ if (!p)
+ p = cond_get_or_allocate(cond);
+
cond_signal(DRD_(thread_get_running_tid)(), p);
}
Modified: trunk/drd/drd_cond.h
===================================================================
--- trunk/drd/drd_cond.h 2010-05-29 18:42:14 UTC (rev 11138)
+++ trunk/drd/drd_cond.h 2010-05-29 18:43:21 UTC (rev 11139)
@@ -36,6 +36,12 @@
struct cond_info;
+/* Variable declarations. */
+
+extern Addr DRD_(pthread_cond_initializer);
+extern int DRD_(pthread_cond_initializer_size);
+
+
/* Function declarations. */
void DRD_(cond_set_report_signal_unlocked)(const Bool r);
Modified: trunk/drd/drd_pthread_intercepts.c
===================================================================
--- trunk/drd/drd_pthread_intercepts.c 2010-05-29 18:42:14 UTC (rev 11138)
+++ trunk/drd/drd_pthread_intercepts.c 2010-05-29 18:43:21 UTC (rev 11139)
@@ -134,6 +134,7 @@
static void DRD_(init)(void) __attribute__((constructor));
static void DRD_(check_threading_library)(void);
static void DRD_(set_main_thread_state)(void);
+static void DRD_(set_pthread_cond_initializer)(void);
/* Function definitions. */
@@ -152,6 +153,7 @@
{
DRD_(check_threading_library)();
DRD_(set_main_thread_state)();
+ DRD_(set_pthread_cond_initializer)();
}
/**
@@ -339,7 +341,20 @@
// Make sure that DRD knows about the main thread's POSIX thread ID.
VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SET_PTHREADID,
pthread_self(), 0, 0, 0, 0);
+}
+/** Tell DRD which value PTHREAD_COND_INITIALIZER has. */
+static void DRD_(set_pthread_cond_initializer)(void)
+{
+ int res;
+
+ static pthread_cond_t pthread_cond_initializer = PTHREAD_COND_INITIALIZER;
+
+ // Make sure that DRD knows about the main thread's POSIX thread ID.
+ VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SET_PTHREAD_COND_INITIALIZER,
+ &pthread_cond_initializer,
+ sizeof(pthread_cond_initializer),
+ 0, 0, 0);
}
|