From 217351c30b11a891fbd7b6867b8eac4b35629925 Mon Sep 17 00:00:00 2001 From: samr7 Date: Sun, 1 Jul 2012 16:21:23 -0700 Subject: [PATCH] Clean up timing statistics on thread shutdown. --- oclengine.c | 1 + pattern.c | 31 ++++++++++++++++++++++++++----- pattern.h | 1 + vanitygen.c | 1 + 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/oclengine.c b/oclengine.c index 7dd46ce..4557e2c 100644 --- a/oclengine.c +++ b/oclengine.c @@ -2189,6 +2189,7 @@ l_rekey: vg_ocl_free_args(vocp); vocp->voc_halt = 0; vocp->voc_ocl_slot = -1; + vg_context_thread_exit(vcp); return NULL; } diff --git a/pattern.c b/pattern.c index 384b0ae..d954adc 100644 --- a/pattern.c +++ b/pattern.c @@ -138,11 +138,11 @@ typedef struct _timing_info_s { int ti_hist_last; } timing_info_t; +static pthread_mutex_t timing_mutex = PTHREAD_MUTEX_INITIALIZER; + int vg_output_timing(vg_context_t *vcp, int cycle, struct timeval *last) { - static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; - pthread_t me; struct timeval tvnow, tv; timing_info_t *tip, *mytip; @@ -158,7 +158,7 @@ vg_output_timing(vg_context_t *vcp, int cycle, struct timeval *last) mytime = 1; rate = 0; - pthread_mutex_lock(&mutex); + pthread_mutex_lock(&timing_mutex); me = pthread_self(); for (tip = vcp->vc_timing_head, mytip = NULL; tip != NULL; tip = tip->ti_next) { @@ -207,17 +207,38 @@ vg_output_timing(vg_context_t *vcp, int cycle, struct timeval *last) vcp->vc_timing_sincelast += cycle; if (mytip != vcp->vc_timing_head) { - pthread_mutex_unlock(&mutex); + pthread_mutex_unlock(&timing_mutex); return myrate; } total = vcp->vc_timing_total; sincelast = vcp->vc_timing_sincelast; - pthread_mutex_unlock(&mutex); + pthread_mutex_unlock(&timing_mutex); vcp->vc_output_timing(vcp, sincelast, rate, total); return myrate; } +void +vg_context_thread_exit(vg_context_t *vcp) +{ + timing_info_t *tip, **ptip; + pthread_t me; + + pthread_mutex_lock(&timing_mutex); + me = pthread_self(); + for (ptip = &vcp->vc_timing_head, tip = *ptip; + tip != NULL; + ptip = &tip->ti_next, tip = *ptip) { + if (!pthread_equal(tip->ti_thread, me)) + continue; + *ptip = tip->ti_next; + free(tip); + break; + } + pthread_mutex_unlock(&timing_mutex); + +} + static void vg_timing_info_free(vg_context_t *vcp) { diff --git a/pattern.h b/pattern.h index a775937..da1e34e 100644 --- a/pattern.h +++ b/pattern.h @@ -122,6 +122,7 @@ extern int vg_context_add_patterns(vg_context_t *vcp, const char ** const patterns, int npatterns); extern void vg_context_clear_all_patterns(vg_context_t *vcp); extern int vg_context_hash160_sort(vg_context_t *vcp, void *buf); +extern void vg_context_thread_exit(vg_context_t *vcp); extern vg_context_t *vg_prefix_context_new(int addrtype, int privtype, diff --git a/vanitygen.c b/vanitygen.c index e368729..a8c79b9 100644 --- a/vanitygen.c +++ b/vanitygen.c @@ -392,6 +392,7 @@ vg_thread_loop(void *arg) out: vg_thread_context_del(&ctx); + vg_context_thread_exit(vcp); for (i = 0; i < ptarraysize; i++) if (ppnt[i])