1 #if defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL) && defined(HAVE_RUBY_THREAD_H)
3 # include <ruby/thread.h>
4 # define WITHOUT_GVL(fn,a,ubf,b) \
5 rb_thread_call_without_gvl((fn),(a),(ubf),(b))
6 #elif defined(HAVE_RB_THREAD_BLOCKING_REGION)
7 typedef VALUE (*my_blocking_fn_t
)(void*);
8 # define WITHOUT_GVL(fn,a,ubf,b) \
9 rb_thread_blocking_region((my_blocking_fn_t)(fn),(a),(ubf),(b))
13 struct stat_args
{ int err
; const char *path
; struct stat
*buf
; };
14 static void * ng_stat(void *ptr
)
16 struct stat_args
*a
= ptr
;
17 a
->err
= stat(a
->path
, a
->buf
);
21 static int my_stat(const char *path
, struct stat
*buf
)
27 WITHOUT_GVL(ng_stat
, &a
, RUBY_UBF_IO
, 0);
31 #ifndef HAVE_RB_THREAD_IO_BLOCKING_REGION
32 # define rb_thread_io_blocking_region(fn,data,fd) \
33 WITHOUT_GVL((fn),(data), RUBY_UBF_IO, 0)
35 VALUE
rb_thread_io_blocking_region(VALUE(*)(void *), void *, int);
38 struct write_args
{ int fd
; const void *buf
; size_t count
; };
39 static VALUE
ng_write(void *ptr
)
41 struct write_args
*a
= ptr
;
43 return (VALUE
)write(a
->fd
, a
->buf
, a
->count
);
45 static ssize_t
my_write(int fd
, const void *buf
, size_t count
)
53 r
= (ssize_t
)rb_thread_io_blocking_region(ng_write
, &a
, fd
);
57 # define nogvl_stat(path,buf) my_stat((path),(buf))
58 # define nogvl_write(fd,buf,count) my_write((fd),(buf),(count))
59 #else /* !WITHOUT_GVL, for Ruby 1.8 users: */
60 # define nogvl_stat(path,buf) stat((path),(buf))
61 # define nogvl_write(fd,buf,buf) write((fd),(buf),(count))
62 #endif /* !WITHOUT_GVL */