Skip to content

Commit

Permalink
Clean up timing statistics on thread shutdown.
Browse files Browse the repository at this point in the history
  • Loading branch information
samr7 committed Jul 1, 2012
1 parent a439896 commit 217351c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
1 change: 1 addition & 0 deletions oclengine.c
Original file line number Diff line number Diff line change
Expand Up @@ -2189,6 +2189,7 @@ vg_opencl_loop(void *arg)
vg_ocl_free_args(vocp);
vocp->voc_halt = 0;
vocp->voc_ocl_slot = -1;
vg_context_thread_exit(vcp);
return NULL;
}

Expand Down
31 changes: 26 additions & 5 deletions pattern.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions vanitygen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit 217351c

Please sign in to comment.