ratomic 0.1.0 → 0.2.0
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/CHANGELOG.md +16 -0
- data/Cargo.lock +381 -0
- data/Cargo.toml +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +176 -0
- data/ext/ratomic/Cargo.toml +22 -0
- data/ext/ratomic/build.rs +3 -0
- data/ext/ratomic/extconf.rb +2 -12
- data/ext/ratomic/src/counter.rs +26 -0
- data/ext/ratomic/src/fixed_size_object_pool.rs +52 -0
- data/ext/ratomic/src/hashmap.rs +70 -0
- data/ext/ratomic/src/lib.rs +401 -0
- data/ext/ratomic/src/mpmc_queue.rs +164 -0
- data/ext/ratomic/src/sem.rs +72 -0
- data/lib/ratomic/counter.rb +51 -0
- data/lib/ratomic/map.rb +56 -0
- data/lib/ratomic/pool.rb +154 -0
- data/lib/ratomic/queue.rb +17 -0
- data/lib/ratomic/undefined.rb +15 -0
- data/lib/ratomic/version.rb +1 -1
- data/lib/ratomic.rb +8 -60
- data/ratomic.gemspec +19 -13
- metadata +41 -23
- data/ext/ratomic/counter.h +0 -45
- data/ext/ratomic/fixed-size-object-pool.h +0 -76
- data/ext/ratomic/hashmap.h +0 -74
- data/ext/ratomic/mpmc-queue.h +0 -68
- data/ext/ratomic/ratomic.c +0 -16
- data/lib/ratomic/ratomic.bundle +0 -0
- data/rs/Cargo.lock +0 -196
- data/rs/Cargo.toml +0 -26
- data/rs/cbindgen.toml +0 -12
- data/rs/rust-atomics.h +0 -89
- data/rs/src/bin/mpmc_queue.rs +0 -89
- data/rs/src/counter.rs +0 -57
- data/rs/src/fixed_size_object_pool.rs +0 -120
- data/rs/src/hashmap.rs +0 -129
- data/rs/src/lib.rs +0 -23
- data/rs/src/mpmc_queue.rs +0 -231
- data/rs/src/sem.rs +0 -75
- /data/{rs → ext/ratomic}/src/gc_guard.rs +0 -0
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
#include "rust-atomics.h"
|
|
2
|
-
#include <ruby.h>
|
|
3
|
-
|
|
4
|
-
void rb_fixed_size_object_pool_mark(void *);
|
|
5
|
-
void rb_fixed_size_object_pool_free(void *);
|
|
6
|
-
|
|
7
|
-
const rb_data_type_t fixed_size_object_pool_data = {
|
|
8
|
-
.function = {.dfree = rb_fixed_size_object_pool_free,
|
|
9
|
-
.dmark = rb_fixed_size_object_pool_mark},
|
|
10
|
-
.flags = RUBY_TYPED_FROZEN_SHAREABLE};
|
|
11
|
-
|
|
12
|
-
void rb_fixed_size_object_pool_free(void *ptr) {
|
|
13
|
-
fixed_size_object_pool_t *pool = ptr;
|
|
14
|
-
fixed_size_object_pool_drop(pool);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
void rb_fixed_size_object_pool_mark(void *ptr) {
|
|
18
|
-
fixed_size_object_pool_t *pool = ptr;
|
|
19
|
-
fixed_size_object_pool_mark(pool, rb_gc_mark);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
VALUE rb_fixed_size_object_pool_alloc(VALUE klass) {
|
|
23
|
-
fixed_size_object_pool_t *pool;
|
|
24
|
-
TypedData_Make_Struct0(obj, klass, fixed_size_object_pool_t,
|
|
25
|
-
FIXED_SIZE_OBJECT_POOL_SIZE,
|
|
26
|
-
&fixed_size_object_pool_data, pool);
|
|
27
|
-
fixed_size_object_pool_alloc(pool);
|
|
28
|
-
VALUE rb_cRactor = rb_const_get(rb_cObject, rb_intern("Ractor"));
|
|
29
|
-
rb_funcall(rb_cRactor, rb_intern("make_shareable"), 1, obj);
|
|
30
|
-
return obj;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
VALUE rb_fixed_size_object_pool_initialize(VALUE self, VALUE size,
|
|
34
|
-
VALUE timeout_in_ms) {
|
|
35
|
-
fixed_size_object_pool_t *pool;
|
|
36
|
-
TypedData_Get_Struct(self, fixed_size_object_pool_t,
|
|
37
|
-
&fixed_size_object_pool_data, pool);
|
|
38
|
-
fixed_size_object_pool_init(pool, FIX2LONG(size), FIX2LONG(timeout_in_ms),
|
|
39
|
-
rb_yield);
|
|
40
|
-
return Qnil;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
VALUE rb_fixed_size_object_pool_checkout(VALUE self) {
|
|
44
|
-
fixed_size_object_pool_t *pool;
|
|
45
|
-
TypedData_Get_Struct(self, fixed_size_object_pool_t,
|
|
46
|
-
&fixed_size_object_pool_data, pool);
|
|
47
|
-
PooledItem pooled = fixed_size_object_pool_checkout(pool);
|
|
48
|
-
if (pooled.idx == 0 && pooled.rbobj == 0) {
|
|
49
|
-
return Qnil;
|
|
50
|
-
}
|
|
51
|
-
VALUE ary = rb_ary_new_capa(2);
|
|
52
|
-
rb_ary_push(ary, pooled.rbobj);
|
|
53
|
-
rb_ary_push(ary, LONG2FIX(pooled.idx));
|
|
54
|
-
return ary;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
VALUE rb_fixed_size_object_pool_checkin(VALUE self, VALUE idx) {
|
|
58
|
-
fixed_size_object_pool_t *pool;
|
|
59
|
-
TypedData_Get_Struct(self, fixed_size_object_pool_t,
|
|
60
|
-
&fixed_size_object_pool_data, pool);
|
|
61
|
-
fixed_size_object_pool_checkin(pool, FIX2LONG(idx));
|
|
62
|
-
return Qnil;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
static void init_fixed_size_object_pool(VALUE rb_mRoot) {
|
|
66
|
-
VALUE rb_cFixedSizeObjectPool =
|
|
67
|
-
rb_define_class_under(rb_mRoot, "FixedSizeObjectPool", rb_cObject);
|
|
68
|
-
rb_define_alloc_func(rb_cFixedSizeObjectPool,
|
|
69
|
-
rb_fixed_size_object_pool_alloc);
|
|
70
|
-
rb_define_method(rb_cFixedSizeObjectPool, "initialize",
|
|
71
|
-
rb_fixed_size_object_pool_initialize, 2);
|
|
72
|
-
rb_define_method(rb_cFixedSizeObjectPool, "checkout",
|
|
73
|
-
rb_fixed_size_object_pool_checkout, 0);
|
|
74
|
-
rb_define_method(rb_cFixedSizeObjectPool, "checkin",
|
|
75
|
-
rb_fixed_size_object_pool_checkin, 1);
|
|
76
|
-
}
|
data/ext/ratomic/hashmap.h
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
#include "rust-atomics.h"
|
|
2
|
-
#include <ruby.h>
|
|
3
|
-
|
|
4
|
-
void rb_concurrent_hash_map_mark(void *);
|
|
5
|
-
void rb_concurrent_hash_map_free(void *);
|
|
6
|
-
|
|
7
|
-
const rb_data_type_t concurrent_hash_map_data = {
|
|
8
|
-
.function = {.dfree = rb_concurrent_hash_map_free,
|
|
9
|
-
.dmark = rb_concurrent_hash_map_mark},
|
|
10
|
-
.flags = RUBY_TYPED_FROZEN_SHAREABLE};
|
|
11
|
-
|
|
12
|
-
void rb_concurrent_hash_map_free(void *ptr) {
|
|
13
|
-
concurrent_hash_map_t *hashmap = ptr;
|
|
14
|
-
concurrent_hash_map_drop(hashmap);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
void rb_concurrent_hash_map_mark(void *ptr) {
|
|
18
|
-
concurrent_hash_map_t *hashmap = ptr;
|
|
19
|
-
concurrent_hash_map_mark(hashmap, rb_gc_mark);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
VALUE rb_concurrent_hash_map_alloc(VALUE klass) {
|
|
23
|
-
concurrent_hash_map_t *hashmap;
|
|
24
|
-
TypedData_Make_Struct0(obj, klass, concurrent_hash_map_t,
|
|
25
|
-
CONCURRENT_HASH_MAP_SIZE, &concurrent_hash_map_data,
|
|
26
|
-
hashmap);
|
|
27
|
-
concurrent_hash_map_init(hashmap);
|
|
28
|
-
VALUE rb_cRactor = rb_const_get(rb_cObject, rb_intern("Ractor"));
|
|
29
|
-
rb_funcall(rb_cRactor, rb_intern("make_shareable"), 1, obj);
|
|
30
|
-
return obj;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
VALUE rb_concurrent_hash_map_get(VALUE self, VALUE key) {
|
|
34
|
-
concurrent_hash_map_t *hashmap;
|
|
35
|
-
TypedData_Get_Struct(self, concurrent_hash_map_t, &concurrent_hash_map_data,
|
|
36
|
-
hashmap);
|
|
37
|
-
return concurrent_hash_map_get(hashmap, key, Qnil);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
VALUE rb_concurrent_hash_map_set(VALUE self, VALUE key, VALUE value) {
|
|
41
|
-
concurrent_hash_map_t *hashmap;
|
|
42
|
-
TypedData_Get_Struct(self, concurrent_hash_map_t, &concurrent_hash_map_data,
|
|
43
|
-
hashmap);
|
|
44
|
-
concurrent_hash_map_set(hashmap, key, value);
|
|
45
|
-
return Qnil;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
VALUE rb_concurrent_hash_map_clear(VALUE self) {
|
|
49
|
-
concurrent_hash_map_t *hashmap;
|
|
50
|
-
TypedData_Get_Struct(self, concurrent_hash_map_t, &concurrent_hash_map_data,
|
|
51
|
-
hashmap);
|
|
52
|
-
concurrent_hash_map_clear(hashmap);
|
|
53
|
-
return Qnil;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
VALUE rb_concurrent_hash_map_fetch_and_modify(VALUE self, VALUE key) {
|
|
57
|
-
rb_need_block();
|
|
58
|
-
concurrent_hash_map_t *hashmap;
|
|
59
|
-
TypedData_Get_Struct(self, concurrent_hash_map_t, &concurrent_hash_map_data,
|
|
60
|
-
hashmap);
|
|
61
|
-
concurrent_hash_map_fetch_and_modify(hashmap, key, rb_yield);
|
|
62
|
-
return Qnil;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
static void init_hashmap(VALUE rb_mRoot) {
|
|
66
|
-
VALUE rb_cConcurrentHashMap =
|
|
67
|
-
rb_define_class_under(rb_mRoot, "ConcurrentHashMap", rb_cObject);
|
|
68
|
-
rb_define_alloc_func(rb_cConcurrentHashMap, rb_concurrent_hash_map_alloc);
|
|
69
|
-
rb_define_method(rb_cConcurrentHashMap, "get", rb_concurrent_hash_map_get, 1);
|
|
70
|
-
rb_define_method(rb_cConcurrentHashMap, "set", rb_concurrent_hash_map_set, 2);
|
|
71
|
-
rb_define_method(rb_cConcurrentHashMap, "clear", rb_concurrent_hash_map_clear, 0);
|
|
72
|
-
rb_define_method(rb_cConcurrentHashMap, "fetch_and_modify",
|
|
73
|
-
rb_concurrent_hash_map_fetch_and_modify, 1);
|
|
74
|
-
}
|
data/ext/ratomic/mpmc-queue.h
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
#include "rust-atomics.h"
|
|
2
|
-
#include <ruby.h>
|
|
3
|
-
#include <ruby/thread.h>
|
|
4
|
-
|
|
5
|
-
void rb_mpmc_queue_mark(void *);
|
|
6
|
-
void rb_mpmc_queue_free(void *);
|
|
7
|
-
|
|
8
|
-
const rb_data_type_t mpmc_queue_data = {
|
|
9
|
-
.function = {.dfree = rb_mpmc_queue_free, .dmark = rb_mpmc_queue_mark},
|
|
10
|
-
.flags = RUBY_TYPED_FROZEN_SHAREABLE};
|
|
11
|
-
|
|
12
|
-
void rb_mpmc_queue_free(void *ptr) {
|
|
13
|
-
mpmc_queue_t *queue = ptr;
|
|
14
|
-
mpmc_queue_drop(queue);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
void rb_mpmc_queue_mark(void *ptr) {
|
|
18
|
-
mpmc_queue_t *queue = ptr;
|
|
19
|
-
mpmc_queue_mark(queue, rb_gc_mark);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
VALUE rb_mpmc_queue_alloc(VALUE klass) {
|
|
23
|
-
mpmc_queue_t *queue;
|
|
24
|
-
TypedData_Make_Struct0(obj, klass, mpmc_queue_t, MPMC_QUEUE_OBJECT_SIZE,
|
|
25
|
-
&mpmc_queue_data, queue);
|
|
26
|
-
mpmc_queue_alloc(queue);
|
|
27
|
-
VALUE rb_cRactor = rb_const_get(rb_cObject, rb_intern("Ractor"));
|
|
28
|
-
rb_funcall(rb_cRactor, rb_intern("make_shareable"), 1, obj);
|
|
29
|
-
return obj;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
VALUE rb_mpmc_queue_initialize(VALUE self, VALUE cap) {
|
|
33
|
-
mpmc_queue_t *queue;
|
|
34
|
-
TypedData_Get_Struct(self, mpmc_queue_t, &mpmc_queue_data, queue);
|
|
35
|
-
mpmc_queue_init(queue, FIX2LONG(cap), Qnil);
|
|
36
|
-
return Qnil;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
typedef struct {
|
|
40
|
-
mpmc_queue_t *queue;
|
|
41
|
-
VALUE value;
|
|
42
|
-
} push_payload_t;
|
|
43
|
-
|
|
44
|
-
VALUE rb_mpmc_queue_push(VALUE self, VALUE value) {
|
|
45
|
-
mpmc_queue_t *queue;
|
|
46
|
-
TypedData_Get_Struct(self, mpmc_queue_t, &mpmc_queue_data, queue);
|
|
47
|
-
push_payload_t push_payload = {.queue = queue, .value = value};
|
|
48
|
-
rb_thread_call_without_gvl(mpmc_queue_push, &push_payload, NULL, NULL);
|
|
49
|
-
return Qtrue;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
VALUE rb_mpmc_queue_pop(VALUE self) {
|
|
53
|
-
mpmc_queue_t *queue;
|
|
54
|
-
TypedData_Get_Struct(self, mpmc_queue_t, &mpmc_queue_data, queue);
|
|
55
|
-
void *ptr = rb_thread_call_without_gvl(mpmc_queue_pop, queue, NULL, NULL);
|
|
56
|
-
VALUE item = (VALUE)ptr;
|
|
57
|
-
return item;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
static void init_mpmc_queue(VALUE rb_mRoot) {
|
|
61
|
-
VALUE rb_cMpmcQueue =
|
|
62
|
-
rb_define_class_under(rb_mRoot, "Queue", rb_cObject);
|
|
63
|
-
rb_define_alloc_func(rb_cMpmcQueue, rb_mpmc_queue_alloc);
|
|
64
|
-
|
|
65
|
-
rb_define_method(rb_cMpmcQueue, "initialize", rb_mpmc_queue_initialize, 1);
|
|
66
|
-
rb_define_method(rb_cMpmcQueue, "push", rb_mpmc_queue_push, 1);
|
|
67
|
-
rb_define_method(rb_cMpmcQueue, "pop", rb_mpmc_queue_pop, 0);
|
|
68
|
-
}
|
data/ext/ratomic/ratomic.c
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
#include "counter.h"
|
|
2
|
-
#include "fixed-size-object-pool.h"
|
|
3
|
-
#include "hashmap.h"
|
|
4
|
-
#include "mpmc-queue.h"
|
|
5
|
-
#include <ruby.h>
|
|
6
|
-
|
|
7
|
-
RUBY_FUNC_EXPORTED void Init_ratomic(void) {
|
|
8
|
-
rb_ext_ractor_safe(true);
|
|
9
|
-
|
|
10
|
-
VALUE rb_mRoot = rb_define_module("Ratomic");
|
|
11
|
-
|
|
12
|
-
init_counter(rb_mRoot);
|
|
13
|
-
init_hashmap(rb_mRoot);
|
|
14
|
-
init_fixed_size_object_pool(rb_mRoot);
|
|
15
|
-
init_mpmc_queue(rb_mRoot);
|
|
16
|
-
}
|
data/lib/ratomic/ratomic.bundle
DELETED
|
Binary file
|
data/rs/Cargo.lock
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
# This file is automatically @generated by Cargo.
|
|
2
|
-
# It is not intended for manual editing.
|
|
3
|
-
version = 4
|
|
4
|
-
|
|
5
|
-
[[package]]
|
|
6
|
-
name = "autocfg"
|
|
7
|
-
version = "1.4.0"
|
|
8
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
9
|
-
checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
|
|
10
|
-
|
|
11
|
-
[[package]]
|
|
12
|
-
name = "bitflags"
|
|
13
|
-
version = "2.9.0"
|
|
14
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
15
|
-
checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd"
|
|
16
|
-
|
|
17
|
-
[[package]]
|
|
18
|
-
name = "cfg-if"
|
|
19
|
-
version = "1.0.0"
|
|
20
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
21
|
-
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
|
22
|
-
|
|
23
|
-
[[package]]
|
|
24
|
-
name = "crossbeam-channel"
|
|
25
|
-
version = "0.5.14"
|
|
26
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
27
|
-
checksum = "06ba6d68e24814cb8de6bb986db8222d3a027d15872cabc0d18817bc3c0e4471"
|
|
28
|
-
dependencies = [
|
|
29
|
-
"crossbeam-utils",
|
|
30
|
-
]
|
|
31
|
-
|
|
32
|
-
[[package]]
|
|
33
|
-
name = "crossbeam-utils"
|
|
34
|
-
version = "0.8.21"
|
|
35
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
36
|
-
checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
|
|
37
|
-
|
|
38
|
-
[[package]]
|
|
39
|
-
name = "dashmap"
|
|
40
|
-
version = "6.1.0"
|
|
41
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
42
|
-
checksum = "5041cc499144891f3790297212f32a74fb938e5136a14943f338ef9e0ae276cf"
|
|
43
|
-
dependencies = [
|
|
44
|
-
"cfg-if",
|
|
45
|
-
"crossbeam-utils",
|
|
46
|
-
"hashbrown",
|
|
47
|
-
"lock_api",
|
|
48
|
-
"once_cell",
|
|
49
|
-
"parking_lot_core",
|
|
50
|
-
]
|
|
51
|
-
|
|
52
|
-
[[package]]
|
|
53
|
-
name = "hashbrown"
|
|
54
|
-
version = "0.14.5"
|
|
55
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
56
|
-
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
|
|
57
|
-
|
|
58
|
-
[[package]]
|
|
59
|
-
name = "libc"
|
|
60
|
-
version = "0.2.171"
|
|
61
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
62
|
-
checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6"
|
|
63
|
-
|
|
64
|
-
[[package]]
|
|
65
|
-
name = "lock_api"
|
|
66
|
-
version = "0.4.12"
|
|
67
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
68
|
-
checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17"
|
|
69
|
-
dependencies = [
|
|
70
|
-
"autocfg",
|
|
71
|
-
"scopeguard",
|
|
72
|
-
]
|
|
73
|
-
|
|
74
|
-
[[package]]
|
|
75
|
-
name = "once_cell"
|
|
76
|
-
version = "1.21.1"
|
|
77
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
78
|
-
checksum = "d75b0bedcc4fe52caa0e03d9f1151a323e4aa5e2d78ba3580400cd3c9e2bc4bc"
|
|
79
|
-
|
|
80
|
-
[[package]]
|
|
81
|
-
name = "parking_lot"
|
|
82
|
-
version = "0.12.3"
|
|
83
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
84
|
-
checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27"
|
|
85
|
-
dependencies = [
|
|
86
|
-
"lock_api",
|
|
87
|
-
"parking_lot_core",
|
|
88
|
-
]
|
|
89
|
-
|
|
90
|
-
[[package]]
|
|
91
|
-
name = "parking_lot_core"
|
|
92
|
-
version = "0.9.10"
|
|
93
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
94
|
-
checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8"
|
|
95
|
-
dependencies = [
|
|
96
|
-
"cfg-if",
|
|
97
|
-
"libc",
|
|
98
|
-
"redox_syscall",
|
|
99
|
-
"smallvec",
|
|
100
|
-
"windows-targets",
|
|
101
|
-
]
|
|
102
|
-
|
|
103
|
-
[[package]]
|
|
104
|
-
name = "redox_syscall"
|
|
105
|
-
version = "0.5.10"
|
|
106
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
107
|
-
checksum = "0b8c0c260b63a8219631167be35e6a988e9554dbd323f8bd08439c8ed1302bd1"
|
|
108
|
-
dependencies = [
|
|
109
|
-
"bitflags",
|
|
110
|
-
]
|
|
111
|
-
|
|
112
|
-
[[package]]
|
|
113
|
-
name = "rust-atomics"
|
|
114
|
-
version = "0.1.0"
|
|
115
|
-
dependencies = [
|
|
116
|
-
"crossbeam-channel",
|
|
117
|
-
"dashmap",
|
|
118
|
-
"libc",
|
|
119
|
-
"parking_lot",
|
|
120
|
-
]
|
|
121
|
-
|
|
122
|
-
[[package]]
|
|
123
|
-
name = "scopeguard"
|
|
124
|
-
version = "1.2.0"
|
|
125
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
126
|
-
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
|
127
|
-
|
|
128
|
-
[[package]]
|
|
129
|
-
name = "smallvec"
|
|
130
|
-
version = "1.14.0"
|
|
131
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
132
|
-
checksum = "7fcf8323ef1faaee30a44a340193b1ac6814fd9b7b4e88e9d4519a3e4abe1cfd"
|
|
133
|
-
|
|
134
|
-
[[package]]
|
|
135
|
-
name = "windows-targets"
|
|
136
|
-
version = "0.52.6"
|
|
137
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
138
|
-
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
|
|
139
|
-
dependencies = [
|
|
140
|
-
"windows_aarch64_gnullvm",
|
|
141
|
-
"windows_aarch64_msvc",
|
|
142
|
-
"windows_i686_gnu",
|
|
143
|
-
"windows_i686_gnullvm",
|
|
144
|
-
"windows_i686_msvc",
|
|
145
|
-
"windows_x86_64_gnu",
|
|
146
|
-
"windows_x86_64_gnullvm",
|
|
147
|
-
"windows_x86_64_msvc",
|
|
148
|
-
]
|
|
149
|
-
|
|
150
|
-
[[package]]
|
|
151
|
-
name = "windows_aarch64_gnullvm"
|
|
152
|
-
version = "0.52.6"
|
|
153
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
154
|
-
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
|
|
155
|
-
|
|
156
|
-
[[package]]
|
|
157
|
-
name = "windows_aarch64_msvc"
|
|
158
|
-
version = "0.52.6"
|
|
159
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
160
|
-
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
|
|
161
|
-
|
|
162
|
-
[[package]]
|
|
163
|
-
name = "windows_i686_gnu"
|
|
164
|
-
version = "0.52.6"
|
|
165
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
166
|
-
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
|
|
167
|
-
|
|
168
|
-
[[package]]
|
|
169
|
-
name = "windows_i686_gnullvm"
|
|
170
|
-
version = "0.52.6"
|
|
171
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
172
|
-
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
|
|
173
|
-
|
|
174
|
-
[[package]]
|
|
175
|
-
name = "windows_i686_msvc"
|
|
176
|
-
version = "0.52.6"
|
|
177
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
178
|
-
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
|
|
179
|
-
|
|
180
|
-
[[package]]
|
|
181
|
-
name = "windows_x86_64_gnu"
|
|
182
|
-
version = "0.52.6"
|
|
183
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
184
|
-
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
|
|
185
|
-
|
|
186
|
-
[[package]]
|
|
187
|
-
name = "windows_x86_64_gnullvm"
|
|
188
|
-
version = "0.52.6"
|
|
189
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
190
|
-
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
|
|
191
|
-
|
|
192
|
-
[[package]]
|
|
193
|
-
name = "windows_x86_64_msvc"
|
|
194
|
-
version = "0.52.6"
|
|
195
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
196
|
-
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
data/rs/Cargo.toml
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
[package]
|
|
2
|
-
name = "rust-atomics"
|
|
3
|
-
version = "0.1.0"
|
|
4
|
-
edition = "2024"
|
|
5
|
-
|
|
6
|
-
[lib]
|
|
7
|
-
crate-type = ["lib", "staticlib"]
|
|
8
|
-
|
|
9
|
-
[features]
|
|
10
|
-
simulation = []
|
|
11
|
-
|
|
12
|
-
[dependencies]
|
|
13
|
-
crossbeam-channel = "0.5.14"
|
|
14
|
-
dashmap = "6.1.0"
|
|
15
|
-
parking_lot = "0.12.3"
|
|
16
|
-
libc = "0.2.170"
|
|
17
|
-
|
|
18
|
-
[profile.release]
|
|
19
|
-
panic = "abort"
|
|
20
|
-
lto = true
|
|
21
|
-
codegen-units = 1
|
|
22
|
-
|
|
23
|
-
[[bin]]
|
|
24
|
-
bench = false
|
|
25
|
-
name = "mpmc_queue"
|
|
26
|
-
test = false
|
data/rs/cbindgen.toml
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
language = "c"
|
|
2
|
-
include_guard = "RUST_ATOMICS_H"
|
|
3
|
-
style = "type"
|
|
4
|
-
|
|
5
|
-
[export.rename]
|
|
6
|
-
"AtomicCounter" = "atomic_counter_t"
|
|
7
|
-
"ConcurrentHashMap" = "concurrent_hash_map_t"
|
|
8
|
-
"FixedSizeObjectPool" = "fixed_size_object_pool_t"
|
|
9
|
-
"MpmcQueue" = "mpmc_queue_t"
|
|
10
|
-
|
|
11
|
-
[export]
|
|
12
|
-
include = ["QueuePushArg"]
|
data/rs/rust-atomics.h
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
#ifndef RUST_ATOMICS_H
|
|
2
|
-
#define RUST_ATOMICS_H
|
|
3
|
-
|
|
4
|
-
#include <stdarg.h>
|
|
5
|
-
#include <stdbool.h>
|
|
6
|
-
#include <stdint.h>
|
|
7
|
-
#include <stdlib.h>
|
|
8
|
-
|
|
9
|
-
#define ATOMIC_COUNTER_SIZE 8
|
|
10
|
-
|
|
11
|
-
#define CONCURRENT_HASH_MAP_SIZE 40
|
|
12
|
-
|
|
13
|
-
#define FIXED_SIZE_OBJECT_POOL_SIZE 72
|
|
14
|
-
|
|
15
|
-
#define MPMC_QUEUE_OBJECT_SIZE 80
|
|
16
|
-
|
|
17
|
-
typedef struct atomic_counter_t atomic_counter_t;
|
|
18
|
-
|
|
19
|
-
typedef struct concurrent_hash_map_t concurrent_hash_map_t;
|
|
20
|
-
|
|
21
|
-
typedef struct fixed_size_object_pool_t fixed_size_object_pool_t;
|
|
22
|
-
|
|
23
|
-
typedef struct mpmc_queue_t mpmc_queue_t;
|
|
24
|
-
|
|
25
|
-
typedef struct {
|
|
26
|
-
uintptr_t idx;
|
|
27
|
-
unsigned long rbobj;
|
|
28
|
-
} PooledItem;
|
|
29
|
-
|
|
30
|
-
void atomic_counter_init(atomic_counter_t *counter, uint64_t n);
|
|
31
|
-
|
|
32
|
-
void atomic_counter_increment(const atomic_counter_t *counter, uint64_t amt);
|
|
33
|
-
|
|
34
|
-
void atomic_counter_decrement(const atomic_counter_t *counter, uint64_t amt);
|
|
35
|
-
|
|
36
|
-
uint64_t atomic_counter_read(const atomic_counter_t *counter);
|
|
37
|
-
|
|
38
|
-
extern unsigned long rb_hash(unsigned long obj);
|
|
39
|
-
|
|
40
|
-
extern int rb_eql(unsigned long lhs, unsigned long rhs);
|
|
41
|
-
|
|
42
|
-
void concurrent_hash_map_init(concurrent_hash_map_t *hashmap);
|
|
43
|
-
|
|
44
|
-
void concurrent_hash_map_drop(concurrent_hash_map_t *hashmap);
|
|
45
|
-
|
|
46
|
-
void concurrent_hash_map_clear(const concurrent_hash_map_t *hashmap);
|
|
47
|
-
|
|
48
|
-
unsigned long concurrent_hash_map_get(const concurrent_hash_map_t *hashmap,
|
|
49
|
-
unsigned long key,
|
|
50
|
-
unsigned long fallback);
|
|
51
|
-
|
|
52
|
-
void concurrent_hash_map_set(const concurrent_hash_map_t *hashmap,
|
|
53
|
-
unsigned long key,
|
|
54
|
-
unsigned long value);
|
|
55
|
-
|
|
56
|
-
void concurrent_hash_map_mark(const concurrent_hash_map_t *hashmap, void (*f)(unsigned long));
|
|
57
|
-
|
|
58
|
-
void concurrent_hash_map_fetch_and_modify(const concurrent_hash_map_t *hashmap,
|
|
59
|
-
unsigned long key,
|
|
60
|
-
unsigned long (*f)(unsigned long));
|
|
61
|
-
|
|
62
|
-
void fixed_size_object_pool_alloc(fixed_size_object_pool_t *pool);
|
|
63
|
-
|
|
64
|
-
void fixed_size_object_pool_init(fixed_size_object_pool_t *pool,
|
|
65
|
-
uintptr_t max_size,
|
|
66
|
-
uint64_t timeout_in_ms,
|
|
67
|
-
unsigned long (*rb_make_obj)(unsigned long));
|
|
68
|
-
|
|
69
|
-
void fixed_size_object_pool_drop(fixed_size_object_pool_t *pool);
|
|
70
|
-
|
|
71
|
-
void fixed_size_object_pool_mark(const fixed_size_object_pool_t *pool, void (*f)(unsigned long));
|
|
72
|
-
|
|
73
|
-
PooledItem fixed_size_object_pool_checkout(fixed_size_object_pool_t *pool);
|
|
74
|
-
|
|
75
|
-
void fixed_size_object_pool_checkin(fixed_size_object_pool_t *pool, uintptr_t idx);
|
|
76
|
-
|
|
77
|
-
void mpmc_queue_alloc(mpmc_queue_t *q);
|
|
78
|
-
|
|
79
|
-
void mpmc_queue_init(mpmc_queue_t *q, uintptr_t capacity, unsigned long default_);
|
|
80
|
-
|
|
81
|
-
void mpmc_queue_drop(mpmc_queue_t *q);
|
|
82
|
-
|
|
83
|
-
void mpmc_queue_mark(const mpmc_queue_t *q, void (*f)(unsigned long));
|
|
84
|
-
|
|
85
|
-
void *mpmc_queue_push(void *push_paylod);
|
|
86
|
-
|
|
87
|
-
void *mpmc_queue_pop(void *q);
|
|
88
|
-
|
|
89
|
-
#endif /* RUST_ATOMICS_H */
|
data/rs/src/bin/mpmc_queue.rs
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
use std::{
|
|
2
|
-
sync::Arc,
|
|
3
|
-
time::{Duration, Instant},
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
use libc::c_ulong;
|
|
7
|
-
use rust_atomics::MpmcQueue;
|
|
8
|
-
|
|
9
|
-
const RUN_GC_EVERY: Duration = Duration::from_millis(1000);
|
|
10
|
-
const PUSH_ITERATIONS: u64 = 5;
|
|
11
|
-
const THREADS_COUNT: u8 = 10;
|
|
12
|
-
|
|
13
|
-
fn main() {
|
|
14
|
-
let q = make_q(16);
|
|
15
|
-
|
|
16
|
-
let mut consumers = vec![];
|
|
17
|
-
for _ in 0..THREADS_COUNT {
|
|
18
|
-
consumers.push(start_consumer(Arc::clone(&q)));
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
let last_pushed_value = start_producer(Arc::clone(&q));
|
|
22
|
-
|
|
23
|
-
let mut consumed = vec![];
|
|
24
|
-
for consumer in consumers {
|
|
25
|
-
let mut data = consumer.join().unwrap();
|
|
26
|
-
consumed.append(&mut data);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
consumed.sort_unstable();
|
|
30
|
-
|
|
31
|
-
for (prev, next) in consumed.iter().zip(consumed.iter().skip(1)) {
|
|
32
|
-
assert_eq!(*prev + 1, *next);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
assert_eq!(*consumed.last().unwrap(), last_pushed_value);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
fn make_q(buffer_size: usize) -> Arc<MpmcQueue> {
|
|
39
|
-
Arc::new(MpmcQueue::new(buffer_size, 0))
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const END: c_ulong = c_ulong::MAX;
|
|
43
|
-
fn push_end(q: &MpmcQueue) {
|
|
44
|
-
q.push(END);
|
|
45
|
-
}
|
|
46
|
-
fn pop(q: &MpmcQueue) -> Option<c_ulong> {
|
|
47
|
-
match q.pop() {
|
|
48
|
-
END => None,
|
|
49
|
-
other => Some(other),
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
fn start_consumer(q: Arc<MpmcQueue>) -> std::thread::JoinHandle<Vec<c_ulong>> {
|
|
54
|
-
std::thread::spawn(move || {
|
|
55
|
-
let mut popped = vec![];
|
|
56
|
-
|
|
57
|
-
while let Some(value) = pop(&q) {
|
|
58
|
-
eprintln!("[{:?}] popped {value}", std::thread::current().id());
|
|
59
|
-
popped.push(value);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
popped
|
|
63
|
-
})
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
fn start_producer(q: Arc<MpmcQueue>) -> c_ulong {
|
|
67
|
-
let mut value = 1;
|
|
68
|
-
|
|
69
|
-
for _ in 0..PUSH_ITERATIONS {
|
|
70
|
-
// push for `RUN_GC_EVERY`
|
|
71
|
-
let start = Instant::now();
|
|
72
|
-
while Instant::now() - start < RUN_GC_EVERY {
|
|
73
|
-
q.push(value);
|
|
74
|
-
value += 1;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
q.acquire_as_gc(|| {
|
|
78
|
-
eprintln!("===== GC START ======");
|
|
79
|
-
std::thread::sleep(Duration::from_millis(1000));
|
|
80
|
-
eprintln!("===== GC END ========");
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
for _ in 0..THREADS_COUNT {
|
|
85
|
-
push_end(&q);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
value - 1
|
|
89
|
-
}
|