Skip to content

Commit

Permalink
Switch gc_intrays_clearing to use condvar.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Jul 25, 2017
1 parent 4d0a9d1 commit 54fb63c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/core/instance.h
Expand Up @@ -162,13 +162,13 @@ struct MVMInstance {
AO_t gc_finish;
uv_cond_t cond_gc_finish;

/* Whether the coordinator considers all in-trays clear. */
/* Whether the coordinator considers all in-trays clear, and condition
* variable for when it changes. */
AO_t gc_intrays_clearing;
uv_cond_t cond_gc_intrays_clearing;

/* The number of threads that have yet to acknowledge the finish, and
* condition variable for when it changes. */
/* The number of threads that have yet to acknowledge the finish. */
AO_t gc_ack;
uv_cond_t cond_gc_ack;

/* Linked list (via forwarder) of STables to free. */
MVMSTable *stables_to_free;
Expand Down
8 changes: 6 additions & 2 deletions src/gc/orchestrate.c
Expand Up @@ -180,14 +180,18 @@ static void finish_gc(MVMThreadContext *tc, MVMuint8 gen, MVMuint8 is_coordinato

GCDEBUG_LOG(tc, MVM_GC_DEBUG_ORCHESTRATE,
"Thread %d run %d : Co-ordinator signalling in-trays clear\n");
uv_mutex_lock(&tc->instance->mutex_gc_orchestrate);
MVM_store(&tc->instance->gc_intrays_clearing, 0);
uv_cond_broadcast(&tc->instance->cond_gc_intrays_clearing);
uv_mutex_unlock(&tc->instance->mutex_gc_orchestrate);
}
else {
GCDEBUG_LOG(tc, MVM_GC_DEBUG_ORCHESTRATE,
"Thread %d run %d : Waiting for in-tray clearing completion\n");
uv_mutex_lock(&tc->instance->mutex_gc_orchestrate);
while (MVM_load(&tc->instance->gc_intrays_clearing))
for (i = 0; i < 1000; i++)
; /* XXX Something HT-efficienter. */
uv_cond_wait(&tc->instance->cond_gc_intrays_clearing, &tc->instance->mutex_gc_orchestrate);
uv_mutex_unlock(&tc->instance->mutex_gc_orchestrate);
GCDEBUG_LOG(tc, MVM_GC_DEBUG_ORCHESTRATE,
"Thread %d run %d : Got in-tray clearing complete notice\n");
}
Expand Down
4 changes: 2 additions & 2 deletions src/moar.c
Expand Up @@ -100,7 +100,7 @@ MVMInstance * MVM_vm_create_instance(void) {
init_mutex(instance->mutex_gc_orchestrate, "GC orchestration");
init_cond(instance->cond_gc_start, "GC start");
init_cond(instance->cond_gc_finish, "GC finish");
init_cond(instance->cond_gc_ack, "GC ack");
init_cond(instance->cond_gc_intrays_clearing, "GC intrays clearing");

/* Create fixed size allocator. */
instance->fsa = MVM_fixed_size_create(instance->main_thread);
Expand Down Expand Up @@ -442,7 +442,7 @@ void MVM_vm_destroy_instance(MVMInstance *instance) {
MVM_free(instance->permroot_descriptions);
uv_cond_destroy(&instance->cond_gc_start);
uv_cond_destroy(&instance->cond_gc_finish);
uv_cond_destroy(&instance->cond_gc_ack);
uv_cond_destroy(&instance->cond_gc_intrays_clearing);
uv_mutex_destroy(&instance->mutex_gc_orchestrate);

/* Clean up Hash of HLLConfig. */
Expand Down

0 comments on commit 54fb63c

Please sign in to comment.