polyphony 0.99.4 → 0.99.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +10 -0
- data/examples/pipes/gzip_http_server.rb +2 -2
- data/examples/pipes/http_server.rb +1 -1
- data/examples/pipes/tcp_proxy.rb +1 -1
- data/ext/polyphony/backend_common.c +4 -4
- data/ext/polyphony/backend_io_uring.c +8 -8
- data/ext/polyphony/backend_libev.c +5 -5
- data/ext/polyphony/fiber.c +32 -41
- data/ext/polyphony/io_extensions.c +50 -37
- data/ext/polyphony/pipe.c +6 -18
- data/ext/polyphony/polyphony.c +63 -133
- data/ext/polyphony/queue.c +25 -63
- data/ext/polyphony/thread.c +3 -12
- data/lib/polyphony/adapters/process.rb +1 -2
- data/lib/polyphony/adapters/sequel.rb +2 -2
- data/lib/polyphony/core/debug.rb +1 -1
- data/lib/polyphony/core/exceptions.rb +1 -1
- data/lib/polyphony/core/global_api.rb +24 -38
- data/lib/polyphony/core/resource_pool.rb +7 -8
- data/lib/polyphony/core/sync.rb +1 -2
- data/lib/polyphony/core/thread_pool.rb +2 -5
- data/lib/polyphony/core/throttler.rb +1 -5
- data/lib/polyphony/core/timer.rb +24 -25
- data/lib/polyphony/extensions/fiber.rb +507 -540
- data/lib/polyphony/extensions/io.rb +3 -12
- data/lib/polyphony/extensions/openssl.rb +2 -23
- data/lib/polyphony/extensions/pipe.rb +4 -15
- data/lib/polyphony/extensions/socket.rb +15 -109
- data/lib/polyphony/extensions/thread.rb +0 -13
- data/lib/polyphony/extensions/timeout.rb +0 -1
- data/lib/polyphony/net.rb +5 -8
- data/lib/polyphony/version.rb +1 -1
- data/lib/polyphony.rb +2 -6
- data/test/test_io.rb +221 -221
- data/test/test_socket.rb +3 -3
- data/test/test_trace.rb +2 -2
- metadata +1 -1
data/ext/polyphony/polyphony.c
CHANGED
@@ -27,15 +27,11 @@ ID ID_R;
|
|
27
27
|
ID ID_W;
|
28
28
|
ID ID_RW;
|
29
29
|
|
30
|
-
/*
|
31
|
-
* snooze
|
32
|
-
* Polyphony.snooze
|
33
|
-
*
|
34
|
-
* Switches to the next fiber in the current thread's runqueue after adding the
|
30
|
+
/* Switches to the next fiber in the current thread's runqueue after adding the
|
35
31
|
* current fiber to the runqueue. This lets other fibers run, letting the
|
36
32
|
* current fiber eventually continue its work. This call is useful when
|
37
33
|
* performing long-running calculations in order to keep the program responsive.
|
38
|
-
*
|
34
|
+
*
|
39
35
|
* @return [void]
|
40
36
|
*/
|
41
37
|
|
@@ -43,14 +39,10 @@ VALUE Polyphony_snooze(VALUE self) {
|
|
43
39
|
return Backend_snooze(BACKEND());
|
44
40
|
}
|
45
41
|
|
46
|
-
/*
|
47
|
-
* suspend
|
48
|
-
* Polyphony.suspend
|
49
|
-
*
|
50
|
-
* Switches to the next fiber in the current thread's runqueue without
|
42
|
+
/* Switches to the next fiber in the current thread's runqueue without
|
51
43
|
* rescheduling the current fiber. This is useful if the current fiber does not
|
52
44
|
* need to continue or will be scheduled by other means eventually.
|
53
|
-
*
|
45
|
+
*
|
54
46
|
* @return [void]
|
55
47
|
*/
|
56
48
|
|
@@ -62,15 +54,12 @@ static VALUE Polyphony_suspend(VALUE self) {
|
|
62
54
|
return ret;
|
63
55
|
}
|
64
56
|
|
65
|
-
/*
|
66
|
-
* Polyphony.backend_accept(server_socket, socket_class) -> socket
|
67
|
-
*
|
68
|
-
* Accepts an incoming connection on the given server socket, returning an
|
57
|
+
/* Accepts an incoming connection on the given server socket, returning an
|
69
58
|
* instance of the given socket class.
|
70
|
-
*
|
59
|
+
*
|
71
60
|
* @param server_socket [Socket] socket to accept on
|
72
61
|
* @param socket_class [Class] class of the socket to instantiate for the accepted connection
|
73
|
-
*
|
62
|
+
*
|
74
63
|
* @return [Socket] accepted connection
|
75
64
|
*/
|
76
65
|
|
@@ -78,15 +67,12 @@ VALUE Polyphony_backend_accept(VALUE self, VALUE server_socket, VALUE socket_cla
|
|
78
67
|
return Backend_accept(BACKEND(), server_socket, socket_class);
|
79
68
|
}
|
80
69
|
|
81
|
-
/*
|
82
|
-
* Polyphony.backend_accept_loop(server_socket, socket_class) { |socket| ... }
|
83
|
-
*
|
84
|
-
* Runs an infinite loop accepting connections on the given server socket,
|
70
|
+
/* Runs an infinite loop accepting connections on the given server socket,
|
85
71
|
* returning an instance of the given socket class.
|
86
|
-
*
|
72
|
+
*
|
87
73
|
* @param server_socket [Socket] socket to accept on
|
88
74
|
* @param socket_class [Class] class of the socket to instantiate for the accepted connection
|
89
|
-
* @yield [Socket] accepted connection
|
75
|
+
* @yield [Socket] accepted connection
|
90
76
|
* @return [void]
|
91
77
|
*/
|
92
78
|
|
@@ -95,12 +81,9 @@ VALUE Polyphony_backend_accept_loop(VALUE self, VALUE server_socket, VALUE socke
|
|
95
81
|
}
|
96
82
|
|
97
83
|
#ifdef HAVE_IO_URING_PREP_MULTISHOT_ACCEPT
|
98
|
-
/*
|
99
|
-
* Polyphony.backend_multishot_accept(server_socket) { ... }
|
100
|
-
*
|
101
|
-
* Starts a multishot accept operation on the given server socket. This API is
|
84
|
+
/* Starts a multishot accept operation on the given server socket. This API is
|
102
85
|
* available only for the io_uring backend.
|
103
|
-
*
|
86
|
+
*
|
104
87
|
* @param server_socket [Socket] socket to accept on
|
105
88
|
* @return [void]
|
106
89
|
*/
|
@@ -111,15 +94,12 @@ VALUE Polyphony_backend_multishot_accept(VALUE self, VALUE server_socket) {
|
|
111
94
|
#endif
|
112
95
|
|
113
96
|
|
114
|
-
/*
|
115
|
-
* Polyphony.backend_connect(socket, addr, port) -> socket
|
97
|
+
/* Connects the given socket to the given address and port.
|
116
98
|
*
|
117
|
-
* Connects the given socket to the given address and port.
|
118
|
-
*
|
119
99
|
* @param io [Socket] socket to connect
|
120
100
|
* @param addr [String] address to connect to
|
121
101
|
* @param port [Integer] port to connect to
|
122
|
-
*
|
102
|
+
*
|
123
103
|
* @return [Socket] accepted connection
|
124
104
|
*/
|
125
105
|
|
@@ -127,36 +107,29 @@ VALUE Polyphony_backend_connect(VALUE self, VALUE io, VALUE addr, VALUE port) {
|
|
127
107
|
return Backend_connect(BACKEND(), io, addr, port);
|
128
108
|
}
|
129
109
|
|
130
|
-
/*
|
131
|
-
*
|
110
|
+
/* Runs a feed loop, reading data from the given io, feeding it to the receiver
|
111
|
+
* with the given method. The loop terminates when EOF is encountered. If a
|
112
|
+
* block is given, it is used as the block for the method call to the receiver.
|
132
113
|
*
|
133
|
-
* Runs a feed loop, reading data from the given io, feeding it to the receiver
|
134
|
-
* with the given method, and passing the receiver's output to the given block.
|
135
|
-
* The loop terminates when EOF is encountered.
|
136
|
-
*
|
137
114
|
* @param io [IO] io to read from
|
138
115
|
* @param receiver [any] an object receiving the data
|
139
116
|
* @param method [Symbol] method used to feed the data to the receiver
|
140
|
-
*
|
141
|
-
*
|
142
|
-
* @return [void]
|
117
|
+
*
|
118
|
+
* @return [IO] io
|
143
119
|
*/
|
144
120
|
|
145
121
|
VALUE Polyphony_backend_feed_loop(VALUE self, VALUE io, VALUE receiver, VALUE method) {
|
146
122
|
return Backend_feed_loop(BACKEND(), io, receiver, method);
|
147
123
|
}
|
148
124
|
|
149
|
-
/*
|
150
|
-
* Polyphony.backend_read(io, buffer, length, to_eof, pos) -> buffer
|
125
|
+
/* Reads from the given io.
|
151
126
|
*
|
152
|
-
* Reads from the given io.
|
153
|
-
*
|
154
127
|
* @param io [IO] io to read from
|
155
128
|
* @param buffer [String, nil] buffer to read into
|
156
129
|
* @param length [Integer] maximum bytes to read
|
157
130
|
* @param to_eof [boolean] whether to read to EOF
|
158
131
|
* @param pos [Integer] Position in the buffer to read into
|
159
|
-
*
|
132
|
+
*
|
160
133
|
* @return [String] buffer
|
161
134
|
*/
|
162
135
|
|
@@ -164,15 +137,12 @@ VALUE Polyphony_backend_read(VALUE self, VALUE io, VALUE buffer, VALUE length, V
|
|
164
137
|
return Backend_read(BACKEND(), io, buffer, length, to_eof, pos);
|
165
138
|
}
|
166
139
|
|
167
|
-
/*
|
168
|
-
* Polyphony.backend_read_loop(io, max_len)
|
169
|
-
*
|
170
|
-
* Performs an infinite loop reading data from the given io. The loop terminates
|
140
|
+
/* Performs an infinite loop reading data from the given io. The loop terminates
|
171
141
|
* when EOF is encountered.
|
172
|
-
*
|
142
|
+
*
|
173
143
|
* @param io [IO] io to read from
|
174
144
|
* @param maxlen [Integer] maximum bytes to read
|
175
|
-
*
|
145
|
+
*
|
176
146
|
* @return [void]
|
177
147
|
*/
|
178
148
|
|
@@ -180,16 +150,13 @@ VALUE Polyphony_backend_read_loop(VALUE self, VALUE io, VALUE maxlen) {
|
|
180
150
|
return Backend_read_loop(BACKEND(), io, maxlen);
|
181
151
|
}
|
182
152
|
|
183
|
-
/*
|
184
|
-
* Polyphony.backend_recv(io, buffer, length, pos) -> buffer
|
153
|
+
/* Receives data on the given io.
|
185
154
|
*
|
186
|
-
* Receives data on the given io.
|
187
|
-
*
|
188
155
|
* @param io [Socket] io to receive on
|
189
156
|
* @param buffer [String, nil] buffer to read into
|
190
157
|
* @param length [Integer] maximum bytes to read
|
191
158
|
* @param pos [Integer] Position in the buffer to read into
|
192
|
-
*
|
159
|
+
*
|
193
160
|
* @return [String] buffer
|
194
161
|
*/
|
195
162
|
|
@@ -197,11 +164,8 @@ VALUE Polyphony_backend_recv(VALUE self, VALUE io, VALUE buffer, VALUE length, V
|
|
197
164
|
return Backend_recv(BACKEND(), io, buffer, length, pos);
|
198
165
|
}
|
199
166
|
|
200
|
-
/*
|
201
|
-
* Polyphony.backend_recvmsg(socket, buffer, maxlen, pos, flags, maxcontrollen, opts) -> buffer
|
167
|
+
/* Receives a message on the given socket.
|
202
168
|
*
|
203
|
-
* Receives a message on the given socket.
|
204
|
-
*
|
205
169
|
* @param socket [UDPSocket] io to receive on
|
206
170
|
* @param buffer [String, nil] buffer to read into
|
207
171
|
* @param maxlen [Integer] maximum bytes to read
|
@@ -209,7 +173,6 @@ VALUE Polyphony_backend_recv(VALUE self, VALUE io, VALUE buffer, VALUE length, V
|
|
209
173
|
* @param flags [Integer] Flags
|
210
174
|
* @param maxcontrollen [Integer] Maximum control bytes
|
211
175
|
* @param opts [Hash] Options
|
212
|
-
*
|
213
176
|
* @return [String] buffer
|
214
177
|
*/
|
215
178
|
|
@@ -217,15 +180,12 @@ VALUE Polyphony_backend_recvmsg(VALUE self, VALUE socket, VALUE buffer, VALUE ma
|
|
217
180
|
return Backend_recvmsg(BACKEND(), socket, buffer, maxlen, pos, flags, maxcontrollen, opts);
|
218
181
|
}
|
219
182
|
|
220
|
-
/*
|
221
|
-
*
|
183
|
+
/* Performs an infinite loop receiving data on the given socket. The loop
|
184
|
+
* terminates when the socket is closed.
|
222
185
|
*
|
223
|
-
* Performs an infinite loop receiving data on the given socket. The loop terminates
|
224
|
-
* when the socket is closed.
|
225
|
-
*
|
226
186
|
* @param socket [Socket] socket to receive on
|
227
187
|
* @param maxlen [Integer] maximum bytes to read
|
228
|
-
*
|
188
|
+
* @yield [data] received data
|
229
189
|
* @return [void]
|
230
190
|
*/
|
231
191
|
|
@@ -233,18 +193,15 @@ VALUE Polyphony_backend_recv_loop(VALUE self, VALUE socket, VALUE maxlen) {
|
|
233
193
|
return Backend_recv_loop(BACKEND(), socket, maxlen);
|
234
194
|
}
|
235
195
|
|
236
|
-
/*
|
237
|
-
*
|
196
|
+
/* Runs a feed loop, receiving data on the given socket, feeding it to the
|
197
|
+
* receiver with the given method. The loop terminates when EOF is encountered.
|
198
|
+
* If a block is given, it is used as the block for the method call to the
|
199
|
+
* receiver.
|
238
200
|
*
|
239
|
-
* Runs a feed loop, receiving data on the given socket, feeding it to the receiver
|
240
|
-
* with the given method, and passing the receiver's output to the given block.
|
241
|
-
* The loop terminates when EOF is encountered.
|
242
|
-
*
|
243
201
|
* @param socket [Socket] socket to receive on
|
244
202
|
* @param receiver [any] an object receiving the data
|
245
203
|
* @param method [Symbol] method used to feed the data to the receiver
|
246
|
-
*
|
247
|
-
*
|
204
|
+
*
|
248
205
|
* @return [void]
|
249
206
|
*/
|
250
207
|
|
@@ -252,15 +209,12 @@ VALUE Polyphony_backend_recv_feed_loop(VALUE self, VALUE socket, VALUE receiver,
|
|
252
209
|
return Backend_recv_feed_loop(BACKEND(), socket, receiver, method);
|
253
210
|
}
|
254
211
|
|
255
|
-
/*
|
256
|
-
* Polyphony.backend_send(socket, msg, flags) -> bytes_sent
|
212
|
+
/* Sends data on the given socket, returning the number of bytes sent.
|
257
213
|
*
|
258
|
-
* Sends data on the given socket, returning the number of bytes sent.
|
259
|
-
*
|
260
214
|
* @param socket [Socket] socket to read from
|
261
215
|
* @param msg [String] data to be sent
|
262
216
|
* @param flags [Integer] Flags
|
263
|
-
*
|
217
|
+
*
|
264
218
|
* @return [Integer] number of bytes sent
|
265
219
|
*/
|
266
220
|
|
@@ -268,11 +222,8 @@ VALUE Polyphony_backend_send(VALUE self, VALUE socket, VALUE msg, VALUE flags) {
|
|
268
222
|
return Backend_send(BACKEND(), socket, msg, flags);
|
269
223
|
}
|
270
224
|
|
271
|
-
/*
|
272
|
-
* Polyphony.backend_sendmsg(socket, msg, flags, dest_sockaddr, controls) -> bytes_sent
|
225
|
+
/* Sends data on the given socket, returning the number of bytes sent.
|
273
226
|
*
|
274
|
-
* Sends data on the given socket, returning the number of bytes sent.
|
275
|
-
*
|
276
227
|
* @param socket [Socket] socket to read from
|
277
228
|
* @param msg [String] data to be sent
|
278
229
|
* @param flags [Integer] Flags
|
@@ -285,11 +236,9 @@ VALUE Polyphony_backend_sendmsg(VALUE self, VALUE socket, VALUE msg, VALUE flags
|
|
285
236
|
return Backend_sendmsg(BACKEND(), socket, msg, flags, dest_sockaddr, controls);
|
286
237
|
}
|
287
238
|
|
288
|
-
/*
|
289
|
-
*
|
239
|
+
/* Sends multiple strings on the given socket, returning the number of bytes
|
240
|
+
* sent.
|
290
241
|
*
|
291
|
-
* Sends multiple strings on the given socket, returning the number of bytes sent.
|
292
|
-
*
|
293
242
|
* @param socket [Socket] socket to read from
|
294
243
|
* @param ary [Array<String>] data to be sent
|
295
244
|
* @param flags [Integer] Flags
|
@@ -300,11 +249,8 @@ VALUE Polyphony_backend_sendv(VALUE self, VALUE socket, VALUE ary, VALUE flags)
|
|
300
249
|
return Backend_sendv(BACKEND(), socket, ary, flags);
|
301
250
|
}
|
302
251
|
|
303
|
-
/*
|
304
|
-
* Polyphony.backend_sleep(duration)
|
252
|
+
/* Sleeps for the given duration, yielding execution to other fibers.
|
305
253
|
*
|
306
|
-
* Sleeps for the given duration, yielding execution to other fibers.
|
307
|
-
*
|
308
254
|
* @param duration [Number] duration in seconds
|
309
255
|
* @return [void]
|
310
256
|
*/
|
@@ -313,12 +259,9 @@ VALUE Polyphony_backend_sleep(VALUE self, VALUE duration) {
|
|
313
259
|
return Backend_sleep(BACKEND(), duration);
|
314
260
|
}
|
315
261
|
|
316
|
-
/*
|
317
|
-
* Polyphony.backend_splice(src, dest, maxlen) -> bytes_spliced
|
318
|
-
*
|
319
|
-
* Splices data from the given source to the given destination, returning the
|
262
|
+
/* Splices data from the given source to the given destination, returning the
|
320
263
|
* number of bytes spliced.
|
321
|
-
*
|
264
|
+
*
|
322
265
|
* @param src [IO] source
|
323
266
|
* @param dest [IO] destination
|
324
267
|
* @param maxlen [Integer] Maximum bytes to splice
|
@@ -345,27 +288,26 @@ VALUE Polyphony_backend_tee(VALUE self, VALUE src, VALUE dest, VALUE chunksize)
|
|
345
288
|
}
|
346
289
|
#endif
|
347
290
|
|
348
|
-
/*
|
349
|
-
* Polyphony.backend_timeout(duration) { ... }
|
350
|
-
* Polyphony.backend_timeout(duration, exception_class) { ... }
|
351
|
-
*
|
352
|
-
* Runs the given block, raising an exception if the block has not finished
|
291
|
+
/* Runs the given block, raising an exception if the block has not finished
|
353
292
|
* running before a timeout has elapsed, using the given duration. If an
|
354
293
|
* exception class is not given, a TimeoutError is raised.
|
355
|
-
*
|
294
|
+
*
|
295
|
+
* @overload backend_timeout(duration)
|
296
|
+
* @param duration [Number] timeout duration in seconds
|
297
|
+
* @return [any] return value of block
|
298
|
+
* @overload backend_timeout(duration, exception_class)
|
299
|
+
* @param duration [Number] timeout duration in seconds
|
300
|
+
* @param exception_class [Class] exception class to raise in case of timeout
|
301
|
+
* @return [any] return value of block
|
356
302
|
*/
|
357
303
|
|
358
304
|
VALUE Polyphony_backend_timeout(int argc,VALUE *argv, VALUE self) {
|
359
305
|
return Backend_timeout(argc, argv, BACKEND());
|
360
306
|
}
|
361
307
|
|
362
|
-
/*
|
363
|
-
* Polyphony.backend_timer_loop(interval) { ... }
|
308
|
+
/* Runs an infinite loop that calls the given block at the specified time interval.
|
364
309
|
*
|
365
|
-
* Runs an infinite loop that calls the given block at the specified time interval.
|
366
|
-
*
|
367
310
|
* @param interval [Number] interval in seconds
|
368
|
-
* @yield [] code to run
|
369
311
|
* @return [void]
|
370
312
|
*/
|
371
313
|
|
@@ -373,13 +315,10 @@ VALUE Polyphony_backend_timer_loop(VALUE self, VALUE interval) {
|
|
373
315
|
return Backend_timer_loop(BACKEND(), interval);
|
374
316
|
}
|
375
317
|
|
376
|
-
/*
|
377
|
-
* Polyphony.backend_wait_event(raise)
|
378
|
-
*
|
379
|
-
* For for the current fiber to be rescheduled, resuming the fiber with its
|
318
|
+
/* For for the current fiber to be rescheduled, resuming the fiber with its
|
380
319
|
* resumed value. If raise is true and the resumed value is an exception, an
|
381
320
|
* exception will be raised.
|
382
|
-
*
|
321
|
+
*
|
383
322
|
* @param raise [boolean]
|
384
323
|
* @return [any] resumed value
|
385
324
|
*/
|
@@ -388,12 +327,9 @@ VALUE Polyphony_backend_wait_event(VALUE self, VALUE raise) {
|
|
388
327
|
return Backend_wait_event(BACKEND(), raise);
|
389
328
|
}
|
390
329
|
|
391
|
-
/*
|
392
|
-
* Polyphony.backend_wait_io(io, read_or_write)
|
393
|
-
*
|
394
|
-
* Waits for the given IO to be readable or writeable, according to the
|
330
|
+
/* Waits for the given IO to be readable or writeable, according to the
|
395
331
|
* read_or_write parameter.
|
396
|
-
*
|
332
|
+
*
|
397
333
|
* @param io [IO]
|
398
334
|
* @param write [boolean] false for read, true for write
|
399
335
|
* @return [void]
|
@@ -403,11 +339,8 @@ VALUE Polyphony_backend_wait_io(VALUE self, VALUE io, VALUE write) {
|
|
403
339
|
return Backend_wait_io(BACKEND(), io, write);
|
404
340
|
}
|
405
341
|
|
406
|
-
/*
|
407
|
-
* Polyphony.backend_wait_pid(pid) -> exit code
|
342
|
+
/* Waits for the given process to terminate, returning its exit code.
|
408
343
|
*
|
409
|
-
* Waits for the given process to terminate, returning its exit code.
|
410
|
-
*
|
411
344
|
* @param pid [Integer] pid
|
412
345
|
* @return [Integer] exit code
|
413
346
|
*/
|
@@ -416,10 +349,7 @@ VALUE Polyphony_backend_waitpid(VALUE self, VALUE pid) {
|
|
416
349
|
return Backend_waitpid(BACKEND(), pid);
|
417
350
|
}
|
418
351
|
|
419
|
-
/*
|
420
|
-
* Polyphony.backend_write(io, data, ...) -> bytes_written
|
421
|
-
*
|
422
|
-
* Writes one or more strings to the given io, returning the total number of
|
352
|
+
/* Writes one or more strings to the given io, returning the total number of
|
423
353
|
* bytes written.
|
424
354
|
*/
|
425
355
|
|
@@ -450,7 +380,7 @@ VALUE Polyphony_raw_buffer_get(int argc, VALUE *argv, VALUE self) {
|
|
450
380
|
|
451
381
|
struct buffer_spec *buffer_spec = FIX2PTR(buf);
|
452
382
|
int length = (len == Qnil) ? buffer_spec->len : FIX2INT(len);
|
453
|
-
|
383
|
+
|
454
384
|
if (length > buffer_spec->len) length = buffer_spec->len;
|
455
385
|
return rb_utf8_str_new((char *)buffer_spec->ptr, length);
|
456
386
|
}
|
@@ -462,7 +392,7 @@ VALUE Polyphony_raw_buffer_set(VALUE self, VALUE buffer, VALUE str) {
|
|
462
392
|
int len = RSTRING_LEN(str);
|
463
393
|
if (len > buffer_spec->len)
|
464
394
|
rb_raise(rb_eRuntimeError, "Given string does not fit in given buffer");
|
465
|
-
|
395
|
+
|
466
396
|
memcpy(buffer_spec->ptr, RSTRING_PTR(str), len);
|
467
397
|
buffer_spec->len = len;
|
468
398
|
return self;
|
@@ -504,7 +434,7 @@ void Init_Polyphony(void) {
|
|
504
434
|
rb_define_singleton_method(mPolyphony, "backend_sendv", Polyphony_backend_sendv, 3);
|
505
435
|
rb_define_singleton_method(mPolyphony, "backend_sleep", Polyphony_backend_sleep, 1);
|
506
436
|
rb_define_singleton_method(mPolyphony, "backend_splice", Polyphony_backend_splice, 3);
|
507
|
-
|
437
|
+
|
508
438
|
#ifdef POLYPHONY_BACKEND_LIBURING
|
509
439
|
rb_define_singleton_method(mPolyphony, "backend_double_splice", Polyphony_backend_double_splice, 2);
|
510
440
|
#endif
|
@@ -512,7 +442,7 @@ void Init_Polyphony(void) {
|
|
512
442
|
#ifdef POLYPHONY_LINUX
|
513
443
|
rb_define_singleton_method(mPolyphony, "backend_tee", Polyphony_backend_tee, 3);
|
514
444
|
#endif
|
515
|
-
|
445
|
+
|
516
446
|
rb_define_singleton_method(mPolyphony, "backend_timeout", Polyphony_backend_timeout, -1);
|
517
447
|
rb_define_singleton_method(mPolyphony, "backend_timer_loop", Polyphony_backend_timer_loop, 1);
|
518
448
|
rb_define_singleton_method(mPolyphony, "backend_wait_event", Polyphony_backend_wait_event, 1);
|
data/ext/polyphony/queue.c
CHANGED
@@ -61,16 +61,16 @@ static VALUE Queue_allocate(VALUE klass) {
|
|
61
61
|
#define GetQueue(obj, queue) \
|
62
62
|
TypedData_Get_Struct((obj), Queue_t, &Queue_type, (queue))
|
63
63
|
|
64
|
-
/*
|
65
|
-
* Queue.new -> queue
|
66
|
-
* Queue.new(capacity) -> queue
|
67
|
-
*
|
68
|
-
* Initializes a queue instance. If the capacity is given, the queue becomes
|
64
|
+
/* Initializes a queue instance. If the capacity is given, the queue becomes
|
69
65
|
* capped, i.e. it cannot contain more elements than its capacity. When trying
|
70
66
|
* to add items to a capped queue that is full, the current fiber will block
|
71
67
|
* until at least one item is removed from the queue.
|
72
|
-
*
|
73
|
-
* @
|
68
|
+
*
|
69
|
+
* @overload new()
|
70
|
+
* @return [void]
|
71
|
+
* @overload new(capacity)
|
72
|
+
* @param capacity [Integer] maximum items in queue
|
73
|
+
* @return [void]
|
74
74
|
*/
|
75
75
|
|
76
76
|
static VALUE Queue_initialize(int argc, VALUE *argv, VALUE self) {
|
@@ -131,7 +131,7 @@ static inline void capped_queue_block_push(Queue_t *queue) {
|
|
131
131
|
*
|
132
132
|
* Adds the given value to the queue's end. If the queue is capped and full, the
|
133
133
|
* call will block until a value is removed from the queue.
|
134
|
-
*
|
134
|
+
*
|
135
135
|
* @param value [any] value to be added to the queue
|
136
136
|
* @return [Queue] self
|
137
137
|
*/
|
@@ -151,12 +151,9 @@ VALUE Queue_push(VALUE self, VALUE value) {
|
|
151
151
|
return self;
|
152
152
|
}
|
153
153
|
|
154
|
-
/*
|
155
|
-
* queue.unshift(value) -> queue
|
156
|
-
*
|
157
|
-
* Adds the given value to the queue's beginning. If the queue is capped and
|
154
|
+
/* Adds the given value to the queue's beginning. If the queue is capped and
|
158
155
|
* full, the call will block until a value is removed from the queue.
|
159
|
-
*
|
156
|
+
*
|
160
157
|
* @param value [any] value to be added to the queue
|
161
158
|
* @return [Queue] self
|
162
159
|
*/
|
@@ -230,6 +227,7 @@ VALUE Queue_shift_block(Queue_t *queue) {
|
|
230
227
|
* the queue is empty, a ThreadError exception is raised. In blocking mode, if
|
231
228
|
* the queue is empty, the call will block until an item is added to the queue.
|
232
229
|
*
|
230
|
+
* @param nonblock [boolean] non-blocking mode
|
233
231
|
* @return [any] first value in queue
|
234
232
|
*/
|
235
233
|
|
@@ -243,10 +241,7 @@ VALUE Queue_shift(int argc,VALUE *argv, VALUE self) {
|
|
243
241
|
Queue_shift_block(queue);
|
244
242
|
}
|
245
243
|
|
246
|
-
/*
|
247
|
-
* queue.delete(value) -> queue
|
248
|
-
*
|
249
|
-
* Removes the given value from the queue.
|
244
|
+
/* Removes the given value from the queue.
|
250
245
|
*
|
251
246
|
* @return [Queue] self
|
252
247
|
*/
|
@@ -263,10 +258,7 @@ VALUE Queue_delete(VALUE self, VALUE value) {
|
|
263
258
|
return self;
|
264
259
|
}
|
265
260
|
|
266
|
-
/*
|
267
|
-
* queue.cap(capacity) -> queue
|
268
|
-
*
|
269
|
-
* Sets the capacity for the queue to the given value. If 0 or nil is given, the
|
261
|
+
/* Sets the capacity for the queue to the given value. If 0 or nil is given, the
|
270
262
|
* queue becomes uncapped.
|
271
263
|
*
|
272
264
|
* @param cap [Integer, nil] new capacity
|
@@ -287,10 +279,7 @@ VALUE Queue_cap(VALUE self, VALUE cap) {
|
|
287
279
|
return self;
|
288
280
|
}
|
289
281
|
|
290
|
-
/*
|
291
|
-
* queue.capped? -> bool
|
292
|
-
*
|
293
|
-
* Returns true if the queue is capped.
|
282
|
+
/* Returns true if the queue is capped.
|
294
283
|
*
|
295
284
|
* @return [boolean] is the queue capped
|
296
285
|
*/
|
@@ -302,10 +291,7 @@ VALUE Queue_capped_p(VALUE self) {
|
|
302
291
|
return queue->capacity ? INT2FIX(queue->capacity) : Qnil;
|
303
292
|
}
|
304
293
|
|
305
|
-
/*
|
306
|
-
* queue.clear -> queue
|
307
|
-
*
|
308
|
-
* Removes all values from the queue.
|
294
|
+
/* Removes all values from the queue.
|
309
295
|
*
|
310
296
|
* @return [Queue] self
|
311
297
|
*/
|
@@ -327,13 +313,10 @@ long Queue_len(VALUE self) {
|
|
327
313
|
return queue->values.count;
|
328
314
|
}
|
329
315
|
|
330
|
-
/*
|
331
|
-
* queue.shift_each { |value| do_something(value) } -> queue
|
332
|
-
*
|
333
|
-
* Iterates over all values in the queue, removing each item and passing it to
|
316
|
+
/* Iterates over all values in the queue, removing each item and passing it to
|
334
317
|
* the given block.
|
335
318
|
*
|
336
|
-
* @yield [any]
|
319
|
+
* @yield [any] removed item
|
337
320
|
* @return [Queue] self
|
338
321
|
*/
|
339
322
|
|
@@ -346,10 +329,7 @@ VALUE Queue_shift_each(VALUE self) {
|
|
346
329
|
return self;
|
347
330
|
}
|
348
331
|
|
349
|
-
/*
|
350
|
-
* queue.shift_all -> array
|
351
|
-
*
|
352
|
-
* Returns all values currently in the queue, clearing the queue.
|
332
|
+
/* Returns all values currently in the queue, clearing the queue.
|
353
333
|
*
|
354
334
|
* @return [Array] all values
|
355
335
|
*/
|
@@ -365,10 +345,7 @@ VALUE Queue_shift_all(VALUE self) {
|
|
365
345
|
return result;
|
366
346
|
}
|
367
347
|
|
368
|
-
/*
|
369
|
-
* queue.flush_waiters -> queue
|
370
|
-
*
|
371
|
-
* Flushes all fibers currently blocked waiting to remove items from the queue,
|
348
|
+
/* Flushes all fibers currently blocked waiting to remove items from the queue,
|
372
349
|
* resuming them with the given value.
|
373
350
|
*
|
374
351
|
* @param value [any] value to resome all waiting fibers with
|
@@ -389,10 +366,7 @@ VALUE Queue_flush_waiters(VALUE self, VALUE value) {
|
|
389
366
|
return self;
|
390
367
|
}
|
391
368
|
|
392
|
-
/*
|
393
|
-
* queue.empty? -> bool
|
394
|
-
*
|
395
|
-
* Returns true if the queue is empty.
|
369
|
+
/* Returns true if the queue is empty.
|
396
370
|
*
|
397
371
|
* @return [boolean]
|
398
372
|
*/
|
@@ -404,10 +378,7 @@ VALUE Queue_empty_p(VALUE self) {
|
|
404
378
|
return (!queue->values.count) ? Qtrue : Qfalse;
|
405
379
|
}
|
406
380
|
|
407
|
-
/*
|
408
|
-
* queue.pending? -> bool
|
409
|
-
*
|
410
|
-
* Returns true if any fibers are currently waiting to remove items from the
|
381
|
+
/* Returns true if any fibers are currently waiting to remove items from the
|
411
382
|
* queue.
|
412
383
|
*
|
413
384
|
* @return [boolean]
|
@@ -420,10 +391,7 @@ VALUE Queue_pending_p(VALUE self) {
|
|
420
391
|
return (queue->shift_queue.count) ? Qtrue : Qfalse;
|
421
392
|
}
|
422
393
|
|
423
|
-
/*
|
424
|
-
* queue.num_waiting -> integer
|
425
|
-
*
|
426
|
-
* Returns the number of fibers currently waiting to remove items from the
|
394
|
+
/* Returns the number of fibers currently waiting to remove items from the
|
427
395
|
* queue.
|
428
396
|
*
|
429
397
|
* @return [Integer]
|
@@ -438,7 +406,7 @@ VALUE Queue_num_waiting(VALUE self) {
|
|
438
406
|
|
439
407
|
/* call-seq:
|
440
408
|
* queue.size -> integer
|
441
|
-
* queue.length -> integer
|
409
|
+
* queue.length -> integer
|
442
410
|
*
|
443
411
|
* Returns the number of values currently in the queue.
|
444
412
|
*
|
@@ -452,10 +420,7 @@ VALUE Queue_size_m(VALUE self) {
|
|
452
420
|
return INT2FIX(queue->values.count);
|
453
421
|
}
|
454
422
|
|
455
|
-
/*
|
456
|
-
* queue.closed? -> bool
|
457
|
-
*
|
458
|
-
* Returns true if the queue has been closed.
|
423
|
+
/* Returns true if the queue has been closed.
|
459
424
|
*
|
460
425
|
* @return [boolean]
|
461
426
|
*/
|
@@ -467,10 +432,7 @@ VALUE Queue_closed_p(VALUE self) {
|
|
467
432
|
return (queue->closed) ? Qtrue : Qfalse;
|
468
433
|
}
|
469
434
|
|
470
|
-
/*
|
471
|
-
* queue.close -> queue
|
472
|
-
*
|
473
|
-
* Marks the queue as closed. Any fibers currently waiting on the queue are
|
435
|
+
/* Marks the queue as closed. Any fibers currently waiting on the queue are
|
474
436
|
* resumed with a `nil` value. After the queue is closed, trying to remove items
|
475
437
|
* from the queue will cause a `ClosedQueueError` to be raised.
|
476
438
|
*
|
data/ext/polyphony/thread.c
CHANGED
@@ -19,11 +19,8 @@ inline void schedule_fiber(VALUE self, VALUE fiber, VALUE value, int prioritize)
|
|
19
19
|
Backend_schedule_fiber(self, rb_ivar_get(self, ID_ivar_backend), fiber, value, prioritize);
|
20
20
|
}
|
21
21
|
|
22
|
-
/*
|
23
|
-
* thread.unschedule_fiber(fiber)
|
22
|
+
/* Removes the given fiber from the thread's runqueue.
|
24
23
|
*
|
25
|
-
* Removes the given fiber from the thread's runqueue.
|
26
|
-
*
|
27
24
|
* @param fiber [Fiber] fiber to unschedule
|
28
25
|
* @return [Thread] self
|
29
26
|
*/
|
@@ -45,11 +42,8 @@ inline void Thread_schedule_fiber_with_priority(VALUE self, VALUE fiber, VALUE v
|
|
45
42
|
// schedule_fiber(self, fiber, value, 1);
|
46
43
|
}
|
47
44
|
|
48
|
-
/*
|
49
|
-
* thread.switch_fiber()
|
45
|
+
/* Switches to the next fiber in the thread's runqueue.
|
50
46
|
*
|
51
|
-
* Switches to the next fiber in the thread's runqueue.
|
52
|
-
*
|
53
47
|
* @return [void]
|
54
48
|
*/
|
55
49
|
|
@@ -80,11 +74,8 @@ VALUE Thread_debug(VALUE self) {
|
|
80
74
|
return self;
|
81
75
|
}
|
82
76
|
|
83
|
-
/*
|
84
|
-
* Thread.backend
|
77
|
+
/* Returns the backend for the current thread.
|
85
78
|
*
|
86
|
-
* Returns the backend for the current thread.
|
87
|
-
*
|
88
79
|
* @return [Polyphony::Backend] backend for the current thread
|
89
80
|
*/
|
90
81
|
|