summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-07-10 13:57:11 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-07-10 13:57:11 +0000
commitc51a826764c3307a7fe9258e1d18ddca93cb7b5f (patch)
treeb6139e61fe139e418a606ff611b0b6c30ce30dfe /ext
parent1a853390ee08af1b8ff3d1882a8762155d151306 (diff)
rb_thread_call_without_gvl
* include/ruby/thread.h: new header file for thread stuff. * thread.c (rb_thread_call_without_gvl): export. [Feature#4328] returns void* instead of VALUE. [Feature #5543] * thread.c (rb_thread_blocking_region): deprecate. [ruby-core:46295] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36355 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/curses/curses.c25
-rw-r--r--ext/curses/depend2
-rw-r--r--ext/openssl/ossl.h1
-rw-r--r--ext/openssl/ossl_pkey_dh.c6
-rw-r--r--ext/openssl/ossl_pkey_dsa.c6
-rw-r--r--ext/openssl/ossl_pkey_rsa.c6
-rw-r--r--ext/socket/ancdata.c12
-rw-r--r--ext/socket/depend2
-rw-r--r--ext/socket/raddrinfo.c20
-rw-r--r--ext/socket/rubysocket.h1
-rw-r--r--ext/zlib/zlib.c7
11 files changed, 46 insertions, 42 deletions
diff --git a/ext/curses/curses.c b/ext/curses/curses.c
index 6a12808..b99fb96 100644
--- a/ext/curses/curses.c
+++ b/ext/curses/curses.c
@@ -18,6 +18,7 @@
#include "ruby.h"
#include "ruby/io.h"
+#include "ruby/thread.h"
#if defined(HAVE_NCURSES_H)
# include <ncurses.h>
@@ -634,12 +635,12 @@ curses_addstr(VALUE obj, VALUE str)
return Qnil;
}
-static VALUE
+static void *
getch_func(void *arg)
{
int *ip = (int *)arg;
*ip = getch();
- return Qnil;
+ return 0;
}
/*
@@ -656,7 +657,7 @@ curses_getch(VALUE obj)
int c;
curses_stdscr();
- rb_thread_blocking_region(getch_func, (void *)&c, RUBY_UBF_IO, 0);
+ rb_thread_call_without_gvl(getch_func, &c, RUBY_UBF_IO, 0);
if (c == EOF) return Qnil;
if (rb_isprint(c)) {
char ch = (char)c;
@@ -669,7 +670,7 @@ curses_getch(VALUE obj)
/* This should be big enough.. I hope */
#define GETSTR_BUF_SIZE 1024
-static VALUE
+static void *
getstr_func(void *arg)
{
char *rtn = (char *)arg;
@@ -678,7 +679,7 @@ getstr_func(void *arg)
#else
getstr(rtn);
#endif
- return Qnil;
+ return 0;
}
/*
@@ -693,7 +694,7 @@ curses_getstr(VALUE obj)
char rtn[GETSTR_BUF_SIZE];
curses_stdscr();
- rb_thread_blocking_region(getstr_func, (void *)rtn, RUBY_UBF_IO, 0);
+ rb_thread_call_without_gvl(getstr_func, rtn, RUBY_UBF_IO, 0);
return rb_locale_str_new_cstr(rtn);
}
@@ -1955,12 +1956,12 @@ struct wgetch_arg {
int c;
};
-static VALUE
+static void *
wgetch_func(void *_arg)
{
struct wgetch_arg *arg = (struct wgetch_arg *)_arg;
arg->c = wgetch(arg->win);
- return Qnil;
+ return 0;
}
/*
@@ -1980,7 +1981,7 @@ window_getch(VALUE obj)
GetWINDOW(obj, winp);
arg.win = winp->window;
- rb_thread_blocking_region(wgetch_func, (void *)&arg, RUBY_UBF_IO, 0);
+ rb_thread_call_without_gvl(wgetch_func, (void *)&arg, RUBY_UBF_IO, 0);
c = arg.c;
if (c == EOF) return Qnil;
if (rb_isprint(c)) {
@@ -1996,7 +1997,7 @@ struct wgetstr_arg {
char rtn[GETSTR_BUF_SIZE];
};
-static VALUE
+static void *
wgetstr_func(void *_arg)
{
struct wgetstr_arg *arg = (struct wgetstr_arg *)_arg;
@@ -2005,7 +2006,7 @@ wgetstr_func(void *_arg)
#else
wgetstr(arg->win, arg->rtn);
#endif
- return Qnil;
+ return 0;
}
/*
@@ -2022,7 +2023,7 @@ window_getstr(VALUE obj)
GetWINDOW(obj, winp);
arg.win = winp->window;
- rb_thread_blocking_region(wgetstr_func, (void *)&arg, RUBY_UBF_IO, 0);
+ rb_thread_call_without_gvl(wgetstr_func, (void *)&arg, RUBY_UBF_IO, 0);
return rb_locale_str_new_cstr(arg.rtn);
}
diff --git a/ext/curses/depend b/ext/curses/depend
index ecb79e5..66742b7 100644
--- a/ext/curses/depend
+++ b/ext/curses/depend
@@ -1 +1 @@
-curses.o: curses.c $(hdrdir)/ruby.h $(topdir)/config.h $(hdrdir)/defines.h
+curses.o: curses.c $(hdrdir)/ruby.h $(topdir)/config.h $(hdrdir)/defines.h $(hdrdir)/thread.h
diff --git a/ext/openssl/ossl.h b/ext/openssl/ossl.h
index f8023bc..88e4506 100644
--- a/ext/openssl/ossl.h
+++ b/ext/openssl/ossl.h
@@ -30,6 +30,7 @@ extern "C" {
#endif
#include <ruby.h>
#include <ruby/io.h>
+#include <ruby/thread.h>
/*
* Check the OpenSSL version
diff --git a/ext/openssl/ossl_pkey_dh.c b/ext/openssl/ossl_pkey_dh.c
index 819fbce..c8fb40e 100644
--- a/ext/openssl/ossl_pkey_dh.c
+++ b/ext/openssl/ossl_pkey_dh.c
@@ -90,12 +90,12 @@ struct dh_blocking_gen_arg {
int result;
};
-static VALUE
+static void *
dh_blocking_gen(void *arg)
{
struct dh_blocking_gen_arg *gen = (struct dh_blocking_gen_arg *)arg;
gen->result = DH_generate_parameters_ex(gen->dh, gen->size, gen->gen, gen->cb);
- return Qnil;
+ return 0;
}
#endif
@@ -123,7 +123,7 @@ dh_generate(int size, int gen)
dh_blocking_gen(&gen_arg);
} else {
/* there's a chance to unblock */
- rb_thread_blocking_region(dh_blocking_gen, &gen_arg, ossl_generate_cb_stop, &cb_arg);
+ rb_thread_call_without_gvl(dh_blocking_gen, &gen_arg, ossl_generate_cb_stop, &cb_arg);
}
if (!gen_arg.result) {
diff --git a/ext/openssl/ossl_pkey_dsa.c b/ext/openssl/ossl_pkey_dsa.c
index d3e91f0..ba28ba0 100644
--- a/ext/openssl/ossl_pkey_dsa.c
+++ b/ext/openssl/ossl_pkey_dsa.c
@@ -87,12 +87,12 @@ struct dsa_blocking_gen_arg {
int result;
};
-static VALUE
+static void *
dsa_blocking_gen(void *arg)
{
struct dsa_blocking_gen_arg *gen = (struct dsa_blocking_gen_arg *)arg;
gen->result = DSA_generate_parameters_ex(gen->dsa, gen->size, gen->seed, gen->seed_len, gen->counter, gen->h, gen->cb);
- return Qnil;
+ return 0;
}
#endif
@@ -130,7 +130,7 @@ dsa_generate(int size)
dsa_blocking_gen(&gen_arg);
} else {
/* there's a chance to unblock */
- rb_thread_blocking_region(dsa_blocking_gen, &gen_arg, ossl_generate_cb_stop, &cb_arg);
+ rb_thread_call_without_gvl(dsa_blocking_gen, &gen_arg, ossl_generate_cb_stop, &cb_arg);
}
if (!gen_arg.result) {
DSA_free(dsa);
diff --git a/ext/openssl/ossl_pkey_rsa.c b/ext/openssl/ossl_pkey_rsa.c
index 3fbd87f..e395e71 100644
--- a/ext/openssl/ossl_pkey_rsa.c
+++ b/ext/openssl/ossl_pkey_rsa.c
@@ -85,12 +85,12 @@ struct rsa_blocking_gen_arg {
int result;
};
-static VALUE
+static void *
rsa_blocking_gen(void *arg)
{
struct rsa_blocking_gen_arg *gen = (struct rsa_blocking_gen_arg *)arg;
gen->result = RSA_generate_key_ex(gen->rsa, gen->size, gen->e, gen->cb);
- return Qnil;
+ return 0;
}
#endif
@@ -133,7 +133,7 @@ rsa_generate(int size, unsigned long exp)
rsa_blocking_gen(&gen_arg);
} else {
/* there's a chance to unblock */
- rb_thread_blocking_region(rsa_blocking_gen, &gen_arg, ossl_generate_cb_stop, &cb_arg);
+ rb_thread_call_without_gvl(rsa_blocking_gen, &gen_arg, ossl_generate_cb_stop, &cb_arg);
}
if (!gen_arg.result) {
BN_free(e);
diff --git a/ext/socket/ancdata.c b/ext/socket/ancdata.c
index 52f92a1..5af090c 100644
--- a/ext/socket/ancdata.c
+++ b/ext/socket/ancdata.c
@@ -1110,11 +1110,11 @@ struct sendmsg_args_struct {
int flags;
};
-static VALUE
+static void *
nogvl_sendmsg_func(void *ptr)
{
struct sendmsg_args_struct *args = ptr;
- return sendmsg(args->fd, args->msg, args->flags);
+ return (void *)sendmsg(args->fd, args->msg, args->flags);
}
static ssize_t
@@ -1124,7 +1124,7 @@ rb_sendmsg(int fd, const struct msghdr *msg, int flags)
args.fd = fd;
args.msg = msg;
args.flags = flags;
- return rb_thread_blocking_region(nogvl_sendmsg_func, &args, RUBY_UBF_IO, 0);
+ return (ssize_t)rb_thread_call_without_gvl(nogvl_sendmsg_func, &args, RUBY_UBF_IO, 0);
}
static VALUE
@@ -1368,12 +1368,12 @@ rsock_recvmsg(int socket, struct msghdr *message, int flags)
return recvmsg(socket, message, flags);
}
-static VALUE
+static void *
nogvl_recvmsg_func(void *ptr)
{
struct recvmsg_args_struct *args = ptr;
int flags = args->flags;
- return rsock_recvmsg(args->fd, args->msg, flags);
+ return (void *)rsock_recvmsg(args->fd, args->msg, flags);
}
static ssize_t
@@ -1383,7 +1383,7 @@ rb_recvmsg(int fd, struct msghdr *msg, int flags)
args.fd = fd;
args.msg = msg;
args.flags = flags;
- return rb_thread_blocking_region(nogvl_recvmsg_func, &args, RUBY_UBF_IO, 0);
+ return (ssize_t)rb_thread_call_without_gvl(nogvl_recvmsg_func, &args, RUBY_UBF_IO, 0);
}
#if defined(HAVE_ST_MSG_CONTROL)
diff --git a/ext/socket/depend b/ext/socket/depend
index ab0a5e8..1716f9c 100644
--- a/ext/socket/depend
+++ b/ext/socket/depend
@@ -1,5 +1,5 @@
SOCK_HEADERS = $(srcdir)/rubysocket.h $(hdrdir)/ruby/ruby.h $(arch_hdrdir)/ruby/config.h \
- $(hdrdir)/ruby/defines.h $(hdrdir)/ruby/io.h \
+ $(hdrdir)/ruby/defines.h $(hdrdir)/ruby/io.h $(hdrdir)/ruby/thread.h \
$(srcdir)/addrinfo.h $(srcdir)/sockport.h constdefs.h $(top_srcdir)/internal.h
init.o: init.c $(SOCK_HEADERS)
diff --git a/ext/socket/raddrinfo.c b/ext/socket/raddrinfo.c
index a7391c9..f37c87b 100644
--- a/ext/socket/raddrinfo.c
+++ b/ext/socket/raddrinfo.c
@@ -154,12 +154,12 @@ struct getaddrinfo_arg
struct addrinfo **res;
};
-static VALUE
+static void *
nogvl_getaddrinfo(void *arg)
{
struct getaddrinfo_arg *ptr = arg;
- return getaddrinfo(ptr->node, ptr->service,
- ptr->hints, ptr->res);
+ return (void *)getaddrinfo(ptr->node, ptr->service,
+ ptr->hints, ptr->res);
}
#endif
@@ -178,7 +178,7 @@ rb_getaddrinfo(const char *node, const char *service,
arg.service = service;
arg.hints = hints;
arg.res = res;
- ret = (int)BLOCKING_REGION(nogvl_getaddrinfo, &arg);
+ ret = (int)rb_thread_call_without_gvl(nogvl_getaddrinfo, &arg, RUBY_UBF_IO, 0);
return ret;
#endif
}
@@ -195,14 +195,14 @@ struct getnameinfo_arg
int flags;
};
-static VALUE
+static void *
nogvl_getnameinfo(void *arg)
{
struct getnameinfo_arg *ptr = arg;
- return getnameinfo(ptr->sa, ptr->salen,
- ptr->host, (socklen_t)ptr->hostlen,
- ptr->serv, (socklen_t)ptr->servlen,
- ptr->flags);
+ return (void *)getnameinfo(ptr->sa, ptr->salen,
+ ptr->host, (socklen_t)ptr->hostlen,
+ ptr->serv, (socklen_t)ptr->servlen,
+ ptr->flags);
}
#endif
@@ -223,7 +223,7 @@ rb_getnameinfo(const struct sockaddr *sa, socklen_t salen,
arg.serv = serv;
arg.servlen = servlen;
arg.flags = flags;
- ret = (int)BLOCKING_REGION(nogvl_getnameinfo, &arg);
+ ret = (int)rb_thread_call_without_gvl(nogvl_getnameinfo, &arg, RUBY_UBF_IO, 0);
return ret;
#endif
}
diff --git a/ext/socket/rubysocket.h b/ext/socket/rubysocket.h
index 3b6f51f..bbc8249 100644
--- a/ext/socket/rubysocket.h
+++ b/ext/socket/rubysocket.h
@@ -3,6 +3,7 @@
#include "ruby/ruby.h"
#include "ruby/io.h"
+#include "ruby/thread.h"
#include "ruby/util.h"
#include "internal.h"
#include <stdio.h>
diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c
index fc49e44..3fb1be9 100644
--- a/ext/zlib/zlib.c
+++ b/ext/zlib/zlib.c
@@ -10,6 +10,7 @@
#include <zlib.h>
#include <time.h>
#include <ruby/io.h>
+#include <ruby/thread.h>
#ifdef HAVE_VALGRIND_MEMCHECK_H
# include <valgrind/memcheck.h>
@@ -916,7 +917,7 @@ zstream_end(struct zstream *z)
return Qnil;
}
-static VALUE
+static void *
zstream_run_func(void *ptr)
{
struct zstream_run_args *args = (struct zstream_run_args *)ptr;
@@ -950,7 +951,7 @@ zstream_run_func(void *ptr)
}
}
- return (VALUE)err;
+ return (void *)err;
}
/*
@@ -994,7 +995,7 @@ zstream_run(struct zstream *z, Bytef *src, long len, int flush)
}
loop:
- err = (int)rb_thread_blocking_region(
+ err = (int)rb_thread_call_without_gvl(
zstream_run_func, (void *)&args,
zstream_unblock_func, (void *)&args);