Increase the number of queues for work to reside. Worker threads, once started, don't exit until shutdown.
This commit is contained in:
parent
1623d5293c
commit
4418a74183
1 changed files with 6 additions and 3 deletions
|
@ -393,13 +393,15 @@ async_nif_worker_fn(void *arg)
|
||||||
/* Queue is empty so we wait for more work to arrive. */
|
/* Queue is empty so we wait for more work to arrive. */
|
||||||
if (q->num_workers > ASYNC_NIF_MIN_WORKERS) {
|
if (q->num_workers > ASYNC_NIF_MIN_WORKERS) {
|
||||||
enif_mutex_unlock(q->reqs_mutex);
|
enif_mutex_unlock(q->reqs_mutex);
|
||||||
if (tries == 0 && q == we->q) break; // we've tried all queues, thread exit
|
if (tries == 0 && q == we->q) {
|
||||||
else {
|
tries = async_nif->num_queues;
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
tries--;
|
tries--;
|
||||||
__sync_fetch_and_add(&q->num_workers, -1);
|
__sync_fetch_and_add(&q->num_workers, -1);
|
||||||
q = q->next;
|
q = q->next;
|
||||||
__sync_fetch_and_add(&q->num_workers, 1);
|
__sync_fetch_and_add(&q->num_workers, 1);
|
||||||
continue; // try another queue
|
continue; // try next queue
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
enif_cond_wait(q->reqs_cnd, q->reqs_mutex);
|
enif_cond_wait(q->reqs_cnd, q->reqs_mutex);
|
||||||
|
@ -554,6 +556,7 @@ async_nif_load()
|
||||||
if (num_queues < 2)
|
if (num_queues < 2)
|
||||||
num_queues = 2;
|
num_queues = 2;
|
||||||
}
|
}
|
||||||
|
num_queues *= 32;
|
||||||
|
|
||||||
/* Init our portion of priv_data's module-specific state. */
|
/* Init our portion of priv_data's module-specific state. */
|
||||||
async_nif = enif_alloc(sizeof(struct async_nif_state) +
|
async_nif = enif_alloc(sizeof(struct async_nif_state) +
|
||||||
|
|
Loading…
Reference in a new issue