diff --git a/src/ruby/ext/grpc/rb_completion_queue.c b/src/ruby/ext/grpc/rb_completion_queue.c index 3fdbdd837a7e7866d3a245053695e52f6e484964..215de99c299a3b201cd591e53f5bc7a7ea07e7e0 100644 --- a/src/ruby/ext/grpc/rb_completion_queue.c +++ b/src/ruby/ext/grpc/rb_completion_queue.c @@ -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. */ diff --git a/src/ruby/ext/grpc/rb_completion_queue.h b/src/ruby/ext/grpc/rb_completion_queue.h index 38025ea2d2e2488d81b7b879a89a1fa8f05e4c55..13715ccaa754a95b8c0be03f66aa4ce13a3e5fbd 100644 --- a/src/ruby/ext/grpc/rb_completion_queue.h +++ b/src/ruby/ext/grpc/rb_completion_queue.h @@ -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;