Added reference counting to segments. Synchronization objects (mutex, semaphore, barrier, rwlock) now keep a pointer to a segment instead of copying a vector clock for modeling causal relationships.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@7727 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/exp-drd/drd_semaphore.c b/exp-drd/drd_semaphore.c
index 607abe9..d9c818f 100644
--- a/exp-drd/drd_semaphore.c
+++ b/exp-drd/drd_semaphore.c
@@ -64,7 +64,7 @@
   p->value     = value;
   p->waiters   = 0;
   p->last_sem_post_tid = DRD_INVALID_THREADID;
-  vc_init(&p->vc, 0, 0);
+  p->last_sem_post_segment = 0;
 }
 
 /** Free the memory that was allocated by semaphore_initialize(). Called by
@@ -82,7 +82,7 @@
                             " upon",
                             &sei);
   }
-  vc_cleanup(&p->vc);
+  sg_put(p->last_sem_post_segment);
 }
 
 static
@@ -215,8 +215,12 @@
   }
   p->value--;
   tl_assert(p->value >= 0);
-  if (p->last_sem_post_tid != tid)
-    thread_combine_vc2(tid, &p->vc);
+  if (p->last_sem_post_tid != tid
+      && p->last_sem_post_tid != DRD_INVALID_THREADID)
+  {
+    tl_assert(p->last_sem_post_segment);
+    thread_combine_vc2(tid, &p->last_sem_post_segment->vc);
+  }
   thread_new_segment(tid);
 }
 
@@ -239,7 +243,7 @@
   {
     p->last_sem_post_tid = tid;
     thread_new_segment(tid);
-    vc_assign(&p->vc, thread_get_vc(tid));
+    thread_get_latest_segment(&p->last_sem_post_segment, tid);
   }
 }