Author: sewardj
Date: 2007-11-30 08:30:29 +0000 (Fri, 30 Nov 2007)
New Revision: 7252

Log:
Remove pthread_object_size.h and associated hardwired constants.
(Bart Van Assche)

Added:
   trunk/exp-drd/priv_drd_clientreq.h
Removed:
   trunk/exp-drd/pthread_object_size.h
Modified:
   trunk/exp-drd/TODO.txt
   trunk/exp-drd/drd_clientreq.c
   trunk/exp-drd/drd_clientreq.h
   trunk/exp-drd/drd_cond.c
   trunk/exp-drd/drd_cond.h
   trunk/exp-drd/drd_main.c
   trunk/exp-drd/drd_mutex.c
   trunk/exp-drd/drd_mutex.h
   trunk/exp-drd/drd_preloaded.c
   trunk/exp-drd/drd_thread.c
   trunk/exp-drd/drd_track.h
   trunk/exp-drd/tests/Makefile.am


Modified: trunk/exp-drd/TODO.txt
===================================================================
--- trunk/exp-drd/TODO.txt      2007-11-29 13:04:03 UTC (rev 7251)
+++ trunk/exp-drd/TODO.txt      2007-11-30 08:30:29 UTC (rev 7252)
@@ -19,7 +19,6 @@
   AMD64).
 - Change s_threadinfo[] from an array into an OSet or VgHashTable, in order to
   make ThreadId <> DrdThreadId <> pthread_t conversions faster.
-- Write a configure test that figures out sizeof(pthread_mutex_t) etc.
 - [AMD64] Find out why removing 'write(1, "", 0)' in drd_preloaded.c triggers
   a crash on AMD64. Is this a drd or a VEX bug ?
 - Reintroduce the const keyword in the function declarations of the OSet

Modified: trunk/exp-drd/drd_clientreq.c
===================================================================
--- trunk/exp-drd/drd_clientreq.c       2007-11-29 13:04:03 UTC (rev 7251)
+++ trunk/exp-drd/drd_clientreq.c       2007-11-30 08:30:29 UTC (rev 7252)
@@ -4,7 +4,7 @@
 #include "drd_suppression.h"      // drd_start_suppression()
 #include "drd_thread.h"
 #include "drd_track.h"
-#include "pthread_object_size.h"
+#include "priv_drd_clientreq.h"
 #include "pub_core_tooliface.h"   // VG_TRACK()
 #include "pub_tool_basics.h"      // Bool
 #include "pub_tool_libcassert.h"
@@ -20,24 +20,26 @@
    struct mutex_info* mutex_p = mutex_get(spinlock);
    if (mutex_p)
    {
-      mutex_unlock(spinlock);
+      mutex_unlock(spinlock, mutex_type_spinlock);
    }
    else
    {
-      mutex_init(spinlock, size);
+      mutex_init(spinlock, size, mutex_type_spinlock);
    }
 }
 
-static void drd_pre_cond_wait(const Addr cond, const Addr mutex)
+static void drd_pre_cond_wait(const Addr cond, const SizeT cond_size,
+                              const Addr mutex)
 {
-   mutex_unlock(mutex);
-   cond_pre_wait(cond, mutex);
+   mutex_unlock(mutex, mutex_type_mutex);
+   cond_pre_wait(cond, cond_size, mutex);
 }
 
-static void drd_post_cond_wait(const Addr cond, const Addr mutex)
+static void drd_post_cond_wait(const Addr cond, const Addr mutex,
+                               const SizeT size)
 {
    cond_post_wait(cond);
-   mutex_lock(mutex, PTHREAD_MUTEX_SIZE);
+   mutex_lock(mutex, size, mutex_type_mutex);
 }
 
 static void drd_pre_cond_signal(const Addr cond)
@@ -105,7 +107,7 @@
       break;
 
    case VG_USERREQ__PRE_MUTEX_INIT:
-      drd_pre_mutex_init(arg[1], arg[2]);
+      drd_pre_mutex_init(arg[1], arg[2], arg[3]);
       break;
 
    case VG_USERREQ__POST_MUTEX_DESTROY:
@@ -113,15 +115,15 @@
       break;
 
    case VG_USERREQ__PRE_PTHREAD_MUTEX_LOCK:
-      drd_pre_mutex_lock(thread_get_running_tid(), arg[1], arg[2]);
+      drd_pre_mutex_lock(thread_get_running_tid(), arg[1], arg[2], arg[3]);
       break;
 
    case VG_USERREQ__POST_PTHREAD_MUTEX_LOCK:
-      drd_post_mutex_lock(thread_get_running_tid(), arg[1], arg[2]);
+      drd_post_mutex_lock(thread_get_running_tid(), arg[1], arg[2], arg[3]);
       break;
 
    case VG_USERREQ__PRE_PTHREAD_MUTEX_UNLOCK:
-      drd_pre_mutex_unlock(thread_get_running_tid(), arg[1]);
+      drd_pre_mutex_unlock(thread_get_running_tid(), arg[1], arg[3]);
       break;
 
    case VG_USERREQ__SPIN_INIT_OR_UNLOCK:
@@ -133,15 +135,16 @@
       break;
 
    case VG_USERREQ__PRE_PTHREAD_COND_DESTROY:
-      drd_pre_cond_destroy(arg[1], arg[2]);
+      drd_pre_cond_destroy(arg[1]);
       break;
 
    case VG_USERREQ__PRE_PTHREAD_COND_WAIT:
-      drd_pre_cond_wait(arg[1], arg[2]);
+      drd_pre_cond_wait(arg[1]/*cond*/, arg[2]/*cond_size*/, arg[3]/*mutex*/);
       break;
 
    case VG_USERREQ__POST_PTHREAD_COND_WAIT:
-      drd_post_cond_wait(arg[1], arg[2]);
+      drd_post_cond_wait(arg[1]/*cond*/, arg[3]/*mutex*/,
+                         arg[4]/*mutex_size*/);
       break;
 
    case VG_USERREQ__PRE_PTHREAD_COND_SIGNAL:

Modified: trunk/exp-drd/drd_clientreq.h
===================================================================
--- trunk/exp-drd/drd_clientreq.h       2007-11-29 13:04:03 UTC (rev 7251)
+++ trunk/exp-drd/drd_clientreq.h       2007-11-30 08:30:29 UTC (rev 7252)
@@ -54,16 +54,16 @@
 
   /* To notify the core of a pthread_mutex_init call */
   VG_USERREQ__PRE_MUTEX_INIT,
-  /* args: Addr, SizeT */
+  /* args: Addr, MutexT */
   /* To notify the core of a pthread_mutex_destroy call */
   VG_USERREQ__POST_MUTEX_DESTROY,
-  /* args: Addr, SizeT */
+  /* args: Addr, SizeT, MutexT */
   /* To notify the core of pthread_mutex_lock calls */
   VG_USERREQ__PRE_PTHREAD_MUTEX_LOCK,
-  /* args: Addr, SizeT */
+  /* args: Addr, SizeT, MutexT */
   /* To notify the core of pthread_mutex_lock calls */
   VG_USERREQ__POST_PTHREAD_MUTEX_LOCK,
-  /* args: Addr, SizeT */
+  /* args: Addr, SizeT, MutexT */
   /* To notify the core of pthread_mutex_unlock calls */
   VG_USERREQ__PRE_PTHREAD_MUTEX_UNLOCK,
   /* args: Addr */
@@ -73,14 +73,14 @@
 
   /* To notify the core of a pthread_cond_init call */
   VG_USERREQ__POST_PTHREAD_COND_INIT,
-  /* args: Addr, SizeT */
+  /* args: Addr */
   /* To notify the core of a pthread_cond_destroy call */
   VG_USERREQ__PRE_PTHREAD_COND_DESTROY,
-  /* args: Addr, SizeT */
+  /* args: Addr cond, SizeT cond_size, Addr mutex, SizeT mutex_size */
   VG_USERREQ__PRE_PTHREAD_COND_WAIT,
-  /* args: Addr cond, Addr mutex */
+  /* args: Addr cond, SizeT cond_size, Addr mutex, SizeT mutex_size */
   VG_USERREQ__POST_PTHREAD_COND_WAIT,
-  /* args: Addr cond, Addr mutex */
+  /* args: Addr cond, SizeT cond_size, Addr mutex, SizeT mutex_size */
   VG_USERREQ__PRE_PTHREAD_COND_SIGNAL,
   /* args: Addr cond */
   VG_USERREQ__PRE_PTHREAD_COND_BROADCAST,
@@ -88,7 +88,11 @@
 
 };
 
-void drd_clientreq_init(void);
+typedef enum
+{
+   mutex_type_mutex = 1,
+   mutex_type_spinlock = 2,
+} MutexT;
 
 
 #endif //  __DRD_CLIENTREQ_H

Modified: trunk/exp-drd/drd_cond.c
===================================================================
--- trunk/exp-drd/drd_cond.c    2007-11-29 13:04:03 UTC (rev 7251)
+++ trunk/exp-drd/drd_cond.c    2007-11-30 08:30:29 UTC (rev 7252)
@@ -27,7 +27,6 @@
 #include "drd_error.h"
 #include "drd_mutex.h"
 #include "drd_suppression.h"
-#include "pthread_object_size.h"
 #include "pub_tool_errormgr.h"    // VG_(maybe_record_error)()
 #include "pub_tool_libcassert.h"  // tl_assert()
 #include "pub_tool_libcprint.h"   // VG_(printf)()
@@ -46,29 +45,37 @@
 }
 
 static
-void cond_initialize(struct cond_info* const p, const Addr cond)
+void cond_initialize(struct cond_info* const p, const Addr cond,
+                     const SizeT size)
 {
   tl_assert(cond != 0);
 
   p->cond         = cond;
+  p->size         = size;
   p->waiter_count = 0;
   p->mutex        = 0;
 }
 
-static struct cond_info* cond_get_or_allocate(const Addr cond)
+static struct cond_info*
+cond_get_or_allocate(const Addr cond, const SizeT size)
 {
   int i;
   for (i = 0; i < sizeof(s_cond)/sizeof(s_cond[0]); i++)
+  {
     if (s_cond[i].cond == cond)
+    {
+      tl_assert(s_cond[i].size == size);
       return &s_cond[i];
+    }
+  }
   for (i = 0; i < sizeof(s_cond)/sizeof(s_cond[0]); i++)
   {
     if (s_cond[i].cond == 0)
     {
-      cond_initialize(&s_cond[i], cond);
+      cond_initialize(&s_cond[i], cond, size);
       /* TO DO: replace the constant below by a symbolic constant referring */
       /* to sizeof(pthread_cond_t).                                        */
-      drd_start_suppression(cond, cond + PTHREAD_COND_SIZE, "cond");
+      drd_start_suppression(cond, cond + size, "cond");
       return &s_cond[i];
     }
   }
@@ -76,7 +83,7 @@
   return 0;
 }
 
-void cond_init(const Addr cond)
+void cond_init(const Addr cond, const SizeT size)
 {
   if (s_trace_cond)
   {
@@ -85,7 +92,8 @@
                                VG_(clo_backtrace_size));
   }
   tl_assert(cond_get(cond) == 0);
-  cond_get_or_allocate(cond);
+  tl_assert(size > 0);
+  cond_get_or_allocate(cond, size);
 }
 
 void cond_destroy(struct cond_info* const p)
@@ -100,7 +108,7 @@
   // TO DO: print a proper error message if waiter_count != 0.
   tl_assert(p->waiter_count == 0);
 
-  drd_finish_suppression(p->cond, p->cond + PTHREAD_COND_SIZE);
+  drd_finish_suppression(p->cond, p->cond + p->size);
 
   p->cond         = 0;
   p->waiter_count = 0;
@@ -116,11 +124,11 @@
   return 0;
 }
 
-int cond_pre_wait(const Addr cond, const Addr mutex)
+int cond_pre_wait(const Addr cond, const SizeT cond_size, const Addr mutex)
 {
   struct cond_info* p;
 
-  p = cond_get_or_allocate(cond);
+  p = cond_get_or_allocate(cond, cond_size);
   if (p->waiter_count == 0)
   {
     p->mutex = mutex;
@@ -194,7 +202,7 @@
   {
     if (a1 <= s_cond[i].cond && s_cond[i].cond < a2)
     {
-      tl_assert(s_cond[i].cond + PTHREAD_COND_SIZE <= a2);
+      tl_assert(s_cond[i].cond + s_cond[i].size <= a2);
       cond_destroy(&s_cond[i]);
     }
   }

Modified: trunk/exp-drd/drd_cond.h
===================================================================
--- trunk/exp-drd/drd_cond.h    2007-11-29 13:04:03 UTC (rev 7251)
+++ trunk/exp-drd/drd_cond.h    2007-11-30 08:30:29 UTC (rev 7252)
@@ -38,17 +38,18 @@
 
 struct cond_info
 {
-  Addr cond;  // Pointer to client condition variable.
-  int  waiter_count;
-  Addr mutex; // Client mutex specified in pthread_cond_wait() call, and null
+  Addr  cond;  // Pointer to client condition variable.
+  SizeT size;  // sizeof(pthread_cond_t)
+  int   waiter_count;
+  Addr  mutex; // Client mutex specified in pthread_cond_wait() call, and null
               // if no client threads are currently waiting on this cond.var.
 };
 
 void cond_set_trace(const Bool trace_cond);
-void cond_init(const Addr cond);
+void cond_init(const Addr cond, const SizeT size);
 void cond_destroy(struct cond_info* const p);
 struct cond_info* cond_get(Addr const mutex);
-int cond_pre_wait(const Addr cond, const Addr mutex);
+int cond_pre_wait(const Addr cond, const SizeT cond_size, const Addr mutex);
 int cond_post_wait(const Addr cond);
 void cond_pre_signal(Addr const cond);
 void cond_pre_broadcast(Addr const cond);

Modified: trunk/exp-drd/drd_main.c
===================================================================
--- trunk/exp-drd/drd_main.c    2007-11-29 13:04:03 UTC (rev 7251)
+++ trunk/exp-drd/drd_main.c    2007-11-30 08:30:29 UTC (rev 7252)
@@ -34,7 +34,7 @@
 #include "drd_thread.h"
 #include "drd_track.h"
 #include "drd_vc.h"
-#include "pthread_object_size.h"
+#include "priv_drd_clientreq.h"
 #include "pub_core_mallocfree.h"
 #include "pub_core_options.h"
 #include "pub_tool_vki.h"
@@ -469,12 +469,12 @@
    thread_finished(drd_tid);
 }
 
-void drd_pre_mutex_init(Addr mutex, SizeT size)
+void drd_pre_mutex_init(Addr mutex, SizeT size, MutexT mutex_type)
 {
-   mutex_init(mutex, size);
+   mutex_init(mutex, size, mutex_type);
 }
 
-void drd_post_mutex_destroy(Addr mutex, SizeT size)
+void drd_post_mutex_destroy(Addr mutex, MutexT mutex_type)
 {
    struct mutex_info* p;
 
@@ -490,29 +490,32 @@
 
 void drd_pre_mutex_lock(const DrdThreadId drd_tid,
                         const Addr mutex,
-                        const SizeT size)
+                        const SizeT size,
+                        const MutexT mutex_type)
 {
    if (mutex_get(mutex) == 0)
    {
-      mutex_init(mutex, size);
+      mutex_init(mutex, size, mutex_type);
    }
 }
 
 void drd_post_mutex_lock(const DrdThreadId drd_tid,
                          const Addr mutex,
-                         const SizeT size)
+                         const SizeT size,
+                         const MutexT mutex_type)
 {
-   mutex_lock(mutex, size);
+   mutex_lock(mutex, size, mutex_type);
 }
 
-void drd_pre_mutex_unlock(const DrdThreadId drd_tid, Addr mutex)
+void drd_pre_mutex_unlock(const DrdThreadId drd_tid,
+                          const Addr mutex,
+                          const MutexT mutex_type)
 {
-   mutex_unlock(mutex);
+   mutex_unlock(mutex, mutex_type);
 }
 
 void drd_post_cond_init(Addr cond, SizeT s)
 {
-   tl_assert(s == PTHREAD_COND_SIZE);
    if (cond_get(cond))
    {
       CondErrInfo cei = { .cond = cond };
@@ -522,14 +525,13 @@
                               "initialized twice",
                               &cei);
    }
-   cond_init(cond);
+   cond_init(cond, s);
 }
 
-void drd_pre_cond_destroy(Addr cond, SizeT s)
+void drd_pre_cond_destroy(Addr cond)
 {
    struct cond_info* cond_p;
 
-   tl_assert(s == PTHREAD_COND_SIZE);
    cond_p = cond_get(cond);
    if (cond_p)
    {

Modified: trunk/exp-drd/drd_mutex.c
===================================================================
--- trunk/exp-drd/drd_mutex.c   2007-11-29 13:04:03 UTC (rev 7251)
+++ trunk/exp-drd/drd_mutex.c   2007-11-30 08:30:29 UTC (rev 7252)
@@ -26,7 +26,7 @@
 #include "drd_error.h"
 #include "drd_mutex.h"
 #include "drd_suppression.h"
-#include "pthread_object_size.h"
+#include "priv_drd_clientreq.h"
 #include "pub_tool_errormgr.h"    // VG_(maybe_record_error)()
 #include "pub_tool_libcassert.h"  // tl_assert()
 #include "pub_tool_libcprint.h"   // VG_(printf)()
@@ -40,6 +40,7 @@
 {
   Addr        mutex;           // Pointer to client mutex.
   SizeT       size;            // Size in bytes of client-side object.
+  MutexT      mutex_type;      // pthread_mutex_t or pthread_spinlock_t.
   int         recursion_count; // 0 if free, >= 1 if locked.
   DrdThreadId owner;           // owner if locked, last owner if free.
   VectorClock vc;              // vector clock associated with last unlock.
@@ -64,30 +65,47 @@
 static
 void mutex_initialize(struct mutex_info* const p,
                       const Addr mutex,
-                      const SizeT size)
+                      const SizeT size,
+                      const MutexT mutex_type)
 {
   tl_assert(mutex != 0);
   tl_assert(size > 0);
+  tl_assert(mutex_type == mutex_type_mutex
+            || mutex_type == mutex_type_spinlock);
 
   p->mutex           = mutex;
   p->size            = size;
+  p->mutex_type      = mutex_type;
   p->recursion_count = 0;
   p->owner           = DRD_INVALID_THREADID;
   vc_init(&p->vc, 0, 0);
 }
 
 static
-struct mutex_info* mutex_get_or_allocate(const Addr mutex, const SizeT size)
+struct mutex_info*
+mutex_get_or_allocate(const Addr mutex,
+                      const SizeT size,
+                      const MutexT mutex_type)
 {
   int i;
+
+  tl_assert(mutex_type == mutex_type_mutex
+            || mutex_type == mutex_type_spinlock);
+
   for (i = 0; i < sizeof(s_mutex)/sizeof(s_mutex[0]); i++)
+  {
     if (s_mutex[i].mutex == mutex)
+    {
+      tl_assert(s_mutex[i].mutex_type == mutex_type);
+      tl_assert(s_mutex[i].size == size);
       return &s_mutex[i];
+    }
+  }
   for (i = 0; i < sizeof(s_mutex)/sizeof(s_mutex[0]); i++)
   {
     if (s_mutex[i].mutex == 0)
     {
-      mutex_initialize(&s_mutex[i], mutex, size);
+      mutex_initialize(&s_mutex[i], mutex, size, mutex_type);
       drd_start_suppression(mutex, mutex + size,
                             mutex_get_typename(&s_mutex[i]));
       return &s_mutex[i];
@@ -97,12 +115,15 @@
   return 0;
 }
 
-struct mutex_info* mutex_init(const Addr mutex, const SizeT size)
+struct mutex_info*
+mutex_init(const Addr mutex, const SizeT size, const MutexT mutex_type)
 {
   struct mutex_info* mutex_p;
 
   tl_assert(mutex_get(mutex) == 0);
-  mutex_p = mutex_get_or_allocate(mutex, size);
+  tl_assert(mutex_type == mutex_type_mutex
+            || mutex_type == mutex_type_spinlock);
+  mutex_p = mutex_get_or_allocate(mutex, size, mutex_type);
 
   if (s_trace_mutex)
   {
@@ -151,10 +172,10 @@
  * Note: this function must be called after pthread_mutex_lock() has been
  * called, or a race condition is triggered !
  */
-int mutex_lock(const Addr mutex, const SizeT size)
+int mutex_lock(const Addr mutex, const SizeT size, MutexT mutex_type)
 {
   const DrdThreadId drd_tid = VgThreadIdToDrdThreadId(VG_(get_running_tid)());
-  struct mutex_info* const p = mutex_get_or_allocate(mutex, size);
+  struct mutex_info* const p = mutex_get_or_allocate(mutex, size, mutex_type);
   const DrdThreadId last_owner = p->owner;
 
   if (s_trace_mutex)
@@ -170,7 +191,12 @@
                  p ? p->owner : VG_INVALID_THREADID);
   }
 
-  if (p->recursion_count >= 1 && p->size == PTHREAD_SPINLOCK_SIZE)
+  tl_assert(mutex_type == mutex_type_mutex
+            || mutex_type == mutex_type_spinlock);
+  tl_assert(p->mutex_type == mutex_type);
+  tl_assert(p->size == size);
+
+  if (p->recursion_count >= 1 && mutex_type == mutex_type_spinlock)
   {
     // TO DO: tell the user in a more friendly way that it is not allowed to
     // lock spinlocks recursively.
@@ -211,7 +237,7 @@
  * @param tid ThreadId of the thread calling pthread_mutex_unlock().
  * @param vc Pointer to the current vector clock of thread tid.
  */
-int mutex_unlock(const Addr mutex)
+int mutex_unlock(const Addr mutex, const MutexT mutex_type)
 {
   const DrdThreadId drd_tid = VgThreadIdToDrdThreadId(VG_(get_running_tid)());
   const ThreadId vg_tid = DrdThreadIdToVgThreadId(drd_tid);
@@ -230,7 +256,11 @@
   }
 
   tl_assert(p);
+  tl_assert(p->mutex_type == mutex_type);
   tl_assert(p->owner != DRD_INVALID_THREADID);
+  tl_assert(mutex_type == mutex_type_mutex
+            || mutex_type == mutex_type_spinlock);
+
   if (p->owner != drd_tid)
   {
     MutexErrInfo MEI = { p->mutex, p->recursion_count, p->owner };
@@ -257,11 +287,12 @@
 const char* mutex_get_typename(struct mutex_info* const p)
 {
   tl_assert(p);
-  switch (p->size)
+
+  switch (p->mutex_type)
   {
-  case PTHREAD_MUTEX_SIZE:
+  case mutex_type_mutex:
     return "mutex";
-  case PTHREAD_SPINLOCK_SIZE:
+  case mutex_type_spinlock:
     return "spinlock";
   default:
     tl_assert(0);

Modified: trunk/exp-drd/drd_mutex.h
===================================================================
--- trunk/exp-drd/drd_mutex.h   2007-11-29 13:04:03 UTC (rev 7251)
+++ trunk/exp-drd/drd_mutex.h   2007-11-30 08:30:29 UTC (rev 7252)
@@ -30,20 +30,22 @@
 #define __MUTEX_H
 
 
+#include "drd_clientreq.h"        // MutexT
+#include "drd_thread.h"           // DrdThreadId
+#include "drd_vc.h"
 #include "pub_tool_basics.h"      // Addr, SizeT
-#include "drd_vc.h"
-#include "drd_thread.h"           // DrdThreadId
 
 
 struct mutex_info;
 
 
 void mutex_set_trace(const Bool trace_mutex);
-struct mutex_info* mutex_init(const Addr mutex, const SizeT size);
+struct mutex_info* mutex_init(const Addr mutex, const SizeT size,
+                              const MutexT mutex_type);
 void mutex_destroy(struct mutex_info* const p);
 struct mutex_info* mutex_get(const Addr mutex);
-int mutex_lock(const Addr mutex, const SizeT size);
-int mutex_unlock(const Addr mutex);
+int mutex_lock(const Addr mutex, const SizeT size, const MutexT mutex_type);
+int mutex_unlock(const Addr mutex, const MutexT mutex_type);
 const char* mutex_get_typename(struct mutex_info* const p);
 Bool mutex_is_locked_by(const Addr mutex, const DrdThreadId tid);
 const VectorClock* mutex_get_last_vc(const Addr mutex);

Modified: trunk/exp-drd/drd_preloaded.c
===================================================================
--- trunk/exp-drd/drd_preloaded.c       2007-11-29 13:04:03 UTC (rev 7251)
+++ trunk/exp-drd/drd_preloaded.c       2007-11-30 08:30:29 UTC (rev 7252)
@@ -56,7 +56,6 @@
 #include "pub_core_debuginfo.h"  // Needed for pub_core_redir.h
 #include "pub_core_redir.h"      // For VG_NOTIFY_ON_LOAD
 #include "pub_tool_threadstate.h"// VG_N_THREADS
-#include "pthread_object_size.h" // PTHREAD_MUTEX_SIZE etc.
 
 
 // Defines.
@@ -165,10 +164,6 @@
    VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__DRD_SUPPRESS_CURRENT_STACK,
                               0, 0, 0, 0, 0);
 
-   // Sanity checks.
-   assert(sizeof(pthread_mutex_t)    == PTHREAD_MUTEX_SIZE);
-   assert(sizeof(pthread_spinlock_t) == PTHREAD_SPINLOCK_SIZE);
-
    // 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);
@@ -281,7 +276,7 @@
    OrigFn fn;
    VALGRIND_GET_ORIG_FN(fn);
    VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_MUTEX_INIT,
-                              mutex, sizeof(*mutex), 0, 0, 0);
+                              mutex, sizeof(*mutex), mutex_type_mutex, 0, 0);
    CALL_FN_W_WW(ret, fn, mutex, attr);
    return ret;
 }
@@ -296,7 +291,7 @@
    VALGRIND_GET_ORIG_FN(fn);
    CALL_FN_W_W(ret, fn, mutex);
    VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_DESTROY,
-                              mutex, sizeof(*mutex), 0, 0, 0);
+                              mutex, mutex_type_mutex, 0, 0, 0);
    return ret;
 }
 
@@ -309,7 +304,7 @@
    OrigFn fn;
    VALGRIND_GET_ORIG_FN(fn);
    VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__PRE_PTHREAD_MUTEX_LOCK,
-                              mutex, sizeof(*mutex), 0, 0, 0);
+                              mutex, sizeof(*mutex), mutex_type_mutex, 0, 0);
 #if 1
    // The only purpose of the system call below is to make drd work on AMD64
    // systems. Without this system call, clients crash (SIGSEGV) in
@@ -319,7 +314,7 @@
    CALL_FN_W_W(ret, fn, mutex);
    if (ret == 0)
       VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__POST_PTHREAD_MUTEX_LOCK,
-                                 mutex, sizeof(*mutex), 0, 0, 0);
+                                mutex, sizeof(*mutex), mutex_type_mutex, 0, 0);
    return ret;
 }
 
@@ -335,7 +330,7 @@
    if (ret == 0)
    {
       VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_PTHREAD_MUTEX_LOCK,
-                                 mutex, sizeof(*mutex), 0, 0, 0);
+                                mutex, sizeof(*mutex), mutex_type_mutex, 0, 0);
    }
    return ret;
 }
@@ -350,7 +345,7 @@
    VALGRIND_GET_ORIG_FN(fn);
    VALGRIND_DO_CLIENT_REQUEST(res, -1,
                               VG_USERREQ__PRE_PTHREAD_MUTEX_UNLOCK,
-                              mutex, sizeof(*mutex), 0, 0, 0);
+                              mutex, sizeof(*mutex), mutex_type_mutex, 0, 0);
    CALL_FN_W_W(ret, fn, mutex);
    return ret;
 }
@@ -379,7 +374,7 @@
    OrigFn fn;
    VALGRIND_GET_ORIG_FN(fn);
    VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_PTHREAD_COND_DESTROY,
-                              cond, sizeof(*cond), 0, 0, 0);
+                              cond, 0, 0, 0, 0);
    CALL_FN_W_W(ret, fn, cond);
    return ret;
 }
@@ -394,10 +389,10 @@
    OrigFn fn;
    VALGRIND_GET_ORIG_FN(fn);
    VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_PTHREAD_COND_WAIT,
-                              cond, mutex, 0, 0, 0);
+                              cond, sizeof(*cond), mutex, sizeof(*mutex), 0);
    CALL_FN_W_WW(ret, fn, cond, mutex);
    VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_PTHREAD_COND_WAIT,
-                              cond, mutex, 0, 0, 0);
+                              cond, sizeof(*cond), mutex, sizeof(*mutex), 0);
    return ret;
 }
 
@@ -412,10 +407,10 @@
    OrigFn fn;
    VALGRIND_GET_ORIG_FN(fn);
    VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__PRE_PTHREAD_COND_WAIT,
-                              cond, mutex, 0, 0, 0);
+                              cond, sizeof(*cond), mutex, sizeof(*mutex), 0);
    CALL_FN_W_WWW(ret, fn, cond, mutex, abstime);
    VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_PTHREAD_COND_WAIT,
-                              cond, mutex, 0, 0, 0);
+                              cond, sizeof(*cond), mutex, sizeof(*mutex), 0);
    return ret;
 }
 
@@ -458,7 +453,8 @@
    OrigFn fn;
    VALGRIND_GET_ORIG_FN(fn);
    VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SPIN_INIT_OR_UNLOCK,
-                              spinlock, sizeof(*spinlock), 0, 0, 0);
+                              spinlock, sizeof(*spinlock),
+                              mutex_type_spinlock, 0, 0);
    CALL_FN_W_WW(ret, fn, spinlock, pshared);
    return ret;
 }
@@ -473,7 +469,7 @@
    VALGRIND_GET_ORIG_FN(fn);
    CALL_FN_W_W(ret, fn, spinlock);
    VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_DESTROY,
-                              spinlock, sizeof(*spinlock), 0, 0, 0);
+                              spinlock, mutex_type_spinlock, 0, 0, 0);
    return ret;
 }
 
@@ -489,7 +485,8 @@
    if (ret == 0)
    {
       VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_PTHREAD_MUTEX_LOCK,
-                                 spinlock, sizeof(*spinlock), 0, 0, 0);
+                                 spinlock, sizeof(*spinlock),
+                                 mutex_type_spinlock, 0, 0);
    }
    return ret;
 }
@@ -506,7 +503,8 @@
    if (ret == 0)
    {
       VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_PTHREAD_MUTEX_LOCK,
-                                 spinlock, sizeof(*spinlock), 0, 0, 0);
+                                 spinlock, sizeof(*spinlock),
+                                 mutex_type_spinlock, 0, 0);
    }
    return ret;
 }
@@ -520,7 +518,8 @@
    OrigFn fn;
    VALGRIND_GET_ORIG_FN(fn);
    VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__SPIN_INIT_OR_UNLOCK,
-                              spinlock, sizeof(*spinlock), 0, 0, 0);
+                              spinlock, sizeof(*spinlock),
+                              mutex_type_spinlock, 0, 0);
    CALL_FN_W_W(ret, fn, spinlock);
    return ret;
 }

Modified: trunk/exp-drd/drd_thread.c
===================================================================
--- trunk/exp-drd/drd_thread.c  2007-11-29 13:04:03 UTC (rev 7251)
+++ trunk/exp-drd/drd_thread.c  2007-11-30 08:30:29 UTC (rev 7252)
@@ -27,7 +27,6 @@
 #include "drd_segment.h"
 #include "drd_suppression.h"
 #include "drd_thread.h"
-#include "pthread_object_size.h"
 #include "pub_core_options.h"     // VG_(clo_backtrace_size)
 #include "pub_tool_basics.h"      // Addr, SizeT
 #include "pub_tool_errormgr.h"    // VG_(unique_error)()

Modified: trunk/exp-drd/drd_track.h
===================================================================
--- trunk/exp-drd/drd_track.h   2007-11-29 13:04:03 UTC (rev 7251)
+++ trunk/exp-drd/drd_track.h   2007-11-30 08:30:29 UTC (rev 7252)
@@ -1,8 +1,11 @@
 void drd_post_thread_join(DrdThreadId joiner, DrdThreadId joinee);
-void drd_pre_mutex_init(Addr mutex, SizeT size);
-void drd_post_mutex_destroy(Addr mutex, SizeT size);
-void drd_pre_mutex_lock(DrdThreadId tid, Addr mutex, const SizeT size);
-void drd_post_mutex_lock(DrdThreadId tid, Addr mutex, const SizeT size);
-void drd_pre_mutex_unlock(DrdThreadId tid, Addr mutex);
+void drd_pre_mutex_init(Addr mutex, SizeT size, const MutexT mutex_type);
+void drd_post_mutex_destroy(Addr mutex, const MutexT mutex_type);
+void drd_pre_mutex_lock(DrdThreadId tid, Addr mutex, const SizeT size,
+                        const MutexT mutex_type);
+void drd_post_mutex_lock(DrdThreadId tid, Addr mutex, const SizeT size,
+                         const MutexT mutex_type);
+void drd_pre_mutex_unlock(const DrdThreadId tid, const Addr mutex,
+                          const MutexT mutex_type);
 void drd_post_cond_init(Addr cond, SizeT s);
-void drd_pre_cond_destroy(Addr cond, SizeT s);
+void drd_pre_cond_destroy(Addr cond);

Added: trunk/exp-drd/priv_drd_clientreq.h
===================================================================
--- trunk/exp-drd/priv_drd_clientreq.h                          (rev 0)
+++ trunk/exp-drd/priv_drd_clientreq.h  2007-11-30 08:30:29 UTC (rev 7252)
@@ -0,0 +1,30 @@
+/*
+  This file is part of drd, a data race detector.
+
+  Copyright (C) 2006-2007 Bart Van Assche
+  [EMAIL PROTECTED]
+
+  This program is free software; you can redistribute it and/or
+  modify it under the terms of the GNU General Public License as
+  published by the Free Software Foundation; either version 2 of the
+  License, or (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+  02111-1307, USA.
+
+  The GNU General Public License is contained in the file COPYING.
+*/
+
+#ifndef __PRIV_DRD_CLIENTREQ_H
+#define __PRIV_DRD_CLIENTREQ_H
+
+void drd_clientreq_init(void);
+
+#endif /* __PRIV_DRD_CLIENTREQ_H */

Deleted: trunk/exp-drd/pthread_object_size.h
===================================================================
--- trunk/exp-drd/pthread_object_size.h 2007-11-29 13:04:03 UTC (rev 7251)
+++ trunk/exp-drd/pthread_object_size.h 2007-11-30 08:30:29 UTC (rev 7252)
@@ -1,15 +0,0 @@
-// TO DO: replace the constants below by macro's #define'd during the configure
-// phase.
-
-#if defined(VGP_x86_linux)
-# define PTHREAD_MUTEX_SIZE    24
-# define PTHREAD_COND_SIZE     48
-#elif defined(VGP_amd64_linux)
-# define PTHREAD_MUTEX_SIZE    40
-# define PTHREAD_COND_SIZE     48
-#else
-  /* FIXME: fill these fields in correctly.  32 is arbitrary. */
-# define PTHREAD_MUTEX_SIZE    32
-# define PTHREAD_COND_SIZE     32
-#endif
-#define PTHREAD_SPINLOCK_SIZE  4

Modified: trunk/exp-drd/tests/Makefile.am
===================================================================
--- trunk/exp-drd/tests/Makefile.am     2007-11-29 13:04:03 UTC (rev 7251)
+++ trunk/exp-drd/tests/Makefile.am     2007-11-30 08:30:29 UTC (rev 7252)
@@ -57,4 +57,4 @@
 pth_detached_LDADD    = -lpthread
 
 sigalrm_SOURCES       = sigalrm.c
-sigalrm_LDADD         = -lpthread -lrt
+sigalrm_LDADD         = -lpthread


-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Valgrind-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/valgrind-developers

Reply via email to