Sha256: b4545ca3a80ff1bcf153d274d40359b6991e5a08c8838e50e5dcf199438400ea

Contents?: true

Size: 1.66 KB

Versions: 6

Compression:

Stored size: 1.66 KB

Contents

#if defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL) && defined(HAVE_RUBY_THREAD_H)
/* Ruby 2.0+ */
#  include <ruby/thread.h>
#  define WITHOUT_GVL(fn,a,ubf,b) \
        rb_thread_call_without_gvl((fn),(a),(ubf),(b))
#elif defined(HAVE_RB_THREAD_BLOCKING_REGION)
typedef VALUE (*my_blocking_fn_t)(void*);
#  define WITHOUT_GVL(fn,a,ubf,b) \
	rb_thread_blocking_region((my_blocking_fn_t)(fn),(a),(ubf),(b))
#endif

#ifdef WITHOUT_GVL
struct stat_args { int err; const char *path; struct stat *buf; };
static void * ng_stat(void *ptr)
{
	struct stat_args *a = ptr;
	a->err = stat(a->path, a->buf);
	return NULL;
}

static int my_stat(const char *path, struct stat *buf)
{
	struct stat_args a;

	a.path = path;
	a.buf = buf;
	WITHOUT_GVL(ng_stat, &a, RUBY_UBF_IO, 0);
	return a.err;
}

#ifndef HAVE_RB_THREAD_IO_BLOCKING_REGION
#  define rb_thread_io_blocking_region(fn,data,fd) \
           WITHOUT_GVL((fn),(data), RUBY_UBF_IO, 0)
#else
  VALUE rb_thread_io_blocking_region(VALUE(*)(void *), void *, int);
#endif

struct write_args { int fd; const void *buf; size_t count; };
static VALUE ng_write(void *ptr)
{
	struct write_args *a = ptr;

	return (VALUE)write(a->fd, a->buf, a->count);
}
static ssize_t my_write(int fd, const void *buf, size_t count)
{
	struct write_args a;
	ssize_t r;

	a.fd = fd;
	a.buf = buf;
	a.count = count;
	r = (ssize_t)rb_thread_io_blocking_region(ng_write, &a, fd);

	return r;
}
#  define nogvl_stat(path,buf) my_stat((path),(buf))
#  define nogvl_write(fd,buf,count) my_write((fd),(buf),(count))
#else /* !WITHOUT_GVL, for Ruby 1.8 users: */
#  define nogvl_stat(path,buf) stat((path),(buf))
#  define nogvl_write(fd,buf,buf) write((fd),(buf),(count))
#endif /* !WITHOUT_GVL */

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
clogger-2.4.0 ext/clogger_ext/blocking_helpers.h
clogger-2.3.1 ext/clogger_ext/blocking_helpers.h
clogger-2.3.0 ext/clogger_ext/blocking_helpers.h
clogger-2.2.1 ext/clogger_ext/blocking_helpers.h
clogger-2.2.0 ext/clogger_ext/blocking_helpers.h
clogger-2.1.0 ext/clogger_ext/blocking_helpers.h