kgio 2.9.1 → 2.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/GIT-VERSION-GEN +1 -1
- data/ext/kgio/accept.c +4 -4
- data/ext/kgio/blocking_io_region.h +1 -1
- data/ext/kgio/connect.c +2 -2
- data/ext/kgio/kgio.h +7 -7
- data/ext/kgio/poll.c +5 -3
- data/ext/kgio/tryopen.c +13 -12
- data/ext/kgio/write.c +2 -2
- metadata +2 -2
data/GIT-VERSION-GEN
CHANGED
data/ext/kgio/accept.c
CHANGED
@@ -13,7 +13,7 @@ static VALUE cKgio_Socket;
|
|
13
13
|
static VALUE mSocketMethods;
|
14
14
|
static VALUE iv_kgio_addr;
|
15
15
|
|
16
|
-
#if defined(__linux__) && defined(
|
16
|
+
#if defined(__linux__) && defined(KGIO_WITHOUT_GVL)
|
17
17
|
static int accept4_flags = SOCK_CLOEXEC;
|
18
18
|
#else /* ! linux */
|
19
19
|
static int accept4_flags = SOCK_CLOEXEC | SOCK_NONBLOCK;
|
@@ -79,7 +79,7 @@ static VALUE xaccept(void *ptr)
|
|
79
79
|
return (VALUE)rv;
|
80
80
|
}
|
81
81
|
|
82
|
-
#ifdef
|
82
|
+
#ifdef KGIO_WITHOUT_GVL
|
83
83
|
# include <time.h>
|
84
84
|
# include "blocking_io_region.h"
|
85
85
|
static int thread_accept(struct accept_args *a, int force_nonblock)
|
@@ -89,7 +89,7 @@ static int thread_accept(struct accept_args *a, int force_nonblock)
|
|
89
89
|
return (int)rb_thread_io_blocking_region(xaccept, a, a->fd);
|
90
90
|
}
|
91
91
|
|
92
|
-
#else /* !
|
92
|
+
#else /* ! KGIO_WITHOUT_GVL */
|
93
93
|
# include <rubysig.h>
|
94
94
|
static int thread_accept(struct accept_args *a, int force_nonblock)
|
95
95
|
{
|
@@ -106,7 +106,7 @@ static int thread_accept(struct accept_args *a, int force_nonblock)
|
|
106
106
|
TRAP_END;
|
107
107
|
return rv;
|
108
108
|
}
|
109
|
-
#endif /* !
|
109
|
+
#endif /* ! KGIO_WITHOUT_GVL */
|
110
110
|
|
111
111
|
static void
|
112
112
|
prepare_accept(struct accept_args *a, VALUE self, int argc, const VALUE *argv)
|
data/ext/kgio/connect.c
CHANGED
@@ -145,7 +145,7 @@ static const struct sockaddr *sockaddr_from(socklen_t *addrlen, VALUE addr)
|
|
145
145
|
return NULL;
|
146
146
|
}
|
147
147
|
|
148
|
-
#if defined(MSG_FASTOPEN) && defined(
|
148
|
+
#if defined(MSG_FASTOPEN) && defined(KGIO_WITHOUT_GVL)
|
149
149
|
#ifndef HAVE_RB_STR_SUBSEQ
|
150
150
|
#define rb_str_subseq rb_str_substr
|
151
151
|
#endif
|
@@ -383,7 +383,7 @@ void init_kgio_connect(void)
|
|
383
383
|
rb_define_singleton_method(cKgio_Socket, "new", kgio_new, -1);
|
384
384
|
rb_define_singleton_method(cKgio_Socket, "connect", kgio_connect, 1);
|
385
385
|
rb_define_singleton_method(cKgio_Socket, "start", kgio_start, 1);
|
386
|
-
#if defined(MSG_FASTOPEN) && defined(
|
386
|
+
#if defined(MSG_FASTOPEN) && defined(KGIO_WITHOUT_GVL)
|
387
387
|
rb_define_method(cKgio_Socket, "kgio_fastopen", fastopen, 2);
|
388
388
|
#endif
|
389
389
|
/*
|
data/ext/kgio/kgio.h
CHANGED
@@ -39,16 +39,16 @@ void kgio_autopush_send(VALUE);
|
|
39
39
|
|
40
40
|
VALUE kgio_call_wait_writable(VALUE io);
|
41
41
|
VALUE kgio_call_wait_readable(VALUE io);
|
42
|
-
#if defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)
|
43
|
-
# define
|
44
|
-
|
45
|
-
# define rb_thread_blocking_region(fn,data1,ubf,data2) \
|
46
|
-
rb_thread_call_without_gvl((kgio_blocking_fn_t)(fn),(data1),(ubf),(data2))
|
42
|
+
#if defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL) && defined(HAVE_RUBY_THREAD_H)
|
43
|
+
# define KGIO_WITHOUT_GVL(fn,data1,ubf,data2) \
|
44
|
+
rb_thread_call_without_gvl((fn),(data1),(ubf),(data2))
|
47
45
|
#elif defined(HAVE_RB_THREAD_BLOCKING_REGION)
|
48
|
-
|
46
|
+
typedef VALUE(*kgio_blocking_fn_t)(void*);
|
47
|
+
# define KGIO_WITHOUT_GVL(fn,data1,ubf,data2) \
|
48
|
+
rb_thread_blocking_region((kgio_blocking_fn_t)(fn),(data1),(ubf),(data2))
|
49
49
|
#endif /* HAVE_RB_THREAD_CALL_WITHOUT_GVL || HAVE_RB_THREAD_BLOCKING_REGION */
|
50
50
|
|
51
|
-
#if defined(
|
51
|
+
#if defined(KGIO_WITHOUT_GVL) && defined(HAVE_POLL)
|
52
52
|
# define USE_KGIO_POLL
|
53
53
|
#endif /* USE_KGIO_POLL */
|
54
54
|
|
data/ext/kgio/poll.c
CHANGED
@@ -107,14 +107,16 @@ static void hash2pollfds(struct poll_args *a)
|
|
107
107
|
rb_hash_foreach(a->ios, io_to_pollfd_i, (VALUE)a);
|
108
108
|
}
|
109
109
|
|
110
|
-
static
|
110
|
+
static void * nogvl_poll(void *ptr)
|
111
111
|
{
|
112
112
|
struct poll_args *a = ptr;
|
113
|
+
long n;
|
113
114
|
|
114
115
|
if (a->timeout > 0)
|
115
116
|
clock_gettime(hopefully_CLOCK_MONOTONIC, &a->start);
|
116
117
|
|
117
|
-
|
118
|
+
n = poll(a->fds, a->nfds, a->timeout);
|
119
|
+
return (void *)n;
|
118
120
|
}
|
119
121
|
|
120
122
|
static VALUE poll_result(int nr, struct poll_args *a)
|
@@ -145,7 +147,7 @@ static VALUE do_poll(VALUE args)
|
|
145
147
|
|
146
148
|
retry:
|
147
149
|
hash2pollfds(a);
|
148
|
-
nr = (long)
|
150
|
+
nr = (long)KGIO_WITHOUT_GVL(nogvl_poll, a, RUBY_UBF_IO, NULL);
|
149
151
|
if (nr < 0) {
|
150
152
|
if (interrupted()) {
|
151
153
|
if (retryable(a)) {
|
data/ext/kgio/tryopen.c
CHANGED
@@ -33,23 +33,24 @@ struct open_args {
|
|
33
33
|
# define rb_cloexec_open(p,f,m) open((p),(f),(m))
|
34
34
|
#endif
|
35
35
|
|
36
|
-
static
|
36
|
+
static void * nogvl_open(void *ptr)
|
37
37
|
{
|
38
38
|
struct open_args *o = ptr;
|
39
|
+
long fd = (long)rb_cloexec_open(o->pathname, o->flags, o->mode);
|
39
40
|
|
40
|
-
return (
|
41
|
+
return (void *)fd;
|
41
42
|
}
|
42
43
|
|
43
|
-
#ifndef
|
44
|
+
#ifndef KGIO_WITHOUT_GVL
|
44
45
|
# define RUBY_UBF_IO ((void *)(-1))
|
45
46
|
# include "rubysig.h"
|
46
|
-
typedef void
|
47
|
-
typedef
|
48
|
-
static
|
49
|
-
|
50
|
-
|
47
|
+
typedef void my_unblock_function_t(void *);
|
48
|
+
typedef void *my_blocking_function_t(void *);
|
49
|
+
static void * my_thread_blocking_region(
|
50
|
+
my_blocking_function_t *fn, void *data1,
|
51
|
+
my_unblock_function_t *ubf, void *data2)
|
51
52
|
{
|
52
|
-
|
53
|
+
void *rv;
|
53
54
|
|
54
55
|
TRAP_BEG; /* for FIFO */
|
55
56
|
rv = fn(data1);
|
@@ -57,9 +58,9 @@ static VALUE my_thread_blocking_region(
|
|
57
58
|
|
58
59
|
return rv;
|
59
60
|
}
|
60
|
-
#define
|
61
|
+
#define KGIO_WITHOUT_GVL(fn,data1,ubf,data2) \
|
61
62
|
my_thread_blocking_region((fn),(data1),(ubf),(data2))
|
62
|
-
#endif /* !
|
63
|
+
#endif /* ! KGIO_WITHOUT_GVL */
|
63
64
|
|
64
65
|
/*
|
65
66
|
* call-seq:
|
@@ -107,7 +108,7 @@ static VALUE s_tryopen(int argc, VALUE *argv, VALUE klass)
|
|
107
108
|
}
|
108
109
|
|
109
110
|
retry:
|
110
|
-
fd = (long)
|
111
|
+
fd = (long)KGIO_WITHOUT_GVL(nogvl_open, &o, RUBY_UBF_IO, 0);
|
111
112
|
if (fd < 0) {
|
112
113
|
if (errno == EMFILE || errno == ENFILE || errno == ENOMEM) {
|
113
114
|
rb_gc();
|
data/ext/kgio/write.c
CHANGED
@@ -155,7 +155,7 @@ static VALUE kgio_trysend(VALUE io, VALUE str)
|
|
155
155
|
# define kgio_trysend kgio_trywrite
|
156
156
|
#endif /* ! USE_MSG_DONTWAIT */
|
157
157
|
|
158
|
-
#if defined(
|
158
|
+
#if defined(KGIO_WITHOUT_GVL)
|
159
159
|
# include "blocking_io_region.h"
|
160
160
|
#ifdef MSG_DONTWAIT /* Linux only */
|
161
161
|
# define MY_MSG_DONTWAIT (MSG_DONTWAIT)
|
@@ -256,7 +256,7 @@ void init_kgio_write(void)
|
|
256
256
|
rb_define_method(mSocketMethods, "kgio_write", kgio_send, 1);
|
257
257
|
rb_define_method(mSocketMethods, "kgio_trywrite", kgio_trysend, 1);
|
258
258
|
|
259
|
-
#if defined(
|
259
|
+
#if defined(KGIO_WITHOUT_GVL)
|
260
260
|
rb_define_method(mSocketMethods, "kgio_syssend", kgio_syssend, 2);
|
261
261
|
#endif
|
262
262
|
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kgio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.9.
|
4
|
+
version: 2.9.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-02-
|
12
|
+
date: 2014-02-15 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! 'kgio provides non-blocking I/O methods for Ruby without raising
|
15
15
|
|