asterism-zenoh 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/README.md +9 -2
- data/ext/asterism_zenoh/zenoh.c +16 -6
- data/lib/asterism/zenoh/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e69691b1bce645a0c919495f5b666dd315f94cc6f2c34707cee76eeeccc1d9f7
|
|
4
|
+
data.tar.gz: efff8d1807c7752b2d2cadd9d71a082ac96da2acf95af0e9f33873686b5be2d1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 18f12c15339bae03cbbe9116933d3eccbbf3c740376c5f348830cc7f8e2cf163bd5b0a86876b471955b08dcefa888e51bbcd8de5c4cf141816770e55b42f860f
|
|
7
|
+
data.tar.gz: e25ab4b30899f357f9440a9c14d3cb12a7e8b80e36ff1962aa280726237c44b5a8af4091a14585273031e392658155f41d7946da2a2ebe092ef7184c9c8e1117
|
data/README.md
CHANGED
|
@@ -55,8 +55,15 @@ its own thread. Nothing calls into Ruby behind its back, and `poll` does not
|
|
|
55
55
|
need to run for data to arrive: it only checks the connection.
|
|
56
56
|
|
|
57
57
|
Waiting calls (`Session.open`, `put`, `get`, `liveliness_get`, `close`)
|
|
58
|
-
release the GVL.
|
|
59
|
-
|
|
58
|
+
release the GVL. A `Session` and its objects may be used from several Ruby
|
|
59
|
+
threads: the calls that keep the GVL are serialized by it, the ones that
|
|
60
|
+
release it by a lock of the session, and a session that closes (by `close`
|
|
61
|
+
or because the connection was lost) is closed for every thread before
|
|
62
|
+
zenoh-c lets it go; calls made after that raise `Asterism::Zenoh::Error`.
|
|
63
|
+
Each entry of a queue is taken by exactly one `each_pending` /
|
|
64
|
+
`each_reply`. The gem itself starts no Ruby thread: blocks, a receiving
|
|
65
|
+
thread and Enumerators on top of this API are in the CRuby layer of the
|
|
66
|
+
`asterism` gem.
|
|
60
67
|
|
|
61
68
|
## Behaviour kept from the mruby gem
|
|
62
69
|
|
data/ext/asterism_zenoh/zenoh.c
CHANGED
|
@@ -18,7 +18,10 @@
|
|
|
18
18
|
* thread. Session#poll only checks the connection: receiving needs no poll.
|
|
19
19
|
*
|
|
20
20
|
* The GVL is released while zenoh-c may wait: opening a session (connecting
|
|
21
|
-
* to the router), put, get, liveliness_get and close.
|
|
21
|
+
* to the router), put, get, liveliness_get and close. A session may be used
|
|
22
|
+
* from several Ruby threads: the calls that hold the GVL are serialized by
|
|
23
|
+
* it, the ones without it by the session's op_lock, and closing marks the
|
|
24
|
+
* session closed for Ruby (with the GVL held) before zenoh-c drops it.
|
|
22
25
|
*
|
|
23
26
|
* Losing the connection (same rules as the mruby gem): a client session is
|
|
24
27
|
* closed when it has no router left, a peer session that only connects when
|
|
@@ -393,7 +396,8 @@ typedef struct zrb_token zrb_token;
|
|
|
393
396
|
struct zrb_session {
|
|
394
397
|
z_owned_session_t session;
|
|
395
398
|
pthread_mutex_t op_lock; /* calls made without the GVL, and close */
|
|
396
|
-
bool open;
|
|
399
|
+
bool open; /* Ruby's view; changed only with the GVL held */
|
|
400
|
+
bool live; /* the zenoh-c session exists; changed under op_lock */
|
|
397
401
|
bool peer; /* peer mode (otherwise client) */
|
|
398
402
|
bool listening; /* peer mode with a listener: stays open without peers */
|
|
399
403
|
zrb_sub *subs; /* live subscribers and liveliness watches */
|
|
@@ -861,8 +865,8 @@ static void zrb_session_detach_all(zrb_session *z) {
|
|
|
861
865
|
static void *zrb_session_close_nogvl(void *p) {
|
|
862
866
|
zrb_session *z = (zrb_session *)p;
|
|
863
867
|
pthread_mutex_lock(&z->op_lock);
|
|
864
|
-
if (z->
|
|
865
|
-
z->
|
|
868
|
+
if (z->live) {
|
|
869
|
+
z->live = false;
|
|
866
870
|
z_close(z_loan_mut(z->session), NULL);
|
|
867
871
|
z_drop(z_move(z->session));
|
|
868
872
|
}
|
|
@@ -875,6 +879,11 @@ static void zrb_session_shutdown(zrb_session *z, bool with_gvl_release) {
|
|
|
875
879
|
if (!z->open) {
|
|
876
880
|
return;
|
|
877
881
|
}
|
|
882
|
+
/* Closed for Ruby before the GVL is released: another Ruby thread that
|
|
883
|
+
* runs while zenoh-c closes the session sees it closed and does not
|
|
884
|
+
* touch the session any more (the calls without the GVL check live
|
|
885
|
+
* under op_lock instead). */
|
|
886
|
+
z->open = false;
|
|
878
887
|
if (with_gvl_release) {
|
|
879
888
|
rb_thread_call_without_gvl(zrb_session_close_nogvl, z, RUBY_UBF_IO, NULL);
|
|
880
889
|
} else {
|
|
@@ -1052,6 +1061,7 @@ static VALUE zrb_session_s_open(int argc, VALUE *argv, VALUE klass) {
|
|
|
1052
1061
|
rb_raise(eZenohError, "cannot open a session to %s (%d)", locator != NULL ? locator : listen, (int)a.ret);
|
|
1053
1062
|
}
|
|
1054
1063
|
z->open = true;
|
|
1064
|
+
z->live = true;
|
|
1055
1065
|
z->peer = peer;
|
|
1056
1066
|
z->listening = (listen != NULL);
|
|
1057
1067
|
return obj;
|
|
@@ -1068,7 +1078,7 @@ typedef struct {
|
|
|
1068
1078
|
static void *zrb_put_nogvl(void *p) {
|
|
1069
1079
|
zrb_put_args *a = (zrb_put_args *)p;
|
|
1070
1080
|
pthread_mutex_lock(&a->z->op_lock);
|
|
1071
|
-
if (a->z->
|
|
1081
|
+
if (a->z->live) {
|
|
1072
1082
|
a->ret = z_put(z_loan(a->z->session), z_loan(a->key), z_move(a->payload), &a->opts);
|
|
1073
1083
|
} else {
|
|
1074
1084
|
a->ret = Z_ESESSION_CLOSED;
|
|
@@ -1269,7 +1279,7 @@ typedef struct {
|
|
|
1269
1279
|
static void *zrb_get_nogvl(void *p) {
|
|
1270
1280
|
zrb_get_args *a = (zrb_get_args *)p;
|
|
1271
1281
|
pthread_mutex_lock(&a->z->op_lock);
|
|
1272
|
-
if (a->z->
|
|
1282
|
+
if (a->z->live) {
|
|
1273
1283
|
if (a->liveliness) {
|
|
1274
1284
|
a->ret = z_liveliness_get(z_loan(a->z->session), z_loan(a->key), z_move(a->cb), &a->lopts);
|
|
1275
1285
|
} else {
|