]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Combined DRD_(thread_new_segment)() and DRD_(thread_combine_vc_sync)()
authorBart Van Assche <bvanassche@acm.org>
Sun, 21 Jun 2009 18:07:35 +0000 (18:07 +0000)
committerBart Van Assche <bvanassche@acm.org>
Sun, 21 Jun 2009 18:07:35 +0000 (18:07 +0000)
into the function DRD_(thread_new_segment_and_combine_vc)() because
before DRD_(thread_combine_vc_sync)() was called the function
DRD_(thread_new_segment)() was always called.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@10357

drd/drd_mutex.c
drd/drd_semaphore.c
drd/drd_thread.c
drd/drd_thread.h

index 489f65a4cbfd1e2f0947a5b31aeaf74a7149f88e..536bf4675a8743c4de61844db14fa1e6ebafafb3 100644 (file)
@@ -306,16 +306,17 @@ void DRD_(mutex_post_lock)(const Addr mutex, const Bool took_lock,
 
    if (p->recursion_count == 0)
    {
-      const DrdThreadId last_owner = p->owner;
-
-      DRD_(thread_new_segment)(drd_tid);
-      s_mutex_segment_creation_count++;
-
-      if (last_owner != drd_tid && last_owner != DRD_INVALID_THREADID)
+      if (p->owner != drd_tid && p->owner != DRD_INVALID_THREADID)
       {
          tl_assert(p->last_locked_segment);
-         DRD_(thread_combine_vc_sync)(drd_tid, p->last_locked_segment);
+
+         DRD_(thread_new_segment_and_combine_vc)(drd_tid,
+                                                 p->last_locked_segment);
       }
+      else
+         DRD_(thread_new_segment)(drd_tid);
+
+      s_mutex_segment_creation_count++;
 
       p->owner           = drd_tid;
       p->acquiry_time_ms = VG_(read_millisecond_timer)();
index bc00fe257366bdcca3348df14219884b3c3dd0fc..4cbf56eecbcd258ed33b5a3e6e92c2076a95236e 100644 (file)
@@ -315,14 +315,14 @@ void DRD_(semaphore_post_wait)(const DrdThreadId tid, const Addr semaphore,
       tl_assert(sg);
       if (sg)
       {
-         DRD_(thread_new_segment)(tid);
-         s_semaphore_segment_creation_count++;
-
          if (p->last_sem_post_tid != tid
              && p->last_sem_post_tid != DRD_INVALID_THREADID)
          {
-            DRD_(thread_combine_vc_sync)(tid, sg);
+            DRD_(thread_new_segment_and_combine_vc)(tid, sg);
          }
+         else
+            DRD_(thread_new_segment)(tid);
+         s_semaphore_segment_creation_count++;
          DRD_(sg_put)(sg);
       }
    }
index d61ae066865b457b94004274f848352d7e5244b8..e88f96340c79876b021de307108c1a484b215df2 100644 (file)
@@ -984,7 +984,7 @@ void DRD_(thread_combine_vc_join)(DrdThreadId joiner, DrdThreadId joinee)
 
       DRD_(vc_copy)(&old_vc, &DRD_(g_threadinfo)[joiner].last->vc);
       DRD_(vc_combine)(&DRD_(g_threadinfo)[joiner].last->vc,
-                      &DRD_(g_threadinfo)[joinee].last->vc);
+                       &DRD_(g_threadinfo)[joinee].last->vc);
       DRD_(thread_update_conflict_set)(joiner, &old_vc);
       s_update_conflict_set_join_count++;
       DRD_(vc_cleanup)(&old_vc);
@@ -992,7 +992,7 @@ void DRD_(thread_combine_vc_join)(DrdThreadId joiner, DrdThreadId joinee)
    else
    {
       DRD_(vc_combine)(&DRD_(g_threadinfo)[joiner].last->vc,
-                      &DRD_(g_threadinfo)[joinee].last->vc);
+                       &DRD_(g_threadinfo)[joinee].last->vc);
    }
 
    thread_discard_ordered_segments();
@@ -1008,11 +1008,9 @@ void DRD_(thread_combine_vc_join)(DrdThreadId joiner, DrdThreadId joinee)
 
 /**
  * Update the vector clock of the last segment of thread tid with the
- * the vector clock of segment sg. Call this function after thread tid had
- * to wait because of thread synchronization until the memory accesses in the
- * segment sg finished.
+ * the vector clock of segment sg.
  */
-void DRD_(thread_combine_vc_sync)(DrdThreadId tid, const Segment* sg)
+static void thread_combine_vc_sync(DrdThreadId tid, const Segment* sg)
 {
    const VectorClock* const vc = &sg->vc;
 
@@ -1051,6 +1049,31 @@ void DRD_(thread_combine_vc_sync)(DrdThreadId tid, const Segment* sg)
    }
 }
 
+/**
+ * Create a new segment for thread tid and update the vector clock of the last
+ * segment of this thread with the the vector clock of segment sg. Call this
+ * function after thread tid had to wait because of thread synchronization
+ * until the memory accesses in the segment sg finished.
+ */
+void DRD_(thread_new_segment_and_combine_vc)(DrdThreadId tid, const Segment* sg)
+{
+   tl_assert(0 <= (int)tid && tid < DRD_N_THREADS
+             && tid != DRD_INVALID_THREADID);
+   tl_assert(thread_conflict_set_up_to_date(DRD_(g_drd_running_tid)));
+   tl_assert(sg);
+
+   thread_append_segment(tid, DRD_(sg_new)(tid, tid));
+
+   thread_combine_vc_sync(tid, sg);
+
+   if (s_segment_merging
+       && ++s_new_segments_since_last_merge >= s_segment_merge_interval)
+   {
+      thread_discard_ordered_segments();
+      thread_merge_segments();
+   }
+}
+
 /**
  * Call this function whenever a thread is no longer using the memory
  * [ a1, a2 [, e.g. because of a call to free() or a stack pointer
@@ -1291,9 +1314,13 @@ static void thread_compute_conflict_set(struct bitmap** conflict_set,
 
    if (*conflict_set)
    {
-      DRD_(bm_delete)(*conflict_set);
+      DRD_(bm_cleanup)(*conflict_set);
+      DRD_(bm_init)(*conflict_set);
+   }
+   else
+   {
+      *conflict_set = DRD_(bm_new)();
    }
-   *conflict_set = DRD_(bm_new)();
 
    if (s_trace_conflict_set)
    {
index affbba3ac99f1560f0be3161acfed66c243a8446..710f905c30b94d47c38cf22923b92e23e0e2c418 100644 (file)
@@ -156,7 +156,8 @@ VectorClock* DRD_(thread_get_vc)(const DrdThreadId tid);
 void DRD_(thread_get_latest_segment)(Segment** sg, const DrdThreadId tid);
 void DRD_(thread_combine_vc_join)(const DrdThreadId joiner,
                                   const DrdThreadId joinee);
-void DRD_(thread_combine_vc_sync)(const DrdThreadId tid, const Segment* sg);
+void DRD_(thread_new_segment_and_combine_vc)(DrdThreadId tid,
+                                             const Segment* sg);
 void DRD_(thread_update_conflict_set)(const DrdThreadId tid,
                                       const VectorClock* const old_vc);