uringmachine 0.1 → 0.3

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.
data/ext/um/op_ctx.c DELETED
@@ -1,138 +0,0 @@
1
- #include "iou.h"
2
-
3
- VALUE cOpCtx;
4
-
5
- inline int is_read_op_p(OpCtx_t *ctx) {
6
- switch (ctx->type) {
7
- case OP_read:
8
- return 1;
9
- default:
10
- return 0;
11
- }
12
- }
13
-
14
- static void OpCtx_mark(void *ptr) {
15
- OpCtx_t *ctx = ptr;
16
- rb_gc_mark_movable(ctx->spec);
17
- rb_gc_mark_movable(ctx->proc);
18
- if (is_read_op_p(ctx))
19
- rb_gc_mark_movable(ctx->data.rd.buffer);
20
- }
21
-
22
- static void OpCtx_compact(void *ptr) {
23
- OpCtx_t *ctx = ptr;
24
- ctx->spec = rb_gc_location(ctx->spec);
25
- ctx->proc = rb_gc_location(ctx->proc);
26
- if (is_read_op_p(ctx))
27
- ctx->data.rd.buffer = rb_gc_location(ctx->data.rd.buffer);
28
- }
29
-
30
- static size_t OpCtx_size(const void *ptr) {
31
- return sizeof(OpCtx_t);
32
- }
33
-
34
- static const rb_data_type_t OpCtx_type = {
35
- "OpCtx",
36
- {OpCtx_mark, 0, OpCtx_size, OpCtx_compact},
37
- 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED
38
- };
39
-
40
- static VALUE OpCtx_allocate(VALUE klass) {
41
- OpCtx_t *ctx = ALLOC(OpCtx_t);
42
-
43
- return TypedData_Wrap_Struct(klass, &OpCtx_type, ctx);
44
- }
45
-
46
- VALUE OpCtx_initialize(VALUE self, VALUE spec, VALUE proc) {
47
- OpCtx_t *ctx = RTYPEDDATA_DATA(self);
48
- RB_OBJ_WRITE(self, &ctx->spec, spec);
49
- RB_OBJ_WRITE(self, &ctx->proc, proc);
50
- memset(&ctx->data, 0, sizeof(ctx->data));
51
- ctx->stop_signal = 0;
52
- return self;
53
- }
54
-
55
- VALUE OpCtx_spec(VALUE self) {
56
- OpCtx_t *ctx = RTYPEDDATA_DATA(self);
57
- return ctx->spec;
58
- }
59
-
60
- inline enum op_type OpCtx_type_get(VALUE self) {
61
- OpCtx_t *ctx = RTYPEDDATA_DATA(self);
62
- return ctx->type;
63
- }
64
-
65
- inline void OpCtx_type_set(VALUE self, enum op_type type) {
66
- OpCtx_t *ctx = RTYPEDDATA_DATA(self);
67
- ctx->type = type;
68
- }
69
-
70
- inline VALUE OpCtx_spec_get(VALUE self) {
71
- OpCtx_t *ctx = RTYPEDDATA_DATA(self);
72
- return ctx->spec;
73
- }
74
-
75
- inline VALUE OpCtx_proc_get(VALUE self) {
76
- OpCtx_t *ctx = RTYPEDDATA_DATA(self);
77
- return ctx->proc;
78
- }
79
-
80
- struct __kernel_timespec *OpCtx_ts_get(VALUE self) {
81
- OpCtx_t *ctx = RTYPEDDATA_DATA(self);
82
- return &ctx->data.ts;
83
- }
84
-
85
- inline struct __kernel_timespec double_to_timespec(double value) {
86
- double integral;
87
- double fraction = modf(value, &integral);
88
- struct __kernel_timespec ts;
89
- ts.tv_sec = integral;
90
- ts.tv_nsec = floor(fraction * 1000000000);
91
- return ts;
92
- }
93
-
94
- inline struct __kernel_timespec value_to_timespec(VALUE value) {
95
- return double_to_timespec(NUM2DBL(value));
96
- }
97
-
98
- inline void OpCtx_ts_set(VALUE self, VALUE value) {
99
- OpCtx_t *ctx = RTYPEDDATA_DATA(self);
100
- ctx->data.ts = value_to_timespec(value);
101
- }
102
-
103
- inline struct sa_data *OpCtx_sa_get(VALUE self) {
104
- OpCtx_t *ctx = RTYPEDDATA_DATA(self);
105
- return &ctx->data.sa;
106
- }
107
-
108
- inline struct read_data *OpCtx_rd_get(VALUE self) {
109
- OpCtx_t *ctx = RTYPEDDATA_DATA(self);
110
- return &ctx->data.rd;
111
- }
112
-
113
- inline void OpCtx_rd_set(VALUE self, VALUE buffer, int buffer_offset, unsigned bg_id, int utf8_encoding) {
114
- OpCtx_t *ctx = RTYPEDDATA_DATA(self);
115
- RB_OBJ_WRITE(self, &ctx->data.rd.buffer, buffer);
116
- ctx->data.rd.buffer_offset = buffer_offset;
117
- ctx->data.rd.bg_id = bg_id;
118
- ctx->data.rd.utf8_encoding = utf8_encoding;
119
- }
120
-
121
- inline int OpCtx_stop_signal_p(VALUE self) {
122
- OpCtx_t *ctx = RTYPEDDATA_DATA(self);
123
- return ctx->stop_signal;
124
- }
125
-
126
- inline void OpCtx_stop_signal_set(VALUE self) {
127
- OpCtx_t *ctx = RTYPEDDATA_DATA(self);
128
- ctx->stop_signal = 1;
129
- }
130
-
131
- void Init_OpCtx(void) {
132
- mIOU = rb_define_module("IOU");
133
- cOpCtx = rb_define_class_under(mIOU, "OpCtx", rb_cObject);
134
- rb_define_alloc_func(cOpCtx, OpCtx_allocate);
135
-
136
- rb_define_method(cOpCtx, "initialize", OpCtx_initialize, 2);
137
- rb_define_method(cOpCtx, "spec", OpCtx_spec, 0);
138
- }