aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbart <bart@a5019735-40e9-0310-863c-91ae7b9d1cf9>2009-06-21 18:07:35 +0000
committerbart <bart@a5019735-40e9-0310-863c-91ae7b9d1cf9>2009-06-21 18:07:35 +0000
commitf6ec1fe18f1fc1222fb274d7dfd4343c16048fb1 (patch)
tree61499fef2299ec3404bd614c78d81e6d842ec555
parente5214666ead5aebb79ad662deacff0a952cba70d (diff)
downloadvalgrind-f6ec1fe18f1fc1222fb274d7dfd4343c16048fb1.tar.gz
Combined DRD_(thread_new_segment)() and DRD_(thread_combine_vc_sync)()
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 a5019735-40e9-0310-863c-91ae7b9d1cf9
-rw-r--r--drd/drd_mutex.c15
-rw-r--r--drd/drd_semaphore.c8
-rw-r--r--drd/drd_thread.c43
-rw-r--r--drd/drd_thread.h3
4 files changed, 49 insertions, 20 deletions
diff --git a/drd/drd_mutex.c b/drd/drd_mutex.c
index 489f65a4c..536bf4675 100644
--- a/drd/drd_mutex.c
+++ b/drd/drd_mutex.c
@@ -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)();
diff --git a/drd/drd_semaphore.c b/drd/drd_semaphore.c
index bc00fe257..4cbf56eec 100644
--- a/drd/drd_semaphore.c
+++ b/drd/drd_semaphore.c
@@ -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);
}
}
diff --git a/drd/drd_thread.c b/drd/drd_thread.c
index d61ae0668..e88f96340 100644
--- a/drd/drd_thread.c
+++ b/drd/drd_thread.c
@@ -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;
@@ -1052,6 +1050,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
* increase.
@@ -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)
{
diff --git a/drd/drd_thread.h b/drd/drd_thread.h
index affbba3ac..710f905c3 100644
--- a/drd/drd_thread.h
+++ b/drd/drd_thread.h
@@ -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);