From: Bart Van Assche Date: Sun, 21 Jun 2009 18:07:35 +0000 (+0000) Subject: Combined DRD_(thread_new_segment)() and DRD_(thread_combine_vc_sync)() X-Git-Tag: svn/VALGRIND_3_5_0~485 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6b937d7d9552cd5503d0950b773de5181fd6211e;p=thirdparty%2Fvalgrind.git 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 --- diff --git a/drd/drd_mutex.c b/drd/drd_mutex.c index 489f65a4cb..536bf4675a 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 bc00fe2573..4cbf56eecb 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 d61ae06686..e88f96340c 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; @@ -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) { diff --git a/drd/drd_thread.h b/drd/drd_thread.h index affbba3ac9..710f905c30 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);