From 3598e2d17837e480869e472e224140ad2643c58c Mon Sep 17 00:00:00 2001 From: J08nY Date: Mon, 10 Apr 2017 00:19:15 +0200 Subject: Moved curve output in multi-threaded invalid curve generation to master thread - Fixed mutex and cond destroy - Added debug() macro - Renamed debug out stream to verbose --- src/invalid/invalid_thread.c | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) (limited to 'src/invalid/invalid_thread.c') diff --git a/src/invalid/invalid_thread.c b/src/invalid/invalid_thread.c index 40b52ec..e43539c 100644 --- a/src/invalid/invalid_thread.c +++ b/src/invalid/invalid_thread.c @@ -31,9 +31,7 @@ void *invalid_thread(void *arg) { ndivides++; } } -#ifdef DEBUG - printf("ndivides = %lu\n", ndivides); -#endif + debug("ndivides = %lu\n", ndivides); if (ndivides > 0) { pthread_mutex_lock(thread->mutex_state); size_t nfree = 0; @@ -48,9 +46,7 @@ void *invalid_thread(void *arg) { nfree++; } } -#ifdef DEBUG - printf("nfree = %lu\n", nfree); -#endif + debug("nfree = %lu\n", nfree); pthread_mutex_unlock(thread->mutex_state); if (nfree > 0) { @@ -59,33 +55,23 @@ void *invalid_thread(void *arg) { exhaustive_gen(invalid, thread->cfg, thread->gens, invalid_argss, OFFSET_GENERATORS, OFFSET_END); - pthread_mutex_lock(thread->mutex_curves); pthread_mutex_lock(thread->mutex_state); size_t count = 0; for (size_t i = thread->nprimes; i-- > 0;) { if (count < nprimes && primes[count] == thread->primes[i]) { -#ifdef DEBUG - printf("[i] = %lu, prime = %lu\n", i, primes[count]); - printf("state = %i\n", thread->states[i]); -#endif + debug("[i] = %lu, prime = %lu\n", i, primes[count]); + debug("state = %i\n", thread->states[i]); thread->states[i] = STATE_GENERATED; thread->curves[i] = curve_new_copy(invalid); - - output_o(thread->curves[i], thread->cfg); count++; } } -#ifdef DEBUG - printf("count = %lu, generated = %lu\n", count, - *(thread->generated)); -#endif + debug("count = %lu, generated = %lu\n", count, + *(thread->generated)); *(thread->generated) += count; -#ifdef DEBUG - printf("generated = %lu\n", *(thread->generated)); -#endif - // pthread_cond_signal(thread->cond_generated); + debug("generated = %lu\n", *(thread->generated)); + pthread_cond_signal(thread->cond_generated); pthread_mutex_unlock(thread->mutex_state); - pthread_mutex_unlock(thread->mutex_curves); invalid = curve_new(); invalid->field = gcopy(thread->original_curve->field); -- cgit v1.2.3-70-g09d2