|
From: <sv...@va...> - 2008-04-04 16:45:18
|
Author: bart
Date: 2008-04-04 17:45:20 +0100 (Fri, 04 Apr 2008)
New Revision: 7840
Log:
Moved one-time initialization code from first intercepted pthread_create() call to _init() function.
Modified:
trunk/exp-drd/drd_pthread_intercepts.c
Modified: trunk/exp-drd/drd_pthread_intercepts.c
===================================================================
--- trunk/exp-drd/drd_pthread_intercepts.c 2008-04-03 12:20:47 UTC (rev 7839)
+++ trunk/exp-drd/drd_pthread_intercepts.c 2008-04-04 16:45:20 UTC (rev 7840)
@@ -64,7 +64,7 @@
ret_ty VG_WRAP_FUNCTION_ZZ(libpthreadZdsoZd0,f)(args)
-// Local data structures.
+/* Local data structures. */
typedef struct
{
@@ -80,13 +80,25 @@
} VgPosixThreadArgs;
-// Local variables.
+/* Function declarations. */
-static int vg_main_thread_state_is_set = 0;
+void _init(void);
+static void check_threading_library(void);
+static void vg_set_main_thread_state(void);
-// Function definitions.
+/* Function definitions. */
+/** Shared library initialization function: the _init() function is called
+ * after dlopen() has loaded the shared library. This function must not
+ * be declared static.
+ */
+void _init(void)
+{
+ check_threading_library();
+ vg_set_main_thread_state();
+}
+
static MutexT pthread_to_drd_mutex_type(const int kind)
{
switch (kind)
@@ -165,6 +177,7 @@
}
}
+/** Return 1 if LinuxThread has been detected, and 0 otherwise. */
static int detected_linuxthreads(void)
{
#if defined(linux)
@@ -185,10 +198,11 @@
#endif
}
-static void vg_set_main_thread_state(void)
+/** Stop and print an error message in case a non-supported threading
+ * library (LinuxThreads) has been detected.
+ */
+static void check_threading_library(void)
{
- int res;
-
if (detected_linuxthreads())
{
if (getenv("LD_ASSUME_KERNEL"))
@@ -210,7 +224,12 @@
}
abort();
}
+}
+static void vg_set_main_thread_state(void)
+{
+ int res;
+
VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__DRD_SUPPRESS_CURRENT_STACK,
0, 0, 0, 0, 0);
@@ -231,11 +250,6 @@
VALGRIND_GET_ORIG_FN(fn);
- if (vg_main_thread_state_is_set == 0)
- {
- vg_set_main_thread_state();
- vg_main_thread_state_is_set = 1;
- }
vg_start_suppression(&vgargs.wrapper_started,
sizeof(vgargs.wrapper_started));
vgargs.start = start;
|