Skip to content

Commit 806502f

Browse files
ioquatixsamuel-williams-shopify
authored andcommitted
Use rb_nogvl(..., RB_NOGVL_OFFLOAD_SAFE) for compatibility with the fiber scheduler.
1 parent bdc9563 commit 806502f

3 files changed

Lines changed: 16 additions & 7 deletions

File tree

src/ruby/ext/grpc/rb_completion_queue.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,10 @@ grpc_event rb_completion_queue_pluck(grpc_completion_queue* queue, void* tag,
8585
grpc_absl_log_str(GPR_DEBUG, "CQ pluck loop begin: ", reason);
8686
do {
8787
next_call.interrupted = 0;
88-
rb_thread_call_without_gvl(grpc_rb_completion_queue_pluck_no_gil,
89-
(void*)&next_call, unblock_func,
90-
(void*)&next_call);
88+
rb_nogvl(grpc_rb_completion_queue_pluck_no_gil,
89+
(void*)&next_call, unblock_func,
90+
(void*)&next_call,
91+
RB_NOGVL_OFFLOAD_SAFE);
9192
if (next_call.event.type != GRPC_QUEUE_TIMEOUT) break;
9293
} while (next_call.interrupted);
9394
grpc_absl_log_str(GPR_DEBUG, "CQ pluck loop done: ", reason);

src/ruby/ext/grpc/rb_event_thread.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,12 @@ static VALUE grpc_rb_event_thread(void* arg) {
124124
grpc_rb_event* event;
125125
(void)arg;
126126
while (true) {
127-
event = (grpc_rb_event*)rb_thread_call_without_gvl(
127+
#ifdef RB_NOGVL_OFFLOAD_SAFE
128+
129+
#endif
130+
event = (grpc_rb_event*)rb_nogvl(
128131
grpc_rb_wait_for_event_no_gil, NULL, grpc_rb_event_unblocking_func,
129-
NULL);
132+
NULL, RB_NOGVL_OFFLOAD_SAFE);
130133
if (event == NULL) {
131134
// Indicates that the thread needs to shut down
132135
break;
@@ -160,8 +163,8 @@ void grpc_rb_event_queue_thread_stop() {
160163
"GRPC_RUBY: call credentials thread stop: thread not running");
161164
return;
162165
}
163-
rb_thread_call_without_gvl(grpc_rb_event_unblocking_func_wrapper, NULL, NULL,
164-
NULL);
166+
rb_nogvl(grpc_rb_event_unblocking_func_wrapper, NULL, NULL,
167+
NULL, RB_NOGVL_OFFLOAD_SAFE);
165168
rb_funcall(g_event_thread, rb_intern("join"), 0);
166169
g_event_thread = Qnil;
167170
}

src/ruby/ext/grpc/rb_grpc.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,9 @@ void grpc_ruby_init();
8585
abort(); \
8686
}
8787

88+
#ifndef RB_NOGVL_OFFLOAD_SAFE
89+
// Default to no-op if it's not defined:
90+
#define RB_NOGVL_OFFLOAD_SAFE 0
91+
#endif
92+
8893
#endif /* GRPC_RB_H_ */

0 commit comments

Comments
 (0)