Simply and rationalise pthread_mutex implementation, in preparation
for implementation of condition variables.

* Use the native pthread_mutex_t directly; we no longer have our own
  VgMutex type nor a fixed array of them.

* Give ThreadState a new field q_next :: ThreadId, used to make a
  linked list of threads waiting on a mutex, or condition variable.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@99 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/vg_include.h b/vg_include.h
index c9be884..5cf1489 100644
--- a/vg_include.h
+++ b/vg_include.h
@@ -126,7 +126,7 @@
    scheduler algorithms is surely O(N^2) in the number of threads,
    since that's simple, at least.  And (in practice) we hope that most
    programs do not need many threads. */
-#define VG_N_THREADS 20
+#define VG_N_THREADS 10
 
 /* Number of file descriptors that can simultaneously be waited on for
    I/O to complete.  Perhaps this should be the same as VG_N_THREADS
@@ -134,9 +134,6 @@
    knows.) */
 #define VG_N_WAITING_FDS 10
 
-/* Maximum number of mutexes allowed. */
-#define VG_N_MUTEXES 30
-
 
 /* ---------------------------------------------------------------------
    Basic types
@@ -400,10 +397,8 @@
 #define VG_USERREQ__PTHREAD_CREATE          0x3001
 #define VG_USERREQ__PTHREAD_JOIN            0x3002
 #define VG_USERREQ__PTHREAD_GET_THREADID    0x3003
-#define VG_USERREQ__PTHREAD_MUTEX_INIT      0x3004
 #define VG_USERREQ__PTHREAD_MUTEX_LOCK      0x3005
 #define VG_USERREQ__PTHREAD_MUTEX_UNLOCK    0x3006
-#define VG_USERREQ__PTHREAD_MUTEX_DESTROY   0x3007
 #define VG_USERREQ__PTHREAD_CANCEL          0x3008
 
 /* Cosmetic ... */
@@ -437,11 +432,6 @@
    UInt 
    ThreadId;
 
-/* MutexIds are simply indices into the vg_mutexes[] array. */
-typedef
-   UInt
-   MutexId;
-
 
 #define VG_INVALID_THREADID ((ThreadId)(-1))
 
@@ -464,7 +454,7 @@
          that we don't try and allocate or deallocate its stack.  For
          convenience of generating error message, we also put the
          ThreadId in this tid field, but be aware that it should
-         ALWAYS just == the index in vg_threads[]. */
+         ALWAYS == the index in vg_threads[]. */
       ThreadId tid;
 
       /* Current scheduling status. */
@@ -474,8 +464,10 @@
          VG_INVALID_THREADID if no one asked to join yet. */
       ThreadId joiner;
 
-      /* Identity of mutex we are waiting on, if .status == WaitMX. */
-      MutexId waited_on_mid;
+      /* Link to the next member of the queue of threads waiting on
+         the same mutex or condition variable.  Only meaningful if
+         .status == WaitMX or WaitCV. */
+      ThreadId q_next;
 
       /* If VgTs_Sleeping, this is when we should wake up. */
       ULong awaken_at;