diff --git a/maestro/i_event.h b/maestro/i_event.h index 9cd8814297b5e27504540b72fcdfefefe58a79c0..1d4203209cd7c5563e3f49f43e60fcb44d5b3eec 100644 --- a/maestro/i_event.h +++ b/maestro/i_event.h @@ -53,6 +53,7 @@ #include <stdatomic.h> #include <stdint.h> #include <pthread.h> +#include <errno.h> /* how much (in sec) are we willing to wait for generic table to be cleared */ @@ -60,6 +61,7 @@ /** Generic timed wait on hash table proper cleanup **/ +/* this should really be a function, not a macro, but HTABLE_COUNT does not take generic args */ #define mstro_cleanup_waitup(retstat,htable,lock,cond,reason) { \ retstat = MSTRO_OK; \ do { \ @@ -78,16 +80,23 @@ } \ \ unsigned rem_ = HASH_COUNT(htable); \ - if(!rem_) { \ + if(rem_==0) { \ INFO("All items in `%s` already completed cleanly\n", reason); \ } else { \ - INFO("In `%s`, %d item(s) still pending, waiting up to %d sec\n", \ + INFO("In `%s`, %d item(s) still pending, waiting up to %d sec\n",\ reason, rem_, MSTRO_TIMED_WAIT); \ - while (HASH_COUNT(htable) && !rc_) \ - rc_ = pthread_cond_timedwait(cond, lock, &ts); \ + do { \ + rc_ = pthread_cond_timedwait(cond, lock, &ts); \ + } while (!rc_ && HASH_COUNT(htable)>0 ); \ + \ if(rc_!=0) { \ - ERR("Failed to perform timedwait: %d (%s)\n", \ - rc_, strerror(rc_)); \ + if(rc_==ETIMEDOUT) { \ + ERR("Waited %zu seconds without change to table\n", \ + (uint64_t)MSTRO_TIMED_WAIT); \ + } else { \ + ERR("Failed to perform timedwait: %d (%s)\n", \ + rc_, strerror(rc_)); \ + } \ retstat = MSTRO_FAIL; \ break; \ } \