ext/ruby/passenger_native_support.c in passenger-5.0.0.beta1 vs ext/ruby/passenger_native_support.c in passenger-5.0.0.beta2
- old
+ new
@@ -34,10 +34,13 @@
#include "version.h"
#endif
#ifdef HAVE_RUBY_VERSION_H
#include "ruby/version.h"
#endif
+#ifdef HAVE_RUBY_THREAD_H
+ #include "ruby/thread.h"
+#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/wait.h>
#include <sys/un.h>
@@ -197,15 +200,23 @@
int filedes;
const struct iovec *iov;
int iovcnt;
} WritevWrapperData;
- static VALUE
- writev_wrapper(void *ptr) {
- WritevWrapperData *data = (WritevWrapperData *) ptr;
- return (VALUE) writev(data->filedes, data->iov, data->iovcnt);
- }
+ #if defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)
+ static void *
+ writev_wrapper(void *ptr) {
+ WritevWrapperData *data = (WritevWrapperData *) ptr;
+ return (void *) writev(data->filedes, data->iov, data->iovcnt);
+ }
+ #else
+ static VALUE
+ writev_wrapper(void *ptr) {
+ WritevWrapperData *data = (WritevWrapperData *) ptr;
+ return (VALUE) writev(data->filedes, data->iov, data->iovcnt);
+ }
+ #endif
#endif
static VALUE
f_generic_writev(VALUE fd, VALUE *array_of_components, unsigned int count) {
VALUE components, str;
@@ -318,11 +329,14 @@
TRAP_END;
#else
writev_wrapper_data.filedes = fd_num;
writev_wrapper_data.iov = groups[i].io_vectors;
writev_wrapper_data.iovcnt = groups[i].count;
- #ifdef HAVE_RB_THREAD_IO_BLOCKING_REGION
+ #if defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)
+ ret = (int) rb_thread_call_without_gvl(writev_wrapper,
+ &writev_wrapper_data, RUBY_UBF_IO, NULL);
+ #elif defined(HAVE_RB_THREAD_IO_BLOCKING_REGION)
ret = (int) rb_thread_io_blocking_region(writev_wrapper,
&writev_wrapper_data, fd_num);
#else
ret = (int) rb_thread_blocking_region(writev_wrapper,
&writev_wrapper_data, RUBY_UBF_IO, 0);
@@ -724,26 +738,39 @@
rb_thread_wait_fd(fd);
return Qnil;
}
#ifndef TRAP_BEG
- static VALUE
- fs_watcher_read_byte_from_fd_wrapper(void *_arg) {
- FSWatcherReadByteData *data = (FSWatcherReadByteData *) _arg;
- data->ret = read(data->fd, &data->byte, 1);
- data->error = errno;
- return Qnil;
- }
+ #if defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)
+ static void *
+ fs_watcher_read_byte_from_fd_wrapper(void *_arg) {
+ FSWatcherReadByteData *data = (FSWatcherReadByteData *) _arg;
+ data->ret = read(data->fd, &data->byte, 1);
+ data->error = errno;
+ return NULL;
+ }
+ #else
+ static VALUE
+ fs_watcher_read_byte_from_fd_wrapper(void *_arg) {
+ FSWatcherReadByteData *data = (FSWatcherReadByteData *) _arg;
+ data->ret = read(data->fd, &data->byte, 1);
+ data->error = errno;
+ return Qnil;
+ }
+ #endif
#endif
static VALUE
fs_watcher_read_byte_from_fd(VALUE _arg) {
FSWatcherReadByteData *data = (FSWatcherReadByteData *) _arg;
#if defined(TRAP_BEG)
TRAP_BEG;
data->ret = read(data->fd, &data->byte, 1);
TRAP_END;
data->error = errno;
+ #elif defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)
+ rb_thread_call_without_gvl2(fs_watcher_read_byte_from_fd_wrapper,
+ data, RUBY_UBF_IO, NULL);
#elif defined(HAVE_RB_THREAD_IO_BLOCKING_REGION)
rb_thread_io_blocking_region(fs_watcher_read_byte_from_fd_wrapper,
data, data->fd);
#else
rb_thread_blocking_region(fs_watcher_read_byte_from_fd_wrapper,