aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Tim Emiola <temiola@google.com>2015-03-28 01:46:00 -0700
committerGravatar Tim Emiola <temiola@google.com>2015-04-10 11:23:42 -0700
commit6de558f9cdd54fedbd7b1b1bb16e95023e3193bc (patch)
tree0cbfc8a2b9d28ea5cf9c28e503796824c5b6b074
parent6b493a33534ec5235e5907f75b4f925b97622755 (diff)
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
-rw-r--r--src/ruby/ext/grpc/rb_completion_queue.c19
-rw-r--r--src/ruby/ext/grpc/rb_completion_queue.h8
2 files changed, 23 insertions, 4 deletions
diff --git a/src/ruby/ext/grpc/rb_completion_queue.c b/src/ruby/ext/grpc/rb_completion_queue.c
index 3fdbdd837a..215de99c29 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 38025ea2d2..13715ccaa7 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;