Class: UringMachine
- Inherits:
-
Object
show all
- Defined in:
- lib/uringmachine.rb,
lib/uringmachine/actor.rb,
lib/uringmachine/version.rb,
lib/uringmachine/dns_resolver.rb,
lib/uringmachine/fiber_scheduler.rb,
ext/um/um_class.c
Defined Under Namespace
Modules: FiberExtensions, ThreadExtensions
Classes: Actor, AsyncOp, BlockingOperationThreadPool, DNSResolver, Error, FiberScheduler, Mutex, Queue, Stream, Terminate
Constant Summary
collapse
- VERSION =
'0.23.1'
- @@fiber_map =
{}
Class Method Summary
collapse
Instance Method Summary
collapse
-
#accept(fd) ⇒ Object
-
#accept_each(fd) ⇒ Object
-
#accept_into_queue(fd, queue) ⇒ Object
-
#await_fibers(fibers) ⇒ Object
-
#bind(fd, host, port) ⇒ Object
-
#close(fd) ⇒ Object
-
#close_async(fd) ⇒ Object
-
#connect(fd, host, port) ⇒ Object
-
#fiber_map ⇒ Object
-
#getsockopt(fd, level, opt) ⇒ Object
-
#initialize(*args) ⇒ Object
constructor
-
#join(*fibers) ⇒ Object
-
#listen(fd, backlog) ⇒ Object
-
#mark(mark) ⇒ Object
-
#metrics ⇒ Object
-
#open(pathname, flags) ⇒ Object
-
#pending_fibers ⇒ Object
-
#periodically(interval) ⇒ Object
-
#poll(fd, mask) ⇒ Object
-
#pop(queue) ⇒ Object
-
#prep_timeout(interval) ⇒ Object
-
#profile(value) ⇒ Object
-
#profile? ⇒ Boolean
-
#push(queue, value) ⇒ Object
-
#read(*args) ⇒ Object
-
#read_each(fd, bgid) ⇒ Object
-
#recv(fd, buffer, maxlen, flags) ⇒ Object
-
#recv_each(fd, bgid, flags) ⇒ Object
-
#resolve(hostname, type = :A) ⇒ Object
-
#run(fiber, &block) ⇒ Object
-
#schedule(fiber, value) ⇒ Object
-
#select(rfds, wfds, efds) ⇒ Object
-
#send(fd, buffer, len, flags) ⇒ Object
-
#send_bundle(*args) ⇒ Object
-
#sendv(*args) ⇒ Object
-
#setsockopt(fd, level, opt, value) ⇒ Object
-
#setup_buffer_ring(size, count) ⇒ Object
-
#shift(queue) ⇒ Object
-
#shutdown(fd, how) ⇒ Object
-
#shutdown_async(fd, how) ⇒ Object
-
#size ⇒ Object
-
#sleep(duration) ⇒ Object
-
#snooze ⇒ Object
-
#socket(domain, type, protocol, flags) ⇒ Object
-
#spin(value = nil, klass = Fiber, &block) ⇒ Object
-
#spin_actor(mod, *a, **k) ⇒ Object
-
#spin_thread_actor(mod, *a, **k) ⇒ Object
-
#statx(dirfd, path, flags, mask) ⇒ Object
-
#submit ⇒ Object
-
#switch ⇒ Object
-
#synchronize(mutex) ⇒ Object
-
#timeout(interval, class) ⇒ Object
-
#unshift(queue, value) ⇒ Object
-
#waitid(idtype, id, options) ⇒ Object
-
#waitid_status(idtype, id, options) ⇒ Object
-
#wakeup ⇒ Object
-
#write(*args) ⇒ Object
-
#write_async(*args) ⇒ Object
-
#writev(*args) ⇒ Object
-
#yield ⇒ Object
Constructor Details
#initialize(*args) ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'ext/um/um_class.c', line 88
VALUE UM_initialize(int argc, VALUE *argv, VALUE self) {
struct um *machine = RTYPEDDATA_DATA(self);
VALUE entries;
VALUE sqpoll_timeout;
rb_scan_args(argc, argv, "02", &entries, &sqpoll_timeout);
uint entries_i = NIL_P(entries) ? 0 : NUM2UINT(entries);
uint sqpoll_timeout_msec = get_sqpoll_timeout_msec(sqpoll_timeout);
um_setup(self, machine, entries_i, sqpoll_timeout_msec);
return self;
}
|
Class Method Details
.debug(str) ⇒ Object
569
570
571
572
|
# File 'ext/um/um_class.c', line 569
VALUE UM_debug(VALUE self, VALUE str) {
fprintf(stderr, "%s\n", StringValueCStr(str));
return Qnil;
}
|
.io_nonblock?(io) ⇒ Boolean
537
538
539
540
541
542
543
|
# File 'ext/um/um_class.c', line 537
VALUE UM_io_nonblock_p(VALUE self, VALUE io) {
int fd = rb_io_descriptor(io);
int oflags = fcntl(fd, F_GETFL);
if (oflags == -1) return Qnil;
return (oflags & O_NONBLOCK) ? Qtrue : Qfalse;
}
|
.io_set_nonblock(io, nonblock) ⇒ Object
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
|
# File 'ext/um/um_class.c', line 545
VALUE UM_io_set_nonblock(VALUE self, VALUE io, VALUE nonblock) {
int fd = rb_io_descriptor(io);
int oflags = fcntl(fd, F_GETFL);
if (oflags == -1) return Qnil;
if (RTEST(nonblock)) {
if (!(oflags & O_NONBLOCK)) {
oflags |= O_NONBLOCK;
fcntl(fd, F_SETFL, oflags);
}
}
else {
if (oflags & O_NONBLOCK) {
oflags &= ~O_NONBLOCK;
fcntl(fd, F_SETFL, oflags);
}
}
return nonblock;
}
|
.kernel_version ⇒ Object
565
566
567
|
# File 'ext/um/um_class.c', line 565
VALUE UM_kernel_version(VALUE self) {
return INT2NUM(UM_KERNEL_VERSION);
}
|
.pidfd_open(pid) ⇒ Object
515
516
517
518
519
520
521
522
523
|
# File 'ext/um/um_class.c', line 515
VALUE UM_pidfd_open(VALUE self, VALUE pid) {
int fd = syscall(SYS_pidfd_open, NUM2INT(pid), 0);
if (fd == -1) {
int e = errno;
rb_syserr_fail(e, strerror(e));
}
return INT2NUM(fd);
}
|
.pidfd_send_signal(fd, sig) ⇒ Object
525
526
527
528
529
530
531
532
533
534
535
|
# File 'ext/um/um_class.c', line 525
VALUE UM_pidfd_send_signal(VALUE self, VALUE fd, VALUE sig) {
int ret = syscall(
SYS_pidfd_send_signal, NUM2INT(fd), NUM2INT(sig), NULL, 0
);
if (ret) {
int e = errno;
rb_syserr_fail(e, strerror(e));
}
return fd;
}
|
.pipe ⇒ Object
493
494
495
496
497
498
499
500
501
502
|
# File 'ext/um/um_class.c', line 493
VALUE UM_pipe(VALUE self) {
int fds[2];
int ret = pipe(fds);
if (ret) {
int e = errno;
rb_syserr_fail(e, strerror(e));
}
return rb_ary_new_from_args(2, INT2NUM(fds[0]), INT2NUM(fds[1]));
}
|
.socketpair(domain, type, protocol) ⇒ Object
504
505
506
507
508
509
510
511
512
513
|
# File 'ext/um/um_class.c', line 504
VALUE UM_socketpair(VALUE self, VALUE domain, VALUE type, VALUE protocol) {
int fds[2];
int ret = socketpair(NUM2INT(domain), NUM2INT(type), NUM2INT(protocol), fds);
if (ret) {
int e = errno;
rb_syserr_fail(e, strerror(e));
}
return rb_ary_new_from_args(2, INT2NUM(fds[0]), INT2NUM(fds[1]));
}
|
Instance Method Details
#accept(fd) ⇒ Object
277
278
279
280
|
# File 'ext/um/um_class.c', line 277
VALUE UM_accept(VALUE self, VALUE fd) {
struct um *machine = um_get_machine(self);
return um_accept(machine, NUM2INT(fd));
}
|
#accept_each(fd) ⇒ Object
282
283
284
285
|
# File 'ext/um/um_class.c', line 282
VALUE UM_accept_each(VALUE self, VALUE fd) {
struct um *machine = um_get_machine(self);
return um_accept_each(machine, NUM2INT(fd));
}
|
#accept_into_queue(fd, queue) ⇒ Object
287
288
289
290
|
# File 'ext/um/um_class.c', line 287
VALUE UM_accept_into_queue(VALUE self, VALUE fd, VALUE queue) {
struct um *machine = um_get_machine(self);
return um_accept_into_queue(machine, NUM2INT(fd), queue);
}
|
#await_fibers(fibers) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/uringmachine.rb', line 56
def await_fibers(fibers)
if fibers.is_a?(Fiber)
f = fibers
if !f.done?
queue = Fiber.current.mailbox
f.add_done_listener(queue)
self.shift(queue)
end
return 1
end
queue = nil
pending = nil
fibers.each do |f|
if !f.done?
(pending ||= []) << f
queue ||= Fiber.current.mailbox
f.add_done_listener(queue)
end
end
if pending
while !pending.empty?
f = self.shift(queue)
pending.delete(f)
end
end
fibers.count
end
|
#bind(fd, host, port) ⇒ Object
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
|
# File 'ext/um/um_class.c', line 362
VALUE UM_bind(VALUE self, VALUE fd, VALUE host, VALUE port) {
struct sockaddr_in addr;
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = inet_addr(StringValueCStr(host));
addr.sin_port = htons(NUM2INT(port));
#ifdef HAVE_IO_URING_PREP_BIND
struct um *machine = um_get_machine(self);
return um_bind(machine, NUM2INT(fd), (struct sockaddr *)&addr, sizeof(addr));
#else
int res = bind(NUM2INT(fd), (struct sockaddr *)&addr, sizeof(addr));
if (res)
rb_syserr_fail(errno, strerror(errno));
return INT2NUM(0);
#endif
}
|
#close(fd) ⇒ Object
267
268
269
270
|
# File 'ext/um/um_class.c', line 267
VALUE UM_close(VALUE self, VALUE fd) {
struct um *machine = um_get_machine(self);
return um_close(machine, NUM2INT(fd));
}
|
#close_async(fd) ⇒ Object
272
273
274
275
|
# File 'ext/um/um_class.c', line 272
VALUE UM_close_async(VALUE self, VALUE fd) {
struct um *machine = um_get_machine(self);
return um_close_async(machine, NUM2INT(fd));
}
|
#connect(fd, host, port) ⇒ Object
307
308
309
310
311
312
313
314
315
316
317
|
# File 'ext/um/um_class.c', line 307
VALUE UM_connect(VALUE self, VALUE fd, VALUE host, VALUE port) {
struct um *machine = um_get_machine(self);
struct sockaddr_in addr;
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = inet_addr(StringValueCStr(host));
addr.sin_port = htons(NUM2INT(port));
return um_connect(machine, NUM2INT(fd), (struct sockaddr *)&addr, sizeof(addr));
}
|
#fiber_map ⇒ Object
12
13
14
|
# File 'lib/uringmachine.rb', line 12
def fiber_map
@@fiber_map
end
|
#getsockopt(fd, level, opt) ⇒ Object
403
404
405
406
|
# File 'ext/um/um_class.c', line 403
VALUE UM_getsockopt(VALUE self, VALUE fd, VALUE level, VALUE opt) {
struct um *machine = um_get_machine(self);
return um_getsockopt(machine, NUM2INT(fd), NUM2INT(level), NUM2INT(opt));
}
|
#join(*fibers) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/uringmachine.rb', line 32
def join(*fibers)
results = fibers.inject({}) { |h, f| h[f] = nil; h }
queue = nil
pending = nil
fibers.each do |f|
if f.done?
results[f] = f.result
else
(pending ||= []) << f
queue ||= Fiber.current.mailbox
f.add_done_listener(queue)
end
end
if pending
while !pending.empty?
f = self.shift(queue)
pending.delete(f)
results[f] = f.result
end
end
values = results.values
fibers.size == 1 ? values.first : values
end
|
#listen(fd, backlog) ⇒ Object
380
381
382
383
384
385
386
387
388
389
390
|
# File 'ext/um/um_class.c', line 380
VALUE UM_listen(VALUE self, VALUE fd, VALUE backlog) {
#ifdef HAVE_IO_URING_PREP_LISTEN
struct um *machine = um_get_machine(self);
return um_listen(machine, NUM2INT(fd), NUM2INT(backlog));
#else
int res = listen(NUM2INT(fd), NUM2INT(backlog));
if (res)
rb_syserr_fail(errno, strerror(errno));
return INT2NUM(0);
#endif
}
|
#mark(mark) ⇒ Object
113
114
115
116
117
|
# File 'ext/um/um_class.c', line 113
VALUE UM_mark_m(VALUE self, VALUE mark) {
struct um *machine = um_get_machine(self);
machine->mark = NUM2UINT(mark);
return self;
}
|
#metrics ⇒ Object
119
120
121
122
|
# File 'ext/um/um_class.c', line 119
VALUE UM_metrics(VALUE self) {
struct um *machine = um_get_machine(self);
return um_metrics(machine, &machine->metrics);
}
|
#open(pathname, flags) ⇒ Object
454
455
456
457
458
459
460
461
462
463
464
|
# File 'ext/um/um_class.c', line 454
VALUE UM_open(VALUE self, VALUE pathname, VALUE flags) {
struct um *machine = um_get_machine(self);
// TODO: take optional perm (mode) arg
VALUE fd = um_open(machine, pathname, NUM2INT(flags), 0666);
if (rb_block_given_p()) {
struct um_open_ctx ctx = { self, fd };
return rb_ensure(rb_yield, fd, UM_open_complete, (VALUE)&ctx);
}
else
return fd;
}
|
#pending_fibers ⇒ Object
177
178
179
180
|
# File 'ext/um/um_class.c', line 177
VALUE UM_pending_fibers(VALUE self) {
struct um *machine = um_get_machine(self);
return machine->pending_fibers;
}
|
#periodically(interval) ⇒ Object
198
199
200
201
|
# File 'ext/um/um_class.c', line 198
VALUE UM_periodically(VALUE self, VALUE interval) {
struct um *machine = um_get_machine(self);
return um_periodically(machine, NUM2DBL(interval));
}
|
#poll(fd, mask) ⇒ Object
466
467
468
469
|
# File 'ext/um/um_class.c', line 466
VALUE UM_poll(VALUE self, VALUE fd, VALUE mask) {
struct um *machine = um_get_machine(self);
return um_poll(machine, NUM2INT(fd), NUM2UINT(mask));
}
|
#pop(queue) ⇒ Object
425
426
427
428
429
|
# File 'ext/um/um_class.c', line 425
VALUE UM_queue_pop(VALUE self, VALUE queue) {
struct um *machine = um_get_machine(self);
struct um_queue *que = Queue_data(queue);
return um_queue_pop(machine, que);
}
|
#prep_timeout(interval) ⇒ Object
488
489
490
491
|
# File 'ext/um/um_class.c', line 488
VALUE UM_prep_timeout(VALUE self, VALUE interval) {
struct um *machine = um_get_machine(self);
return um_prep_timeout(machine, NUM2DBL(interval));
}
|
#profile(value) ⇒ Object
129
130
131
132
133
134
135
136
137
|
# File 'ext/um/um_class.c', line 129
VALUE UM_profile_set(VALUE self, VALUE value) {
struct um *machine = um_get_machine(self);
machine->profile_mode = RTEST(value);
if (machine->profile_mode) {
machine->metrics.time_total_wait = 0.0;
machine->metrics.time_last_cpu = machine->metrics.time_first_cpu = um_get_time_cpu();
}
return value;
}
|
#profile? ⇒ Boolean
124
125
126
127
|
# File 'ext/um/um_class.c', line 124
VALUE UM_profile_p(VALUE self) {
struct um *machine = um_get_machine(self);
return machine->profile_mode ? Qtrue : Qfalse;
}
|
#push(queue, value) ⇒ Object
419
420
421
422
423
|
# File 'ext/um/um_class.c', line 419
VALUE UM_queue_push(VALUE self, VALUE queue, VALUE value) {
struct um *machine = um_get_machine(self);
struct um_queue *que = Queue_data(queue);
return um_queue_push(machine, que, value);
}
|
#read(*args) ⇒ Object
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
# File 'ext/um/um_class.c', line 203
VALUE UM_read(int argc, VALUE *argv, VALUE self) {
struct um *machine = um_get_machine(self);
VALUE fd;
VALUE buffer;
VALUE maxlen;
VALUE buffer_offset;
VALUE file_offset;
rb_scan_args(argc, argv, "23", &fd, &buffer, &maxlen, &buffer_offset, &file_offset);
ssize_t maxlen_i = NIL_P(maxlen) ? -1 : NUM2INT(maxlen);
ssize_t buffer_offset_i = NIL_P(buffer_offset) ? 0 : NUM2INT(buffer_offset);
__u64 file_offset_i = NIL_P(file_offset) ? (__u64)-1 : NUM2UINT(file_offset);
return um_read(machine, NUM2INT(fd), buffer, maxlen_i, buffer_offset_i, file_offset_i);
}
|
#read_each(fd, bgid) ⇒ Object
219
220
221
222
|
# File 'ext/um/um_class.c', line 219
VALUE UM_read_each(VALUE self, VALUE fd, VALUE bgid) {
struct um *machine = um_get_machine(self);
return um_read_each(machine, NUM2INT(fd), NUM2INT(bgid));
}
|
#recv(fd, buffer, maxlen, flags) ⇒ Object
352
353
354
355
|
# File 'ext/um/um_class.c', line 352
VALUE UM_recv(VALUE self, VALUE fd, VALUE buffer, VALUE maxlen, VALUE flags) {
struct um *machine = um_get_machine(self);
return um_recv(machine, NUM2INT(fd), buffer, NUM2INT(maxlen), NUM2INT(flags));
}
|
#recv_each(fd, bgid, flags) ⇒ Object
357
358
359
360
|
# File 'ext/um/um_class.c', line 357
VALUE UM_recv_each(VALUE self, VALUE fd, VALUE bgid, VALUE flags) {
struct um *machine = um_get_machine(self);
return um_recv_each(machine, NUM2INT(fd), NUM2INT(bgid), NUM2INT(flags));
}
|
#resolve(hostname, type = :A) ⇒ Object
85
86
87
88
|
# File 'lib/uringmachine.rb', line 85
def resolve(hostname, type = :A)
@resolver ||= DNSResolver.new(self)
@resolver.resolve(hostname, type)
end
|
#run(fiber, &block) ⇒ Object
26
27
28
29
30
|
# File 'lib/uringmachine.rb', line 26
def run(fiber, &block)
run_block_in_fiber(block, fiber, nil)
self.schedule(fiber, nil)
@@fiber_map[fiber] = fiber
end
|
#schedule(fiber, value) ⇒ Object
182
183
184
185
186
|
# File 'ext/um/um_class.c', line 182
VALUE UM_schedule(VALUE self, VALUE fiber, VALUE value) {
struct um *machine = um_get_machine(self);
um_schedule(machine, fiber, value);
return self;
}
|
#select(rfds, wfds, efds) ⇒ Object
471
472
473
474
|
# File 'ext/um/um_class.c', line 471
VALUE UM_select(VALUE self, VALUE rfds, VALUE wfds, VALUE efds) {
struct um *machine = um_get_machine(self);
return um_select(machine, rfds, wfds, efds);
}
|
#send(fd, buffer, len, flags) ⇒ Object
319
320
321
322
|
# File 'ext/um/um_class.c', line 319
VALUE UM_send(VALUE self, VALUE fd, VALUE buffer, VALUE len, VALUE flags) {
struct um *machine = um_get_machine(self);
return um_send(machine, NUM2INT(fd), buffer, NUM2INT(len), NUM2INT(flags));
}
|
#send_bundle(*args) ⇒ Object
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
|
# File 'ext/um/um_class.c', line 336
VALUE UM_send_bundle(int argc, VALUE *argv, VALUE self) {
struct um *machine = um_get_machine(self);
VALUE fd;
VALUE bgid;
VALUE strings;
rb_scan_args(argc, argv, "2*", &fd, &bgid, &strings);
if (RARRAY_LEN(strings) == 1) {
VALUE first = rb_ary_entry(strings, 0);
if (TYPE(first) == T_ARRAY)
strings = first;
}
return um_send_bundle(machine, NUM2INT(fd), NUM2INT(bgid), strings);
}
|
#sendv(*args) ⇒ Object
325
326
327
328
329
330
331
332
333
|
# File 'ext/um/um_class.c', line 325
VALUE UM_sendv(int argc, VALUE *argv, VALUE self) {
struct um *machine = um_get_machine(self);
if (argc < 1)
rb_raise(rb_eArgError, "wrong number of arguments (given 0, expected 1+)");
int fd = NUM2INT(argv[0]);
if (argc < 2) return INT2NUM(0);
return um_sendv(machine, fd, argc - 1, argv + 1);
}
|
#setsockopt(fd, level, opt, value) ⇒ Object
408
409
410
411
|
# File 'ext/um/um_class.c', line 408
VALUE UM_setsockopt(VALUE self, VALUE fd, VALUE level, VALUE opt, VALUE value) {
struct um *machine = um_get_machine(self);
return um_setsockopt(machine, NUM2INT(fd), NUM2INT(level), NUM2INT(opt), numeric_value(value));
}
|
#setup_buffer_ring(size, count) ⇒ Object
102
103
104
105
106
|
# File 'ext/um/um_class.c', line 102
VALUE UM_setup_buffer_ring(VALUE self, VALUE size, VALUE count) {
struct um *machine = um_get_machine(self);
int bgid = um_setup_buffer_ring(machine, NUM2UINT(size), NUM2UINT(count));
return INT2NUM(bgid);
}
|
#shift(queue) ⇒ Object
437
438
439
440
441
|
# File 'ext/um/um_class.c', line 437
VALUE UM_queue_shift(VALUE self, VALUE queue) {
struct um *machine = um_get_machine(self);
struct um_queue *que = Queue_data(queue);
return um_queue_shift(machine, que);
}
|
#shutdown(fd, how) ⇒ Object
297
298
299
300
|
# File 'ext/um/um_class.c', line 297
VALUE UM_shutdown(VALUE self, VALUE fd, VALUE how) {
struct um *machine = um_get_machine(self);
return um_shutdown(machine, NUM2INT(fd), NUM2INT(how));
}
|
#shutdown_async(fd, how) ⇒ Object
302
303
304
305
|
# File 'ext/um/um_class.c', line 302
VALUE UM_shutdown_async(VALUE self, VALUE fd, VALUE how) {
struct um *machine = um_get_machine(self);
return um_shutdown_async(machine, NUM2INT(fd), NUM2INT(how));
}
|
#size ⇒ Object
108
109
110
111
|
# File 'ext/um/um_class.c', line 108
VALUE UM_size(VALUE self) {
struct um *machine = um_get_machine(self);
return UINT2NUM(machine->size);
}
|
#sleep(duration) ⇒ Object
193
194
195
196
|
# File 'ext/um/um_class.c', line 193
VALUE UM_sleep(VALUE self, VALUE duration) {
struct um *machine = um_get_machine(self);
return um_sleep(machine, NUM2DBL(duration));
}
|
#snooze ⇒ Object
139
140
141
142
143
144
145
146
147
148
|
# File 'ext/um/um_class.c', line 139
VALUE UM_snooze(VALUE self) {
struct um *machine = um_get_machine(self);
um_schedule(machine, rb_fiber_current(), Qnil);
// the current fiber is already scheduled, and the runqueue is GC-marked, so
// we can safely call um_switch, which is faster than calling um_yield.
VALUE ret = um_switch(machine);
RAISE_IF_EXCEPTION(ret);
return ret;
}
|
#socket(domain, type, protocol, flags) ⇒ Object
292
293
294
295
|
# File 'ext/um/um_class.c', line 292
VALUE UM_socket(VALUE self, VALUE domain, VALUE type, VALUE protocol, VALUE flags) {
struct um *machine = um_get_machine(self);
return um_socket(machine, NUM2INT(domain), NUM2INT(type), NUM2INT(protocol), NUM2UINT(flags));
}
|
#spin(value = nil, klass = Fiber, &block) ⇒ Object
19
20
21
22
23
24
|
# File 'lib/uringmachine.rb', line 19
def spin(value = nil, klass = Fiber, &block)
fiber = klass.new { |v| run_block_in_fiber(block, fiber, v) }
self.schedule(fiber, value)
@@fiber_map[fiber] = fiber
end
|
#spin_actor(mod, *a, **k) ⇒ Object
4
5
6
7
8
9
10
11
|
# File 'lib/uringmachine/actor.rb', line 4
def spin_actor(mod, *a, **k)
target = Object.new.extend(mod)
mailbox = UM::Queue.new
actor = spin(nil, Actor) { actor.run(self, target, mailbox) }
target.setup(*a, **k)
snooze
actor
end
|
#spin_thread_actor(mod, *a, **k) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/uringmachine/actor.rb', line 13
def spin_thread_actor(mod, *a, **k)
machine = UM.new
target = Object.new.extend(mod)
mailbox = UM::Queue.new
actor = Actor.new
Thread.new do
actor.run(machine, target, mailbox)
end
target.setup(*a, **k)
snooze
actor
end
|
#statx(dirfd, path, flags, mask) ⇒ Object
262
263
264
265
|
# File 'ext/um/um_class.c', line 262
VALUE UM_statx(VALUE self, VALUE dirfd, VALUE path, VALUE flags, VALUE mask) {
struct um *machine = um_get_machine(self);
return um_statx(machine, NUM2INT(dirfd), path, NUM2INT(flags), NUM2UINT(mask));
}
|
#submit ⇒ Object
171
172
173
174
175
|
# File 'ext/um/um_class.c', line 171
VALUE UM_submit(VALUE self) {
struct um *machine = um_get_machine(self);
uint ret = um_submit(machine);
return UINT2NUM(ret);
}
|
#switch ⇒ Object
158
159
160
161
162
163
164
|
# File 'ext/um/um_class.c', line 158
VALUE UM_switch(VALUE self) {
struct um *machine = um_get_machine(self);
VALUE ret = um_switch(machine);
RAISE_IF_EXCEPTION(ret);
return ret;
}
|
#synchronize(mutex) ⇒ Object
413
414
415
416
417
|
# File 'ext/um/um_class.c', line 413
VALUE UM_mutex_synchronize(VALUE self, VALUE mutex) {
struct um *machine = um_get_machine(self);
struct um_mutex *mutex_data = Mutex_data(mutex);
return um_mutex_synchronize(machine, mutex_data);
}
|
#timeout(interval, class) ⇒ Object
188
189
190
191
|
# File 'ext/um/um_class.c', line 188
VALUE UM_timeout(VALUE self, VALUE interval, VALUE class) {
struct um *machine = um_get_machine(self);
return um_timeout(machine, interval, class);
}
|
#unshift(queue, value) ⇒ Object
431
432
433
434
435
|
# File 'ext/um/um_class.c', line 431
VALUE UM_queue_unshift(VALUE self, VALUE queue, VALUE value) {
struct um *machine = um_get_machine(self);
struct um_queue *que = Queue_data(queue);
return um_queue_unshift(machine, que, value);
}
|
#waitid(idtype, id, options) ⇒ Object
476
477
478
479
|
# File 'ext/um/um_class.c', line 476
VALUE UM_waitid(VALUE self, VALUE idtype, VALUE id, VALUE options) {
struct um *machine = um_get_machine(self);
return um_waitid(machine, NUM2INT(idtype), NUM2INT(id), NUM2INT(options));
}
|
#waitid_status(idtype, id, options) ⇒ Object
482
483
484
485
|
# File 'ext/um/um_class.c', line 482
VALUE UM_waitid_status(VALUE self, VALUE idtype, VALUE id, VALUE options) {
struct um *machine = um_get_machine(self);
return um_waitid_status(machine, NUM2INT(idtype), NUM2INT(id), NUM2INT(options));
}
|
#wakeup ⇒ Object
166
167
168
169
|
# File 'ext/um/um_class.c', line 166
VALUE UM_wakeup(VALUE self) {
struct um *machine = um_get_machine(self);
return um_wakeup(machine);
}
|
#write(*args) ⇒ Object
224
225
226
227
228
229
230
231
232
233
234
235
236
|
# File 'ext/um/um_class.c', line 224
VALUE UM_write(int argc, VALUE *argv, VALUE self) {
struct um *machine = um_get_machine(self);
VALUE fd;
VALUE buffer;
VALUE len;
VALUE file_offset;
rb_scan_args(argc, argv, "22", &fd, &buffer, &len, &file_offset);
size_t len_i = NIL_P(len) ? (size_t)-1 : NUM2UINT(len);
__u64 file_offset_i = NIL_P(file_offset) ? (__u64)-1 : NUM2UINT(file_offset);
return um_write(machine, NUM2INT(fd), buffer, len_i, file_offset_i);
}
|
#write_async(*args) ⇒ Object
248
249
250
251
252
253
254
255
256
257
258
259
260
|
# File 'ext/um/um_class.c', line 248
VALUE UM_write_async(int argc, VALUE *argv, VALUE self) {
struct um *machine = um_get_machine(self);
VALUE fd;
VALUE buffer;
VALUE len;
VALUE file_offset;
rb_scan_args(argc, argv, "22", &fd, &buffer, &len, &file_offset);
size_t len_i = NIL_P(len) ? (size_t)-1 : NUM2UINT(len);
__u64 file_offset_i = NIL_P(file_offset) ? (__u64)-1 : NUM2UINT(file_offset);
return um_write_async(machine, NUM2INT(fd), buffer, len_i, file_offset_i);
}
|
#writev(*args) ⇒ Object
238
239
240
241
242
243
244
245
246
|
# File 'ext/um/um_class.c', line 238
VALUE UM_writev(int argc, VALUE *argv, VALUE self) {
struct um *machine = um_get_machine(self);
if (argc < 1)
rb_raise(rb_eArgError, "wrong number of arguments (given 0, expected 1+)");
int fd = NUM2INT(argv[0]);
if (argc < 2) return INT2NUM(0);
return um_writev(machine, fd, argc - 1, argv + 1);
}
|
#yield ⇒ Object
150
151
152
153
154
155
156
|
# File 'ext/um/um_class.c', line 150
VALUE UM_yield(VALUE self) {
struct um *machine = um_get_machine(self);
VALUE ret = um_yield(machine);
RAISE_IF_EXCEPTION(ret);
return ret;
}
|