Skip to content
Snippets Groups Projects
Commit 6de558f9 authored by Tim Emiola's avatar Tim Emiola
Browse files

Exposes the implementation of CompletionQueue#pluck

- allows it to be used from other files, e.g, in Call#run_batch
- this keeps code related to releasing the GIL during #pluck in one place
parent 6b493a33
No related branches found
No related tags found
No related merge requests found
......@@ -140,8 +140,19 @@ static VALUE grpc_rb_completion_queue_next(VALUE self, VALUE timeout) {
/* Blocks until the next event for given tag is available, and returns the
* event. */
static VALUE grpc_rb_completion_queue_pluck(VALUE self, VALUE tag,
VALUE timeout) {
VALUE grpc_rb_completion_queue_pluck(VALUE self, VALUE tag,
VALUE timeout) {
grpc_event *ev = grpc_rb_completion_queue_pluck_event(self, tag, timeout);
if (ev == NULL) {
return Qnil;
}
return grpc_rb_new_event(ev);
}
/* Blocks until the next event for given tag is available, and returns the
* event. */
grpc_event* grpc_rb_completion_queue_pluck_event(VALUE self, VALUE tag,
VALUE timeout) {
next_call_stack next_call;
MEMZERO(&next_call, next_call_stack, 1);
Data_Get_Struct(self, grpc_completion_queue, next_call.cq);
......@@ -151,9 +162,9 @@ static VALUE grpc_rb_completion_queue_pluck(VALUE self, VALUE tag,
rb_thread_call_without_gvl(grpc_rb_completion_queue_pluck_no_gil,
(void *)&next_call, NULL, NULL);
if (next_call.event == NULL) {
return Qnil;
return NULL;
}
return grpc_rb_new_event(next_call.event);
return next_call.event;
}
/* rb_cCompletionQueue is the ruby class that proxies grpc_completion_queue. */
......
......@@ -40,6 +40,14 @@
/* Gets the wrapped completion queue from the ruby wrapper */
grpc_completion_queue *grpc_rb_get_wrapped_completion_queue(VALUE v);
/**
* Makes the implementation of CompletionQueue#pluck available in other files
*
* This avoids having code that holds the GIL repeated at multiple sites.
*/
grpc_event* grpc_rb_completion_queue_pluck_event(VALUE cqueue, VALUE tag,
VALUE timeout);
/* rb_cCompletionQueue is the CompletionQueue class whose instances proxy
grpc_completion_queue. */
extern VALUE rb_cCompletionQueue;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment