Skip to content

Commit

Permalink
Spawn a new thread for cmd-idle rather than relying on problematic pt…
Browse files Browse the repository at this point in the history
…hread timedwait

pthreads-win32 uses GetSystemTimeAsFileTime for *_timedwait (UTC) and has no clock_* at all
winpthreads (mingw-w64) uses _ftime for *_timedwait (local time) and GetSystemTimeAsFileTime for clock_*
  • Loading branch information
luke-jr committed Sep 9, 2014
1 parent f6a673a commit 07aa023
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions miner.c
Original file line number Diff line number Diff line change
Expand Up @@ -8554,10 +8554,26 @@ static void pool_resus(struct pool *pool)
applog(LOG_INFO, "Pool %d %s alive", pool->pool_no, pool->rpc_url);
}

static
void *cmd_idle_thread(void * const __maybe_unused userp)
{
pthread_detach(pthread_self());
RenameThread("cmd-idle");
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);

sleep(opt_log_interval);
pthread_testcancel();
run_cmd(cmd_idle);

return NULL;
}

static struct work *hash_pop(void)
{
struct work *work = NULL, *tmp;
int hc;
bool did_cmd_idle = false;
pthread_t cmd_idle_thr;

retry:
mutex_lock(stgd_lock);
Expand All @@ -8576,14 +8592,16 @@ static struct work *hash_pop(void)
no_work = true;
}
pthread_cond_signal(&gws_cond);
const struct timeval tv = { .tv_sec = opt_log_interval, };
if (ETIMEDOUT == bfg_cond_timedwait(&getq->cond, stgd_lock, &tv))

if (cmd_idle && !did_cmd_idle)
{
run_cmd(cmd_idle);
pthread_cond_signal(&gws_cond);
pthread_cond_wait(&getq->cond, stgd_lock);
if (likely(!pthread_create(&cmd_idle_thr, NULL, cmd_idle_thread, NULL)))
did_cmd_idle = true;
}
pthread_cond_wait(&getq->cond, stgd_lock);
}
if (did_cmd_idle)
pthread_cancel(cmd_idle_thr);

no_work = false;

Expand Down

0 comments on commit 07aa023

Please sign in to comment.