| 1 |
|
| # Shared::Arena::Frozen - one structure, read in place by every process. |
| 2 |
|
| |
| 3 |
|
| MODULE = Shared::Arena PACKAGE = Shared::Arena PREFIX = sar_ |
| 4 |
|
| |
| 5 |
|
| # $arena->frozen($name, size => N, slots => 4) |
| 6 |
|
| # |
| 7 |
|
| # `size` is the largest block this will ever carry, and the region costs that |
| 8 |
|
| # times `slots`, because the point of the slots is that a publish never writes |
| 9 |
|
| # where somebody is reading. |
| 10 |
|
| SV * |
| 11 |
|
| sar_frozen(self, name, ...) |
| 12 |
|
| SV *self |
| 13 |
|
| SV *name |
| 14 |
|
| PREINIT: |
| 15 |
|
| sa_region *arena; |
| 16 |
|
| sa_reg *e; |
| 17 |
|
| sa_frozen *f; |
| 18 |
|
| const char *nm; |
| 19 |
|
| STRLEN nlen; |
| 20 |
14 |
| UV size = 65536, slots = 4; |
| 21 |
14 |
| int err = SA_E_OK; |
| 22 |
|
| I32 i; |
| 23 |
|
| SV *obj; |
| 24 |
|
| CODE: |
| 25 |
14 |
| arena = SA_SELF(sa_region, self); |
| 26 |
14 |
▶ | if (!arena || !arena->map.base) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!arena || !arena->map.base) |
14 |
0 |
14 |
| if (!arena || !arena->map.base) |
0 |
14 |
14 |
|
| 27 |
0 |
| croak("Shared::Arena: this region is released"); |
| 28 |
14 |
| nm = SvPV(name, nlen); |
| 29 |
32 |
▶ | for (i = 2; i + 1 < items; i += 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 2; i + 1 < items; i += 2) { |
18 |
14 |
32 |
|
| 30 |
18 |
| const char *o = SvPV_nolen(ST(i)); |
| 31 |
18 |
▶ | if (strEQ(o, "size")) size = SvUV(ST(i + 1)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(o, "size")) size = SvUV(ST(i + 1)); |
14 |
4 |
18 |
|
| 32 |
4 |
▶ | else if (strEQ(o, "slots")) slots = SvUV(ST(i + 1)); |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(o, "slots")) slots = SvUV(ST(i + 1)); |
4 |
0 |
4 |
|
| 33 |
|
| } |
| 34 |
14 |
▶ | if (slots < SA_FROZEN_MIN_SLOTS) slots = SA_FROZEN_MIN_SLOTS; |
Branch: 1 branch
| Branch | True | False | Total |
| if (slots < SA_FROZEN_MIN_SLOTS) slots = SA_FROZEN_MIN_SLOTS; |
0 |
14 |
14 |
|
| 35 |
14 |
▶ | if (slots > SA_FROZEN_MAX_SLOTS) slots = SA_FROZEN_MAX_SLOTS; |
Branch: 1 branch
| Branch | True | False | Total |
| if (slots > SA_FROZEN_MAX_SLOTS) slots = SA_FROZEN_MAX_SLOTS; |
0 |
14 |
14 |
|
| 36 |
14 |
▶ | if (!size) croak("Shared::Arena: a frozen region needs a size"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!size) croak("Shared::Arena: a frozen region needs a size"); |
0 |
14 |
14 |
|
| 37 |
|
| |
| 38 |
14 |
| e = sa_carve(arena, nm, (size_t)nlen, |
| 39 |
|
| sa_frozen_bytes((uint64_t)size, (uint32_t)slots), |
| 40 |
|
| SA_T_FROZEN, &err); |
| 41 |
14 |
▶ | if (!e) croak("Shared::Arena: the block '%s' %s", nm, sa_strerror(err)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!e) croak("Shared::Arena: the block '%s' %s", nm, sa_strerror(err)); |
1 |
13 |
14 |
|
| 42 |
|
| |
| 43 |
13 |
| f = sa_frozen_bind(arena, e, (uint64_t)size, (uint32_t)slots, &err); |
| 44 |
13 |
▶ | if (!f) croak("Shared::Arena: the block '%s' %s", nm, sa_strerror(err)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!f) croak("Shared::Arena: the block '%s' %s", nm, sa_strerror(err)); |
0 |
13 |
13 |
|
| 45 |
|
| |
| 46 |
13 |
| obj = newSV(0); |
| 47 |
13 |
| sv_setref_pv(obj, "Shared::Arena::Frozen", (void *)f); |
| 48 |
13 |
| sv_magicext(SvRV(obj), SvRV(self), PERL_MAGIC_ext, NULL, NULL, 0); |
| 49 |
13 |
| SvREFCNT_inc(SvRV(self)); |
| 50 |
13 |
| RETVAL = obj; |
| 51 |
|
| OUTPUT: |
| 52 |
|
| RETVAL |
| 53 |
|
| |
| 54 |
|
| MODULE = Shared::Arena PACKAGE = Shared::Arena::Frozen PREFIX = saf_ |
| 55 |
|
| |
| 56 |
|
| # Freeze a structure and publish it. Returns the new generation, or undef when |
| 57 |
|
| # the block does not fit the slot the region was carved with. |
| 58 |
|
| # |
| 59 |
|
| # The freezing happens through the ABI table rather than through Frozen's Perl |
| 60 |
|
| # surface, so publishing costs one call rather than a method plus a copy. |
| 61 |
|
| SV * |
| 62 |
|
| saf_publish(self, data, ...) |
| 63 |
|
| SV *self |
| 64 |
|
| SV *data |
| 65 |
|
| PREINIT: |
| 66 |
|
| sa_frozen *f; |
| 67 |
|
| SV *block; |
| 68 |
19 |
| uint64_t gen = 0; |
| 69 |
19 |
| int rc, lossy = 0; |
| 70 |
|
| I32 i; |
| 71 |
|
| CODE: |
| 72 |
19 |
| f = SA_SELF(sa_frozen, self); |
| 73 |
19 |
▶ | if (!f) croak("Shared::Arena::Frozen: this block is released"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!f) croak("Shared::Arena::Frozen: this block is released"); |
1 |
18 |
19 |
|
| 74 |
18 |
▶ | for (i = 2; i + 1 < items; i += 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 2; i + 1 < items; i += 2) { |
0 |
18 |
18 |
|
| 75 |
0 |
| const char *o = SvPV_nolen(ST(i)); |
| 76 |
0 |
▶ | if (strEQ(o, "lossy_nv")) lossy = (int)SvIV(ST(i + 1)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(o, "lossy_nv")) lossy = (int)SvIV(ST(i + 1)); |
0 |
0 |
0 |
|
| 77 |
|
| } |
| 78 |
18 |
| block = (SA_FZ->freeze)(aTHX_ data, lossy, NULL); |
| 79 |
18 |
▶ | if (!block) croak("Shared::Arena::Frozen: cannot freeze that"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!block) croak("Shared::Arena::Frozen: cannot freeze that"); |
0 |
18 |
18 |
|
| 80 |
18 |
| sv_2mortal(block); |
| 81 |
|
| |
| 82 |
18 |
| rc = sa_frozen_publish(f, SvPVX(block), (uint64_t)SvCUR(block), &gen); |
| 83 |
18 |
▶ | if (rc != SA_FZ_OK) XSRETURN_UNDEF; |
Branch: 1 branch
| Branch | True | False | Total |
| if (rc != SA_FZ_OK) XSRETURN_UNDEF; |
1 |
17 |
18 |
|
| 84 |
17 |
| RETVAL = newSVuv((UV)gen); |
| 85 |
|
| OUTPUT: |
| 86 |
|
| RETVAL |
| 87 |
|
| |
| 88 |
|
| # Publish bytes that are already a Frozen block, which is what a process that |
| 89 |
|
| # received one over the wire has. Refused unless it really is one: these bytes |
| 90 |
|
| # become every other process's structure, and the cheapest place to find out |
| 91 |
|
| # they are not a block is before publishing rather than during a read. |
| 92 |
|
| SV * |
| 93 |
|
| saf_publish_bytes(self, bytes) |
| 94 |
|
| SV *self |
| 95 |
|
| SV *bytes |
| 96 |
|
| PREINIT: |
| 97 |
|
| sa_frozen *f; |
| 98 |
|
| fz_container *c; |
| 99 |
|
| const char *p; |
| 100 |
|
| STRLEN len; |
| 101 |
3 |
| uint64_t gen = 0; |
| 102 |
3 |
| int err = 0, rc; |
| 103 |
|
| CODE: |
| 104 |
3 |
| f = SA_SELF(sa_frozen, self); |
| 105 |
3 |
▶ | if (!f) croak("Shared::Arena::Frozen: this block is released"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!f) croak("Shared::Arena::Frozen: this block is released"); |
0 |
3 |
3 |
|
| 106 |
3 |
| p = SvPV(bytes, len); |
| 107 |
3 |
| c = (SA_FZ->borrow)(p, (size_t)len, &err); |
| 108 |
3 |
▶ | if (!c) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!c) |
1 |
2 |
3 |
|
| 109 |
1 |
| croak("Shared::Arena::Frozen: those bytes %s", |
| 110 |
|
| (SA_FZ->error)(err)); |
| 111 |
2 |
▶ | if ((SA_FZ->verify)(c) <= 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((SA_FZ->verify)(c) <= 0) { |
1 |
1 |
2 |
|
| 112 |
1 |
| (void)(SA_FZ->release)(c); |
| 113 |
1 |
| croak("Shared::Arena::Frozen: that block's structure does not hold " |
| 114 |
|
| "together"); |
| 115 |
|
| } |
| 116 |
1 |
| (void)(SA_FZ->release)(c); |
| 117 |
|
| |
| 118 |
1 |
| rc = sa_frozen_publish(f, p, (uint64_t)len, &gen); |
| 119 |
1 |
▶ | if (rc != SA_FZ_OK) XSRETURN_UNDEF; |
Branch: 1 branch
| Branch | True | False | Total |
| if (rc != SA_FZ_OK) XSRETURN_UNDEF; |
0 |
1 |
1 |
|
| 120 |
1 |
| RETVAL = newSVuv((UV)gen); |
| 121 |
|
| OUTPUT: |
| 122 |
|
| RETVAL |
| 123 |
|
| |
| 124 |
|
| # A view of whatever is published now, or an EMPTY LIST when nothing is. |
| 125 |
|
| # |
| 126 |
|
| # The view BORROWS the bytes where they lie: nothing is copied, which is the |
| 127 |
|
| # whole reason this beats handing the same structure down a pipe. Take one, |
| 128 |
|
| # read it, drop it. See the POD on what holding one across a publish means. |
| 129 |
|
| void |
| 130 |
|
| saf_view(self) |
| 131 |
|
| SV *self |
| 132 |
|
| PREINIT: |
| 133 |
|
| sa_frozen *f; |
| 134 |
|
| sa_fzview *v; |
| 135 |
11 |
| const unsigned char *bytes = NULL; |
| 136 |
11 |
| uint64_t len = 0, gen = 0; |
| 137 |
11 |
| uint32_t slot = 0; |
| 138 |
|
| fz_container *c; |
| 139 |
11 |
| int err = 0; |
| 140 |
|
| SV *obj; |
| 141 |
|
| PPCODE: |
| 142 |
11 |
| f = SA_SELF(sa_frozen, self); |
| 143 |
11 |
▶ | if (!f) croak("Shared::Arena::Frozen: this block is released"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!f) croak("Shared::Arena::Frozen: this block is released"); |
0 |
11 |
11 |
|
| 144 |
11 |
▶ | if (sa_frozen_current(f, &bytes, &len, &gen, &slot) != SA_FZ_OK) |
Branch: 1 branch
| Branch | True | False | Total |
| if (sa_frozen_current(f, &bytes, &len, &gen, &slot) != SA_FZ_OK) |
2 |
9 |
11 |
|
| 145 |
2 |
| XSRETURN_EMPTY; |
| 146 |
|
| |
| 147 |
9 |
| c = (SA_FZ->borrow)(bytes, (size_t)len, &err); |
| 148 |
9 |
▶ | if (!c) XSRETURN_EMPTY; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!c) XSRETURN_EMPTY; |
0 |
9 |
9 |
|
| 149 |
|
| |
| 150 |
9 |
| Newxz(v, 1, sa_fzview); |
| 151 |
9 |
| v->c = c; |
| 152 |
9 |
| v->f = f; |
| 153 |
9 |
| v->len = len; |
| 154 |
9 |
| v->slot = slot; |
| 155 |
9 |
| v->gen = gen; |
| 156 |
|
| |
| 157 |
9 |
| obj = newSV(0); |
| 158 |
9 |
| sv_setref_pv(obj, "Shared::Arena::Frozen::View", (void *)v); |
| 159 |
|
| /* The bytes belong to the arena, so the view has to keep the tenant - |
| 160 |
|
| * and through it the region - alive for as long as it exists. */ |
| 161 |
9 |
| sv_magicext(SvRV(obj), SvRV(self), PERL_MAGIC_ext, NULL, NULL, 0); |
| 162 |
9 |
| SvREFCNT_inc(SvRV(self)); |
| 163 |
9 |
▶ | XPUSHs(sv_2mortal(obj)); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(obj)); |
0 |
9 |
9 |
|
| 164 |
|
| |
| 165 |
|
| # A value by dotted path from whatever is published NOW, or an EMPTY LIST when |
| 166 |
|
| # nothing is published or the path does not resolve. |
| 167 |
|
| # |
| 168 |
|
| # The request-path door. It reads through a reader this handle keeps over the |
| 169 |
|
| # live block and borrows again only after a publish, so there is no view to |
| 170 |
|
| # take and drop, and every call sees the latest publish. |
| 171 |
|
| void |
| 172 |
|
| saf_get(self, path, ...) |
| 173 |
|
| SV *self |
| 174 |
|
| SV *path |
| 175 |
|
| PREINIT: |
| 176 |
|
| sa_frozen *f; |
| 177 |
|
| fz_container *c; |
| 178 |
|
| const char *p; |
| 179 |
|
| STRLEN plen; |
| 180 |
10 |
| char sep = '.'; |
| 181 |
|
| uint32_t node; |
| 182 |
|
| PPCODE: |
| 183 |
10 |
| f = SA_SELF(sa_frozen, self); |
| 184 |
10 |
▶ | if (!f) croak("Shared::Arena::Frozen: this block is released"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!f) croak("Shared::Arena::Frozen: this block is released"); |
0 |
10 |
10 |
|
| 185 |
10 |
▶ | if (items > 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (items > 2) { |
2 |
8 |
10 |
|
| 186 |
|
| STRLEN slen; |
| 187 |
2 |
| const char *s = SvPV(ST(2), slen); |
| 188 |
2 |
▶ | if (slen != 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (slen != 1) |
1 |
1 |
2 |
|
| 189 |
1 |
| croak("Shared::Arena::Frozen: a separator is one character"); |
| 190 |
1 |
| sep = s[0]; |
| 191 |
|
| } |
| 192 |
9 |
| p = SvPV(path, plen); |
| 193 |
9 |
| c = sa_fz_reader(f); |
| 194 |
9 |
▶ | if (!c) XSRETURN_EMPTY; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!c) XSRETURN_EMPTY; |
1 |
8 |
9 |
|
| 195 |
8 |
| node = (SA_FZ->path)(c, (SA_FZ->root)(c), p, plen, sep); |
| 196 |
8 |
▶ | if (node == FZ_NOHANDLE) XSRETURN_EMPTY; |
Branch: 1 branch
| Branch | True | False | Total |
| if (node == FZ_NOHANDLE) XSRETURN_EMPTY; |
1 |
7 |
8 |
|
| 197 |
7 |
▶ | XPUSHs(sv_2mortal((SA_FZ->sv_from_node)(aTHX_ c, node))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal((SA_FZ->sv_from_node)(aTHX_ c, node))); |
0 |
7 |
7 |
|
| 198 |
|
| |
| 199 |
|
| # One key against the root of whatever is published now, with no path |
| 200 |
|
| # splitting: the door for a key that contains the separator. |
| 201 |
|
| void |
| 202 |
|
| saf_find(self, key) |
| 203 |
|
| SV *self |
| 204 |
|
| SV *key |
| 205 |
|
| PREINIT: |
| 206 |
|
| sa_frozen *f; |
| 207 |
|
| fz_container *c; |
| 208 |
|
| const char *k; |
| 209 |
|
| STRLEN klen; |
| 210 |
|
| uint32_t node; |
| 211 |
|
| PPCODE: |
| 212 |
2 |
| f = SA_SELF(sa_frozen, self); |
| 213 |
2 |
▶ | if (!f) croak("Shared::Arena::Frozen: this block is released"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!f) croak("Shared::Arena::Frozen: this block is released"); |
0 |
2 |
2 |
|
| 214 |
2 |
| k = SvPV(key, klen); |
| 215 |
2 |
| c = sa_fz_reader(f); |
| 216 |
2 |
▶ | if (!c) XSRETURN_EMPTY; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!c) XSRETURN_EMPTY; |
1 |
1 |
2 |
|
| 217 |
1 |
| node = (SA_FZ->child)(c, (SA_FZ->root)(c), k, klen); |
| 218 |
1 |
▶ | if (node == FZ_NOHANDLE) XSRETURN_EMPTY; |
Branch: 1 branch
| Branch | True | False | Total |
| if (node == FZ_NOHANDLE) XSRETURN_EMPTY; |
0 |
1 |
1 |
|
| 219 |
1 |
▶ | XPUSHs(sv_2mortal((SA_FZ->sv_from_node)(aTHX_ c, node))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal((SA_FZ->sv_from_node)(aTHX_ c, node))); |
0 |
1 |
1 |
|
| 220 |
|
| |
| 221 |
|
| # Whether a dotted path resolves in whatever is published now, without |
| 222 |
|
| # building the value. False when nothing is published. |
| 223 |
|
| int |
| 224 |
|
| saf_exists(self, path, ...) |
| 225 |
|
| SV *self |
| 226 |
|
| SV *path |
| 227 |
|
| PREINIT: |
| 228 |
|
| sa_frozen *f; |
| 229 |
|
| fz_container *c; |
| 230 |
|
| const char *p; |
| 231 |
|
| STRLEN plen; |
| 232 |
4 |
▶ | char sep = '.'; |
Branch: 1 branch
| Branch | True | False | Total |
| char sep = '.'; |
4 |
0 |
4 |
|
| 233 |
|
| CODE: |
| 234 |
4 |
| f = SA_SELF(sa_frozen, self); |
| 235 |
4 |
▶ | if (!f) croak("Shared::Arena::Frozen: this block is released"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!f) croak("Shared::Arena::Frozen: this block is released"); |
0 |
4 |
4 |
|
| 236 |
4 |
▶ | if (items > 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (items > 2) { |
0 |
4 |
4 |
|
| 237 |
|
| STRLEN slen; |
| 238 |
0 |
| const char *s = SvPV(ST(2), slen); |
| 239 |
0 |
▶ | if (slen != 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (slen != 1) |
0 |
0 |
0 |
|
| 240 |
0 |
| croak("Shared::Arena::Frozen: a separator is one character"); |
| 241 |
0 |
| sep = s[0]; |
| 242 |
|
| } |
| 243 |
4 |
| p = SvPV(path, plen); |
| 244 |
4 |
| c = sa_fz_reader(f); |
| 245 |
7 |
▶ | RETVAL = (c && (SA_FZ->path)(c, (SA_FZ->root)(c), p, plen, sep) |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = (c && (SA_FZ->path)(c, (SA_FZ->root)(c), p, plen, sep) |
0 |
4 |
4 |
|
| 246 |
7 |
| != FZ_NOHANDLE) ? 1 : 0; |
| 247 |
|
| OUTPUT: |
| 248 |
|
| RETVAL |
| 249 |
|
| |
| 250 |
|
| UV |
| 251 |
|
| saf_generation(self) |
| 252 |
|
| SV *self |
| 253 |
|
| PREINIT: |
| 254 |
|
| sa_frozen *f; |
| 255 |
|
| CODE: |
| 256 |
4 |
| f = SA_SELF(sa_frozen, self); |
| 257 |
4 |
▶ | if (!f) croak("Shared::Arena::Frozen: this block is released"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!f) croak("Shared::Arena::Frozen: this block is released"); |
0 |
4 |
4 |
|
| 258 |
4 |
| RETVAL = (UV)sa_at_load64_acq(&f->hdr->generation); |
| 259 |
|
| OUTPUT: |
| 260 |
|
| RETVAL |
| 261 |
|
| |
| 262 |
|
| UV |
| 263 |
|
| saf_max_block(self) |
| 264 |
|
| SV *self |
| 265 |
|
| PREINIT: |
| 266 |
|
| sa_frozen *f; |
| 267 |
|
| CODE: |
| 268 |
0 |
| f = SA_SELF(sa_frozen, self); |
| 269 |
0 |
▶ | if (!f) croak("Shared::Arena::Frozen: this block is released"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!f) croak("Shared::Arena::Frozen: this block is released"); |
0 |
0 |
0 |
|
| 270 |
0 |
▶ | RETVAL = (UV)f->slot_bytes; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = (UV)f->slot_bytes; |
0 |
0 |
0 |
|
| 271 |
|
| OUTPUT: |
| 272 |
|
| RETVAL |
| 273 |
|
| |
| 274 |
|
| # generation / published / refused / slots / max_block / bytes |
| 275 |
|
| void |
| 276 |
|
| saf_stats(self) |
| 277 |
|
| SV *self |
| 278 |
|
| PREINIT: |
| 279 |
|
| sa_frozen *f; |
| 280 |
1 |
| uint64_t len = 0; |
| 281 |
1 |
| const unsigned char *b = NULL; |
| 282 |
|
| PPCODE: |
| 283 |
1 |
| f = SA_SELF(sa_frozen, self); |
| 284 |
1 |
▶ | if (!f) croak("Shared::Arena::Frozen: this block is released"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!f) croak("Shared::Arena::Frozen: this block is released"); |
0 |
1 |
1 |
|
| 285 |
1 |
| (void)sa_frozen_current(f, &b, &len, NULL, NULL); |
| 286 |
1 |
▶ | EXTEND(SP, 12); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 12); |
0 |
1 |
1 |
|
| 287 |
1 |
| mPUSHp("generation", 10); |
| 288 |
1 |
| mPUSHu((UV)sa_at_load64_acq(&f->hdr->generation)); |
| 289 |
1 |
| mPUSHp("published", 9); |
| 290 |
1 |
| mPUSHu((UV)sa_at_load64_acq(&f->hdr->published)); |
| 291 |
1 |
| mPUSHp("refused", 7); |
| 292 |
1 |
| mPUSHu((UV)sa_at_load64_acq(&f->hdr->refused)); |
| 293 |
1 |
| mPUSHp("slots", 5); mPUSHu((UV)f->nslots); |
| 294 |
1 |
| mPUSHp("max_block", 9); mPUSHu((UV)f->slot_bytes); |
| 295 |
1 |
| mPUSHp("bytes", 5); mPUSHu((UV)len); |
| 296 |
|
| |
| 297 |
|
| void |
| 298 |
|
| saf_DESTROY(self) |
| 299 |
|
| SV *self |
| 300 |
|
| PREINIT: |
| 301 |
|
| sa_frozen *f; |
| 302 |
|
| CODE: |
| 303 |
14 |
| f = SA_SELF(sa_frozen, self); |
| 304 |
14 |
▶ | if (f) { sa_frozen_free(f); sv_setiv(SvRV(self), 0); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (f) { sa_frozen_free(f); sv_setiv(SvRV(self), 0); } |
13 |
1 |
14 |
|
| 305 |
|
| |
| 306 |
|
| MODULE = Shared::Arena PACKAGE = Shared::Arena::Frozen::View PREFIX = safv_ |
| 307 |
|
| |
| 308 |
|
| # A value by dotted path, or an EMPTY LIST when it does not resolve. |
| 309 |
|
| # |
| 310 |
|
| # The same spelling Frozen uses - `$fz->get('limits.rate')` - and the same |
| 311 |
|
| # walk, because it IS the same walk: the splitting happens in the ABI's own |
| 312 |
|
| # path entry rather than being reimplemented here to be subtly different. |
| 313 |
|
| # |
| 314 |
|
| # The separator is an argument for the case that makes a fixed one wrong, |
| 315 |
|
| # which is a key with a dot in it. |
| 316 |
|
| void |
| 317 |
|
| safv_get(self, path, ...) |
| 318 |
|
| SV *self |
| 319 |
|
| SV *path |
| 320 |
|
| PREINIT: |
| 321 |
|
| sa_fzview *v; |
| 322 |
|
| const char *p; |
| 323 |
|
| STRLEN plen; |
| 324 |
22 |
| char sep = '.'; |
| 325 |
|
| uint32_t node; |
| 326 |
|
| PPCODE: |
| 327 |
22 |
| v = SA_SELF(sa_fzview, self); |
| 328 |
22 |
▶ | if (!v || !v->c) croak("Shared::Arena::Frozen::View: this view is gone"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (!v || !v->c) croak("Shared::Arena::Frozen::View: this view is gone"); |
21 |
1 |
22 |
| if (!v || !v->c) croak("Shared::Arena::Frozen::View: this view is gone"); |
0 |
21 |
21 |
|
| 329 |
21 |
▶ | if (items > 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (items > 2) { |
1 |
20 |
21 |
|
| 330 |
|
| STRLEN slen; |
| 331 |
1 |
| const char *sp = SvPV(ST(2), slen); |
| 332 |
1 |
▶ | if (slen != 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (slen != 1) |
0 |
1 |
1 |
|
| 333 |
0 |
| croak("Shared::Arena::Frozen::View: a separator is one " |
| 334 |
|
| "character"); |
| 335 |
1 |
| sep = sp[0]; |
| 336 |
|
| } |
| 337 |
21 |
| p = SvPV(path, plen); |
| 338 |
21 |
| node = (SA_FZ->path)(v->c, (SA_FZ->root)(v->c), p, plen, sep); |
| 339 |
21 |
▶ | if (node == FZ_NOHANDLE) XSRETURN_EMPTY; |
Branch: 1 branch
| Branch | True | False | Total |
| if (node == FZ_NOHANDLE) XSRETURN_EMPTY; |
3 |
18 |
21 |
|
| 340 |
18 |
▶ | XPUSHs(sv_2mortal((SA_FZ->sv_from_node)(aTHX_ v->c, node))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal((SA_FZ->sv_from_node)(aTHX_ v->c, node))); |
0 |
18 |
18 |
|
| 341 |
|
| |
| 342 |
|
| # One key against the root, with no path splitting at all - the narrowest door, |
| 343 |
|
| # and the right one when a key contains the separator or when a caller already |
| 344 |
|
| # knows there is nothing to descend into. |
| 345 |
|
| void |
| 346 |
|
| safv_find(self, key) |
| 347 |
|
| SV *self |
| 348 |
|
| SV *key |
| 349 |
|
| PREINIT: |
| 350 |
|
| sa_fzview *v; |
| 351 |
|
| const char *k; |
| 352 |
|
| STRLEN klen; |
| 353 |
|
| uint32_t node; |
| 354 |
|
| PPCODE: |
| 355 |
1 |
| v = SA_SELF(sa_fzview, self); |
| 356 |
1 |
▶ | if (!v || !v->c) croak("Shared::Arena::Frozen::View: this view is gone"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (!v || !v->c) croak("Shared::Arena::Frozen::View: this view is gone"); |
1 |
0 |
1 |
| if (!v || !v->c) croak("Shared::Arena::Frozen::View: this view is gone"); |
0 |
1 |
1 |
|
| 357 |
1 |
| k = SvPV(key, klen); |
| 358 |
1 |
| node = (SA_FZ->child)(v->c, (SA_FZ->root)(v->c), k, klen); |
| 359 |
1 |
▶ | if (node == FZ_NOHANDLE) XSRETURN_EMPTY; |
Branch: 1 branch
| Branch | True | False | Total |
| if (node == FZ_NOHANDLE) XSRETURN_EMPTY; |
0 |
1 |
1 |
|
| 360 |
1 |
▶ | XPUSHs(sv_2mortal((SA_FZ->sv_from_node)(aTHX_ v->c, node))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal((SA_FZ->sv_from_node)(aTHX_ v->c, node))); |
0 |
1 |
1 |
|
| 361 |
|
| |
| 362 |
|
| # Whether a dotted path resolves, without building the value it resolves to. |
| 363 |
|
| # The cheap way to ask about something large. |
| 364 |
|
| int |
| 365 |
|
| safv_exists(self, path, ...) |
| 366 |
|
| SV *self |
| 367 |
|
| SV *path |
| 368 |
|
| PREINIT: |
| 369 |
|
| sa_fzview *v; |
| 370 |
|
| const char *p; |
| 371 |
|
| STRLEN plen; |
| 372 |
4 |
▶ | char sep = '.'; |
Branch: 1 branch
| Branch | True | False | Total |
| char sep = '.'; |
4 |
0 |
4 |
|
| 373 |
|
| CODE: |
| 374 |
4 |
| v = SA_SELF(sa_fzview, self); |
| 375 |
4 |
▶ | if (!v || !v->c) croak("Shared::Arena::Frozen::View: this view is gone"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (!v || !v->c) croak("Shared::Arena::Frozen::View: this view is gone"); |
4 |
0 |
4 |
| if (!v || !v->c) croak("Shared::Arena::Frozen::View: this view is gone"); |
0 |
4 |
4 |
|
| 376 |
4 |
▶ | if (items > 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (items > 2) { |
0 |
4 |
4 |
|
| 377 |
|
| STRLEN slen; |
| 378 |
0 |
| const char *sp = SvPV(ST(2), slen); |
| 379 |
0 |
▶ | if (slen != 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (slen != 1) |
0 |
0 |
0 |
|
| 380 |
0 |
| croak("Shared::Arena::Frozen::View: a separator is one " |
| 381 |
|
| "character"); |
| 382 |
0 |
| sep = sp[0]; |
| 383 |
|
| } |
| 384 |
4 |
| p = SvPV(path, plen); |
| 385 |
4 |
| RETVAL = (SA_FZ->path)(v->c, (SA_FZ->root)(v->c), p, plen, sep) |
| 386 |
4 |
▶ | != FZ_NOHANDLE ? 1 : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| != FZ_NOHANDLE ? 1 : 0; |
0 |
4 |
4 |
|
| 387 |
|
| OUTPUT: |
| 388 |
|
| RETVAL |
| 389 |
|
| |
| 390 |
|
| UV |
| 391 |
|
| safv_count(self) |
| 392 |
|
| SV *self |
| 393 |
|
| PREINIT: |
| 394 |
|
| sa_fzview *v; |
| 395 |
|
| CODE: |
| 396 |
1 |
| v = SA_SELF(sa_fzview, self); |
| 397 |
1 |
▶ | if (!v || !v->c) croak("Shared::Arena::Frozen::View: this view is gone"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (!v || !v->c) croak("Shared::Arena::Frozen::View: this view is gone"); |
1 |
0 |
1 |
| if (!v || !v->c) croak("Shared::Arena::Frozen::View: this view is gone"); |
0 |
1 |
1 |
|
| 398 |
1 |
▶ | RETVAL = (UV)(SA_FZ->count)(v->c, (SA_FZ->root)(v->c)); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = (UV)(SA_FZ->count)(v->c, (SA_FZ->root)(v->c)); |
0 |
1 |
1 |
|
| 399 |
|
| OUTPUT: |
| 400 |
|
| RETVAL |
| 401 |
|
| |
| 402 |
|
| void |
| 403 |
|
| safv_keys(self) |
| 404 |
|
| SV *self |
| 405 |
|
| PREINIT: |
| 406 |
|
| sa_fzview *v; |
| 407 |
|
| uint32_t root, n, i; |
| 408 |
|
| PPCODE: |
| 409 |
1 |
| v = SA_SELF(sa_fzview, self); |
| 410 |
1 |
▶ | if (!v || !v->c) croak("Shared::Arena::Frozen::View: this view is gone"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (!v || !v->c) croak("Shared::Arena::Frozen::View: this view is gone"); |
1 |
0 |
1 |
| if (!v || !v->c) croak("Shared::Arena::Frozen::View: this view is gone"); |
0 |
1 |
1 |
|
| 411 |
1 |
| root = (SA_FZ->root)(v->c); |
| 412 |
1 |
| n = (SA_FZ->count)(v->c, root); |
| 413 |
1 |
▶ | EXTEND(SP, (IV)n); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, (IV)n); |
0 |
1 |
1 |
|
| 414 |
7 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
6 |
1 |
7 |
|
| 415 |
6 |
| const char *k = NULL; |
| 416 |
6 |
| STRLEN klen = 0; |
| 417 |
6 |
| int utf8 = 0; |
| 418 |
6 |
▶ | if (!(SA_FZ->key_at)(v->c, root, i, &k, &klen, &utf8)) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(SA_FZ->key_at)(v->c, root, i, &k, &klen, &utf8)) continue; |
0 |
6 |
6 |
|
| 419 |
|
| { |
| 420 |
6 |
| SV *sv = newSVpvn(k, klen); |
| 421 |
6 |
▶ | if (utf8) SvUTF8_on(sv); |
Branch: 1 branch
| Branch | True | False | Total |
| if (utf8) SvUTF8_on(sv); |
0 |
6 |
6 |
|
| 422 |
6 |
| PUSHs(sv_2mortal(sv)); |
| 423 |
|
| } |
| 424 |
|
| } |
| 425 |
|
| |
| 426 |
|
| # The whole structure back as ordinary Perl data. This is the one door that |
| 427 |
|
| # costs what Storable costs, because it is the one that does what Storable |
| 428 |
|
| # does: it builds every value whether the caller wanted it or not. |
| 429 |
|
| SV * |
| 430 |
|
| safv_inflate(self) |
| 431 |
|
| SV *self |
| 432 |
|
| PREINIT: |
| 433 |
|
| sa_fzview *v; |
| 434 |
|
| CODE: |
| 435 |
1 |
| v = SA_SELF(sa_fzview, self); |
| 436 |
1 |
▶ | if (!v || !v->c) croak("Shared::Arena::Frozen::View: this view is gone"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (!v || !v->c) croak("Shared::Arena::Frozen::View: this view is gone"); |
1 |
0 |
1 |
| if (!v || !v->c) croak("Shared::Arena::Frozen::View: this view is gone"); |
0 |
1 |
1 |
|
| 437 |
1 |
| RETVAL = (SA_FZ->sv_from_node)(aTHX_ v->c, (SA_FZ->root)(v->c)); |
| 438 |
|
| OUTPUT: |
| 439 |
|
| RETVAL |
| 440 |
|
| |
| 441 |
|
| # The generation this view was opened on. |
| 442 |
|
| UV |
| 443 |
|
| safv_generation(self) |
| 444 |
|
| SV *self |
| 445 |
|
| PREINIT: |
| 446 |
|
| sa_fzview *v; |
| 447 |
|
| CODE: |
| 448 |
1 |
| v = SA_SELF(sa_fzview, self); |
| 449 |
1 |
▶ | if (!v) croak("Shared::Arena::Frozen::View: this view is gone"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!v) croak("Shared::Arena::Frozen::View: this view is gone"); |
0 |
1 |
1 |
|
| 450 |
1 |
▶ | RETVAL = (UV)v->gen; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = (UV)v->gen; |
0 |
1 |
1 |
|
| 451 |
|
| OUTPUT: |
| 452 |
|
| RETVAL |
| 453 |
|
| |
| 454 |
|
| # Whether the slot still holds the block this view was opened on. |
| 455 |
|
| # |
| 456 |
|
| # A view cannot be stopped from going stale - the bytes belong to the arena and |
| 457 |
|
| # a publisher will eventually come round to that slot again - but it can always |
| 458 |
|
| # find out. False means read it again, not that anything is broken. |
| 459 |
|
| int |
| 460 |
|
| safv_fresh(self) |
| 461 |
|
| SV *self |
| 462 |
|
| PREINIT: |
| 463 |
|
| sa_fzview *v; |
| 464 |
|
| CODE: |
| 465 |
5 |
| v = SA_SELF(sa_fzview, self); |
| 466 |
5 |
▶ | if (!v || !v->f) croak("Shared::Arena::Frozen::View: this view is gone"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (!v || !v->f) croak("Shared::Arena::Frozen::View: this view is gone"); |
5 |
0 |
5 |
| if (!v || !v->f) croak("Shared::Arena::Frozen::View: this view is gone"); |
0 |
5 |
5 |
|
| 467 |
5 |
| RETVAL = sa_frozen_fresh(v->f, v->slot, v->gen); |
| 468 |
|
| OUTPUT: |
| 469 |
|
| RETVAL |
| 470 |
|
| |
| 471 |
|
| # What the block itself says its structure is: the node count, or a negative |
| 472 |
|
| # number when it does not hold together. O(n), for a caller checking bytes it |
| 473 |
|
| # did not write. |
| 474 |
|
| IV |
| 475 |
|
| safv_verify(self) |
| 476 |
|
| SV *self |
| 477 |
|
| PREINIT: |
| 478 |
|
| sa_fzview *v; |
| 479 |
|
| CODE: |
| 480 |
1 |
| v = SA_SELF(sa_fzview, self); |
| 481 |
1 |
▶ | if (!v || !v->c) croak("Shared::Arena::Frozen::View: this view is gone"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (!v || !v->c) croak("Shared::Arena::Frozen::View: this view is gone"); |
1 |
0 |
1 |
| if (!v || !v->c) croak("Shared::Arena::Frozen::View: this view is gone"); |
0 |
1 |
1 |
|
| 482 |
1 |
| RETVAL = (IV)(SA_FZ->verify)(v->c); |
| 483 |
|
| OUTPUT: |
| 484 |
|
| RETVAL |
| 485 |
|
| |
| 486 |
|
| UV |
| 487 |
|
| safv_bytes(self) |
| 488 |
|
| SV *self |
| 489 |
|
| PREINIT: |
| 490 |
|
| sa_fzview *v; |
| 491 |
|
| CODE: |
| 492 |
1 |
| v = SA_SELF(sa_fzview, self); |
| 493 |
1 |
▶ | if (!v || !v->c) croak("Shared::Arena::Frozen::View: this view is gone"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (!v || !v->c) croak("Shared::Arena::Frozen::View: this view is gone"); |
1 |
0 |
1 |
| if (!v || !v->c) croak("Shared::Arena::Frozen::View: this view is gone"); |
0 |
1 |
1 |
|
| 494 |
1 |
▶ | RETVAL = (UV)v->len; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = (UV)v->len; |
0 |
1 |
1 |
|
| 495 |
|
| OUTPUT: |
| 496 |
|
| RETVAL |
| 497 |
|
| |
| 498 |
|
| void |
| 499 |
|
| safv_DESTROY(self) |
| 500 |
|
| SV *self |
| 501 |
|
| PREINIT: |
| 502 |
|
| sa_fzview *v; |
| 503 |
|
| CODE: |
| 504 |
10 |
| v = SA_SELF(sa_fzview, self); |
| 505 |
10 |
▶ | if (v) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (v) { |
9 |
1 |
10 |
|
| 506 |
|
| /* release is close without an interpreter, and it is the right one |
| 507 |
|
| * here: a borrowed container never holds a perl reference, and the |
| 508 |
|
| * bytes it points at are the arena's, so this frees the container |
| 509 |
|
| * and touches nothing else. */ |
| 510 |
9 |
▶ | if (v->c) (void)(SA_FZ->release)(v->c); |
Branch: 1 branch
| Branch | True | False | Total |
| if (v->c) (void)(SA_FZ->release)(v->c); |
9 |
0 |
9 |
|
| 511 |
9 |
| Safefree(v); |
| 512 |
9 |
| sv_setiv(SvRV(self), 0); |
| 513 |
|
| } |
| 514 |
|
| |
| 515 |
|
| MODULE = Shared::Arena PACKAGE = Shared::Arena |
| 516 |
|
| |
| 517 |
|
| BOOT: |
| 518 |
|
| { |
| 519 |
|
| /* The two ends of the ABI, checked here rather than at the first publish. |
| 520 |
|
| * |
| 521 |
|
| * FZ_ABI_VERSION is what THIS file was compiled against; the table says |
| 522 |
|
| * what is actually loaded. `>=` and never `==`, because the table is |
| 523 |
|
| * append-only: a newer Frozen has everything this needs and more, an older |
| 524 |
|
| * one is missing entries that would be called as null pointers - in a |
| 525 |
|
| * worker, in production, at the first request that touched a block. */ |
| 526 |
|
| SV *fzp; |
| 527 |
134 |
| dSP; |
| 528 |
134 |
| ENTER; |
| 529 |
134 |
| SAVETMPS; |
| 530 |
134 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
134 |
134 |
|
| 531 |
134 |
| PUTBACK; |
| 532 |
134 |
| call_pv("Frozen::_abi_ptr", G_SCALAR); |
| 533 |
134 |
| SPAGAIN; |
| 534 |
134 |
| fzp = POPs; |
| 535 |
134 |
| SA_FZ = INT2PTR(const fz_abi *, SvUV(fzp)); |
| 536 |
134 |
| PUTBACK; |
| 537 |
134 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
134 |
0 |
134 |
|
| 538 |
134 |
| LEAVE; |
| 539 |
|
| |
| 540 |
134 |
▶ | if (!SA_FZ) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SA_FZ) |
0 |
134 |
134 |
|
| 541 |
0 |
| croak("Shared::Arena: Frozen gave no ABI table"); |
| 542 |
134 |
▶ | if (SA_FZ->abi_version < FZ_ABI_VERSION) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SA_FZ->abi_version < FZ_ABI_VERSION) |
0 |
134 |
134 |
|
| 543 |
0 |
| croak("Shared::Arena needs Frozen ABI %d or newer, and the Frozen " |
| 544 |
|
| "that is installed publishes %d. Upgrade Frozen.", |
| 545 |
|
| (int)FZ_ABI_VERSION, (int)SA_FZ->abi_version); |
| 546 |
|
| } |