Skip to content

Commit

Permalink
Use mutex to wait for asynchronous processing to complete
Browse files Browse the repository at this point in the history
  • Loading branch information
Watson1978 committed Feb 10, 2024
1 parent e079d17 commit 2007284
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions ext/ilios/future.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,16 +303,18 @@ static VALUE future_await(VALUE self)

GET_FUTURE(self, cassandra_future);

rb_mutex_lock(cassandra_future->proc_mutex);
if (cassandra_future->already_waited) {
rb_mutex_unlock(cassandra_future->proc_mutex);
return self;
}
cassandra_future->already_waited = true;
rb_mutex_unlock(cassandra_future->proc_mutex);

nogvl_future_wait(cassandra_future->future);
if (cassandra_future->on_success_block || cassandra_future->on_failure_block) {
nogvl_sem_wait(&cassandra_future->sem);
} else {
nogvl_future_wait(cassandra_future->future);
}
cassandra_future->already_waited = true;
return self;
}

Expand Down

0 comments on commit 2007284

Please sign in to comment.