| 1 |
|
| #ifndef STORE_ABI_IMPL_H |
| 2 |
|
| #define STORE_ABI_IMPL_H |
| 3 |
|
| |
| 4 |
|
| /* The table behind state_store_abi.h. Each entry is the Perl method's own |
| 5 |
|
| * code with the checks that would croak made first and answered with a |
| 6 |
|
| * code instead: not a store, not allowed now, refused, not found. What is |
| 7 |
|
| * left to croak is what the header says may: no memory, and a Perl watcher |
| 8 |
|
| * or validator that dies. */ |
| 9 |
|
| |
| 10 |
|
| /* The struct behind a store, or NULL: never a croak. A clone in another |
| 11 |
|
| * thread, whose struct is gone, is not a store here. */ |
| 12 |
3315 |
| static store *store_try(pTHX_ SV *sv) { |
| 13 |
3315 |
▶ | if (sv && SvROK(sv) && SvTYPE(SvRV(sv)) >= SVt_PVMG) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (sv && SvROK(sv) && SvTYPE(SvRV(sv)) >= SVt_PVMG) { |
3315 |
0 |
3315 |
| if (sv && SvROK(sv) && SvTYPE(SvRV(sv)) >= SVt_PVMG) { |
3111 |
204 |
3315 |
| if (sv && SvROK(sv) && SvTYPE(SvRV(sv)) >= SVt_PVMG) { |
3111 |
0 |
3111 |
|
| 14 |
|
| MAGIC *mg; |
| 15 |
3111 |
▶ | for (mg = SvMAGIC(SvRV(sv)); mg; mg = mg->mg_moremagic) |
Branch: 1 branch
| Branch | True | False | Total |
| for (mg = SvMAGIC(SvRV(sv)); mg; mg = mg->mg_moremagic) |
3111 |
0 |
3111 |
|
| 16 |
3111 |
▶ | if (mg->mg_type == PERL_MAGIC_ext && mg->mg_virtual == &store_vtbl) |
Branch: 2 branches
| Branch | True | False | Total |
| if (mg->mg_type == PERL_MAGIC_ext && mg->mg_virtual == &store_vtbl) |
3111 |
0 |
3111 |
| if (mg->mg_type == PERL_MAGIC_ext && mg->mg_virtual == &store_vtbl) |
3111 |
0 |
3111 |
|
| 17 |
3111 |
| return (store *)mg->mg_ptr; |
| 18 |
|
| } |
| 19 |
204 |
| return NULL; |
| 20 |
|
| } |
| 21 |
|
| |
| 22 |
|
| /* A name as a scalar, for the code that takes one from Perl. */ |
| 23 |
102 |
| static SV *store_abi_name(pTHX_ const char *name, STRLEN len, int utf8) { |
| 24 |
102 |
▶ | SV *sv = sv_2mortal(newSVpvn(name ? name : "", name ? len : 0)); |
Branch: 2 branches
| Branch | True | False | Total |
| SV *sv = sv_2mortal(newSVpvn(name ? name : "", name ? len : 0)); |
102 |
0 |
102 |
| SV *sv = sv_2mortal(newSVpvn(name ? name : "", name ? len : 0)); |
102 |
0 |
102 |
|
| 25 |
102 |
▶ | if (utf8) SvUTF8_on(sv); |
Branch: 1 branch
| Branch | True | False | Total |
| if (utf8) SvUTF8_on(sv); |
0 |
102 |
102 |
|
| 26 |
102 |
| return sv; |
| 27 |
|
| } |
| 28 |
|
| |
| 29 |
51 |
| static SV *store_abi_new(pTHX_ SV *initial) { |
| 30 |
|
| store *s; |
| 31 |
51 |
▶ | SV *rv = store_new(aTHX_ gv_stashpvs("State::Store", GV_ADD), |
Branch: 1 branch
| Branch | True | False | Total |
| SV *rv = store_new(aTHX_ gv_stashpvs("State::Store", GV_ADD), |
51 |
0 |
51 |
|
| 32 |
|
| initial ? initial : &PL_sv_undef, &s); |
| 33 |
51 |
| return SvREFCNT_inc_simple_NN(rv); |
| 34 |
|
| } |
| 35 |
|
| |
| 36 |
153 |
| static int store_abi_is_store(pTHX_ SV *sv) { |
| 37 |
153 |
| return store_try(aTHX_ sv) != NULL; |
| 38 |
|
| } |
| 39 |
|
| |
| 40 |
408 |
| static SV *store_abi_current(pTHX_ SV *st) { |
| 41 |
408 |
| store *s = store_try(aTHX_ st); |
| 42 |
408 |
▶ | return s ? s->value : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| return s ? s->value : NULL; |
357 |
51 |
408 |
|
| 43 |
|
| } |
| 44 |
|
| |
| 45 |
|
| /* A change through store_put, then the watchers told. The store is held for |
| 46 |
|
| * the length of the call, as the methods hold it. */ |
| 47 |
612 |
| static int store_abi_put(pTHX_ store *s, SV *st, SV *value, int validate, const char *what) { |
| 48 |
612 |
| SV *hold = sv_2mortal(newSVsv(st)); |
| 49 |
612 |
▶ | int rc = store_put(aTHX_ s, value ? value : &PL_sv_undef, hold, validate, what); |
Branch: 1 branch
| Branch | True | False | Total |
| int rc = store_put(aTHX_ s, value ? value : &PL_sv_undef, hold, validate, what); |
612 |
0 |
612 |
|
| 50 |
612 |
| store_deliver(aTHX_ s, hold); |
| 51 |
612 |
▶ | return rc < 0 ? STATE_STORE_REFUSED : rc; |
Branch: 1 branch
| Branch | True | False | Total |
| return rc < 0 ? STATE_STORE_REFUSED : rc; |
561 |
51 |
612 |
|
| 52 |
|
| } |
| 53 |
|
| |
| 54 |
561 |
| static int store_abi_set(pTHX_ SV *st, SV *value) { |
| 55 |
561 |
| store *s = store_try(aTHX_ st); |
| 56 |
561 |
▶ | if (!s) return STATE_STORE_NOTSTORE; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!s) return STATE_STORE_NOTSTORE; |
51 |
510 |
561 |
|
| 57 |
510 |
▶ | if (s->validating) return STATE_STORE_BUSY; |
Branch: 1 branch
| Branch | True | False | Total |
| if (s->validating) return STATE_STORE_BUSY; |
0 |
510 |
510 |
|
| 58 |
510 |
| return store_abi_put(aTHX_ s, st, value, 1, "State::Store set"); |
| 59 |
|
| } |
| 60 |
|
| |
| 61 |
102 |
| static int store_abi_swap(pTHX_ SV *st, state_store_swap_fn fn, void *ud) { |
| 62 |
102 |
| store *s = store_try(aTHX_ st); |
| 63 |
|
| SV *current, *result; |
| 64 |
|
| int rc; |
| 65 |
|
| |
| 66 |
102 |
▶ | if (!s) return STATE_STORE_NOTSTORE; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!s) return STATE_STORE_NOTSTORE; |
0 |
102 |
102 |
|
| 67 |
102 |
▶ | if (s->validating) return STATE_STORE_BUSY; |
Branch: 1 branch
| Branch | True | False | Total |
| if (s->validating) return STATE_STORE_BUSY; |
0 |
102 |
102 |
|
| 68 |
102 |
| ENTER; |
| 69 |
102 |
| SAVETMPS; |
| 70 |
102 |
| current = sv_2mortal(SvREFCNT_inc_simple_NN(s->value)); |
| 71 |
102 |
| result = fn(aTHX_ ud, current); |
| 72 |
51 |
| rc = result ? store_abi_put(aTHX_ s, st, result, 1, "State::Store swap") |
| 73 |
102 |
▶ | : STATE_STORE_STOPPED; |
Branch: 1 branch
| Branch | True | False | Total |
| : STATE_STORE_STOPPED; |
51 |
51 |
102 |
|
| 74 |
102 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
102 |
0 |
102 |
|
| 75 |
102 |
| LEAVE; |
| 76 |
102 |
| return rc; |
| 77 |
|
| } |
| 78 |
|
| |
| 79 |
153 |
| static int store_abi_move(pTHX_ SV *st, int undo, size_t n, size_t *taken) { |
| 80 |
153 |
| store *s = store_try(aTHX_ st); |
| 81 |
|
| SV *hold; |
| 82 |
|
| size_t got; |
| 83 |
|
| |
| 84 |
153 |
▶ | if (taken) *taken = 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (taken) *taken = 0; |
102 |
51 |
153 |
|
| 85 |
153 |
▶ | if (!s) return STATE_STORE_NOTSTORE; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!s) return STATE_STORE_NOTSTORE; |
0 |
153 |
153 |
|
| 86 |
153 |
▶ | if (s->validating || s->txn_depth) return STATE_STORE_BUSY; |
Branch: 2 branches
| Branch | True | False | Total |
| if (s->validating || s->txn_depth) return STATE_STORE_BUSY; |
153 |
0 |
153 |
| if (s->validating || s->txn_depth) return STATE_STORE_BUSY; |
51 |
102 |
153 |
|
| 87 |
102 |
| hold = sv_2mortal(newSVsv(st)); |
| 88 |
102 |
▶ | got = store_move(aTHX_ s, undo, n, undo ? "State::Store undo" : "State::Store redo"); |
Branch: 1 branch
| Branch | True | False | Total |
| got = store_move(aTHX_ s, undo, n, undo ? "State::Store undo" : "State::Store redo"); |
51 |
51 |
102 |
|
| 89 |
102 |
▶ | if (taken) *taken = got; |
Branch: 1 branch
| Branch | True | False | Total |
| if (taken) *taken = got; |
102 |
0 |
102 |
|
| 90 |
102 |
| store_deliver(aTHX_ s, hold); |
| 91 |
102 |
| return STATE_STORE_OK; |
| 92 |
|
| } |
| 93 |
102 |
| static int store_abi_undo(pTHX_ SV *st, size_t n, size_t *taken) { |
| 94 |
102 |
| return store_abi_move(aTHX_ st, 1, n, taken); |
| 95 |
|
| } |
| 96 |
51 |
| static int store_abi_redo(pTHX_ SV *st, size_t n, size_t *taken) { |
| 97 |
51 |
| return store_abi_move(aTHX_ st, 0, n, taken); |
| 98 |
|
| } |
| 99 |
|
| |
| 100 |
102 |
| static size_t store_abi_undo_count(pTHX_ SV *st) { |
| 101 |
102 |
| store *s = store_try(aTHX_ st); |
| 102 |
102 |
▶ | return s ? store_past_len(aTHX_ s) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| return s ? store_past_len(aTHX_ s) : 0; |
102 |
0 |
102 |
|
| 103 |
|
| } |
| 104 |
153 |
| static size_t store_abi_redo_count(pTHX_ SV *st) { |
| 105 |
153 |
| store *s = store_try(aTHX_ st); |
| 106 |
153 |
▶ | return s ? (STORE_HAMT->vec_count)(aTHX_ s->future) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| return s ? (STORE_HAMT->vec_count)(aTHX_ s->future) : 0; |
153 |
0 |
153 |
|
| 107 |
|
| } |
| 108 |
|
| |
| 109 |
51 |
| static int store_abi_clear_history(pTHX_ SV *st) { |
| 110 |
51 |
| store *s = store_try(aTHX_ st); |
| 111 |
51 |
▶ | if (!s) return STATE_STORE_NOTSTORE; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!s) return STATE_STORE_NOTSTORE; |
0 |
51 |
51 |
|
| 112 |
51 |
▶ | if (s->validating || s->txn_depth) return STATE_STORE_BUSY; |
Branch: 2 branches
| Branch | True | False | Total |
| if (s->validating || s->txn_depth) return STATE_STORE_BUSY; |
51 |
0 |
51 |
| if (s->validating || s->txn_depth) return STATE_STORE_BUSY; |
0 |
51 |
51 |
|
| 113 |
51 |
| sv_2mortal(newSVsv(st)); |
| 114 |
51 |
| store_clear_history(aTHX_ s, "State::Store clear_history"); |
| 115 |
51 |
| return STATE_STORE_OK; |
| 116 |
|
| } |
| 117 |
|
| |
| 118 |
102 |
| static int store_abi_history_limit(pTHX_ SV *st, size_t *limit) { |
| 119 |
102 |
| store *s = store_try(aTHX_ st); |
| 120 |
102 |
▶ | if (!s) return STATE_STORE_NOTSTORE; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!s) return STATE_STORE_NOTSTORE; |
0 |
102 |
102 |
|
| 121 |
102 |
▶ | if (limit) *limit = s->limited ? s->limit : 0; |
Branch: 2 branches
| Branch | True | False | Total |
| if (limit) *limit = s->limited ? s->limit : 0; |
102 |
0 |
102 |
| if (limit) *limit = s->limited ? s->limit : 0; |
51 |
51 |
102 |
|
| 122 |
102 |
| return s->limited ? 1 : 0; |
| 123 |
|
| } |
| 124 |
|
| |
| 125 |
51 |
| static int store_abi_set_history_limit(pTHX_ SV *st, int limited, size_t limit) { |
| 126 |
51 |
| store *s = store_try(aTHX_ st); |
| 127 |
51 |
▶ | if (!s) return STATE_STORE_NOTSTORE; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!s) return STATE_STORE_NOTSTORE; |
0 |
51 |
51 |
|
| 128 |
51 |
▶ | if (s->validating || s->txn_depth) return STATE_STORE_BUSY; |
Branch: 2 branches
| Branch | True | False | Total |
| if (s->validating || s->txn_depth) return STATE_STORE_BUSY; |
51 |
0 |
51 |
| if (s->validating || s->txn_depth) return STATE_STORE_BUSY; |
0 |
51 |
51 |
|
| 129 |
51 |
| sv_2mortal(newSVsv(st)); |
| 130 |
51 |
▶ | store_set_limit(aTHX_ s, limited ? limit : 0, limited ? 1 : 0, "State::Store set_history_limit"); |
Branch: 1 branch
| Branch | True | False | Total |
| store_set_limit(aTHX_ s, limited ? limit : 0, limited ? 1 : 0, "State::Store set_history_limit"); |
51 |
0 |
51 |
|
| 131 |
51 |
| return STATE_STORE_OK; |
| 132 |
|
| } |
| 133 |
|
| |
| 134 |
51 |
| static UV store_abi_watch(pTHX_ SV *st, state_store_watch_fn fn, void *ud) { |
| 135 |
51 |
| store *s = store_try(aTHX_ st); |
| 136 |
51 |
▶ | if (!s || !fn) return 0; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!s || !fn) return 0; |
51 |
0 |
51 |
| if (!s || !fn) return 0; |
0 |
51 |
51 |
|
| 137 |
51 |
| return store_watch_add(aTHX_ s, NULL, fn, ud); |
| 138 |
|
| } |
| 139 |
|
| |
| 140 |
102 |
| static int store_abi_unwatch(pTHX_ SV *st, UV id) { |
| 141 |
102 |
| store *s = store_try(aTHX_ st); |
| 142 |
102 |
▶ | if (!s) return STATE_STORE_NOTSTORE; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!s) return STATE_STORE_NOTSTORE; |
0 |
102 |
102 |
|
| 143 |
102 |
▶ | return id ? store_watch_remove(aTHX_ s, id) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| return id ? store_watch_remove(aTHX_ s, id) : 0; |
102 |
0 |
102 |
|
| 144 |
|
| } |
| 145 |
|
| |
| 146 |
102 |
| static size_t store_abi_watchers(pTHX_ SV *st) { |
| 147 |
102 |
| store *s = store_try(aTHX_ st); |
| 148 |
102 |
▶ | return s ? s->live_watchers : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| return s ? s->live_watchers : 0; |
102 |
0 |
102 |
|
| 149 |
|
| } |
| 150 |
|
| |
| 151 |
102 |
| static int store_abi_set_validator(pTHX_ SV *st, state_store_validate_fn fn, void *ud) { |
| 152 |
102 |
| store *s = store_try(aTHX_ st); |
| 153 |
|
| SV *dead; |
| 154 |
102 |
▶ | if (!s) return STATE_STORE_NOTSTORE; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!s) return STATE_STORE_NOTSTORE; |
0 |
102 |
102 |
|
| 155 |
102 |
▶ | if (s->validating) return STATE_STORE_BUSY; |
Branch: 1 branch
| Branch | True | False | Total |
| if (s->validating) return STATE_STORE_BUSY; |
0 |
102 |
102 |
|
| 156 |
102 |
| dead = s->validator; |
| 157 |
102 |
| s->validator = NULL; |
| 158 |
102 |
| s->cvalidator = fn; |
| 159 |
102 |
▶ | s->cvalidator_ud = fn ? ud : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| s->cvalidator_ud = fn ? ud : NULL; |
51 |
51 |
102 |
|
| 160 |
102 |
▶ | if (dead) SvREFCNT_dec(dead); |
Branch: 1 branch
| Branch | True | False | Total |
| if (dead) SvREFCNT_dec(dead); |
0 |
102 |
102 |
|
| 161 |
102 |
| return STATE_STORE_OK; |
| 162 |
|
| } |
| 163 |
|
| |
| 164 |
|
| /* ---- transactions ------------------------------------------------------ */ |
| 165 |
|
| |
| 166 |
|
| struct state_store_txn { |
| 167 |
|
| SV *st; /* a reference of its own to the store */ |
| 168 |
|
| store_saved saved; |
| 169 |
|
| int depth; /* the depth it opened at: which one it is */ |
| 170 |
|
| }; |
| 171 |
|
| |
| 172 |
102 |
| static state_store_txn *store_abi_txn_begin(pTHX_ SV *st, int *status) { |
| 173 |
102 |
| store *s = store_try(aTHX_ st); |
| 174 |
|
| state_store_txn *t; |
| 175 |
|
| store_saved saved; |
| 176 |
|
| |
| 177 |
102 |
▶ | if (status) *status = STATE_STORE_OK; |
Branch: 1 branch
| Branch | True | False | Total |
| if (status) *status = STATE_STORE_OK; |
51 |
51 |
102 |
|
| 178 |
102 |
▶ | if (!s || s->validating) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!s || s->validating) { |
102 |
0 |
102 |
| if (!s || s->validating) { |
0 |
102 |
102 |
|
| 179 |
0 |
▶ | if (status) *status = s ? STATE_STORE_BUSY : STATE_STORE_NOTSTORE; |
Branch: 2 branches
| Branch | True | False | Total |
| if (status) *status = s ? STATE_STORE_BUSY : STATE_STORE_NOTSTORE; |
0 |
0 |
0 |
| if (status) *status = s ? STATE_STORE_BUSY : STATE_STORE_NOTSTORE; |
0 |
0 |
0 |
|
| 180 |
0 |
| return NULL; |
| 181 |
|
| } |
| 182 |
102 |
| store_txn_begin(aTHX_ s, &saved, "State::Store txn_begin"); |
| 183 |
102 |
| t = (state_store_txn *)store_alloc(aTHX_ sizeof(state_store_txn)); |
| 184 |
102 |
| t->saved = saved; |
| 185 |
102 |
| t->st = newSVsv(st); |
| 186 |
102 |
| t->depth = s->txn_depth; |
| 187 |
102 |
| return t; |
| 188 |
|
| } |
| 189 |
|
| |
| 190 |
|
| /* The transaction's store, or NULL with *rc set when it cannot be closed: |
| 191 |
|
| * gone, or not the innermost one open. */ |
| 192 |
153 |
| static store *store_abi_txn_store(pTHX_ state_store_txn *t, int *rc) { |
| 193 |
153 |
▶ | store *s = t ? store_try(aTHX_ t->st) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| store *s = t ? store_try(aTHX_ t->st) : NULL; |
153 |
0 |
153 |
|
| 194 |
153 |
▶ | if (!s) { *rc = STATE_STORE_NOTSTORE; return NULL; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (!s) { *rc = STATE_STORE_NOTSTORE; return NULL; } |
0 |
153 |
153 |
|
| 195 |
153 |
▶ | if (s->txn_depth != t->depth || s->validating) { *rc = STATE_STORE_ORDER; return NULL; } |
Branch: 2 branches
| Branch | True | False | Total |
| if (s->txn_depth != t->depth || s->validating) { *rc = STATE_STORE_ORDER; return NULL; } |
102 |
51 |
153 |
| if (s->txn_depth != t->depth || s->validating) { *rc = STATE_STORE_ORDER; return NULL; } |
0 |
102 |
102 |
|
| 196 |
102 |
| *rc = STATE_STORE_OK; |
| 197 |
102 |
| return s; |
| 198 |
|
| } |
| 199 |
|
| |
| 200 |
102 |
| static void store_abi_txn_free(pTHX_ state_store_txn *t) { |
| 201 |
102 |
| SV *st = t->st; |
| 202 |
102 |
| store_free(aTHX_ t); |
| 203 |
102 |
| SvREFCNT_dec(st); |
| 204 |
102 |
| } |
| 205 |
|
| |
| 206 |
102 |
| static int store_abi_txn_commit(pTHX_ state_store_txn *t) { |
| 207 |
|
| int rc; |
| 208 |
102 |
| store *s = store_abi_txn_store(aTHX_ t, &rc); |
| 209 |
|
| SV *hold; |
| 210 |
|
| |
| 211 |
102 |
▶ | if (!s) return rc; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!s) return rc; |
51 |
51 |
102 |
|
| 212 |
51 |
| hold = sv_2mortal(newSVsv(t->st)); |
| 213 |
51 |
▶ | if (t->depth > 1) store_txn_forget(aTHX_ s, &t->saved); |
Branch: 1 branch
| Branch | True | False | Total |
| if (t->depth > 1) store_txn_forget(aTHX_ s, &t->saved); |
0 |
51 |
51 |
|
| 214 |
51 |
| else store_txn_commit(aTHX_ s, &t->saved, "State::Store txn_commit"); |
| 215 |
51 |
| store_abi_txn_free(aTHX_ t); |
| 216 |
51 |
| store_deliver(aTHX_ s, hold); |
| 217 |
51 |
| return STATE_STORE_OK; |
| 218 |
|
| } |
| 219 |
|
| |
| 220 |
51 |
| static int store_abi_txn_abort(pTHX_ state_store_txn *t) { |
| 221 |
|
| int rc; |
| 222 |
51 |
| store *s = store_abi_txn_store(aTHX_ t, &rc); |
| 223 |
|
| |
| 224 |
51 |
▶ | if (!s) return rc; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!s) return rc; |
0 |
51 |
51 |
|
| 225 |
51 |
| sv_2mortal(newSVsv(t->st)); |
| 226 |
51 |
| store_txn_restore(aTHX_ s, &t->saved); |
| 227 |
51 |
| store_abi_txn_free(aTHX_ t); |
| 228 |
51 |
| return STATE_STORE_OK; |
| 229 |
|
| } |
| 230 |
|
| |
| 231 |
102 |
| static int store_abi_in_txn(pTHX_ SV *st) { |
| 232 |
102 |
| store *s = store_try(aTHX_ st); |
| 233 |
102 |
▶ | if (!s) return STATE_STORE_NOTSTORE; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!s) return STATE_STORE_NOTSTORE; |
0 |
102 |
102 |
|
| 234 |
102 |
| return s->txn_depth > 0; |
| 235 |
|
| } |
| 236 |
|
| |
| 237 |
|
| /* ---- checkpoints ------------------------------------------------------- */ |
| 238 |
|
| |
| 239 |
51 |
| static int store_abi_checkpoint(pTHX_ SV *st, const char *name, STRLEN len, int utf8) { |
| 240 |
51 |
| store *s = store_try(aTHX_ st); |
| 241 |
51 |
▶ | if (!s) return STATE_STORE_NOTSTORE; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!s) return STATE_STORE_NOTSTORE; |
0 |
51 |
51 |
|
| 242 |
51 |
▶ | if (s->validating) return STATE_STORE_BUSY; |
Branch: 1 branch
| Branch | True | False | Total |
| if (s->validating) return STATE_STORE_BUSY; |
0 |
51 |
51 |
|
| 243 |
51 |
| store_checkpoint(aTHX_ s, store_abi_name(aTHX_ name, len, utf8), "State::Store checkpoint"); |
| 244 |
51 |
| return STATE_STORE_OK; |
| 245 |
|
| } |
| 246 |
|
| |
| 247 |
255 |
| static SV *store_abi_checkpoint_value(pTHX_ SV *st, const char *name, STRLEN len, int utf8) { |
| 248 |
255 |
| store *s = store_try(aTHX_ st); |
| 249 |
255 |
▶ | if (!s || !s->checkpoints || !name) return NULL; |
Branch: 3 branches
| Branch | True | False | Total |
| if (!s || !s->checkpoints || !name) return NULL; |
255 |
0 |
255 |
| if (!s || !s->checkpoints || !name) return NULL; |
255 |
0 |
255 |
| if (!s || !s->checkpoints || !name) return NULL; |
0 |
255 |
255 |
|
| 250 |
255 |
| return (STORE_HAMT->map_fetch)(aTHX_ s->checkpoints, name, len, utf8); |
| 251 |
|
| } |
| 252 |
|
| |
| 253 |
102 |
| static int store_abi_has_checkpoint(pTHX_ SV *st, const char *name, STRLEN len, int utf8) { |
| 254 |
102 |
| store *s = store_try(aTHX_ st); |
| 255 |
102 |
▶ | if (!s) return STATE_STORE_NOTSTORE; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!s) return STATE_STORE_NOTSTORE; |
0 |
102 |
102 |
|
| 256 |
102 |
▶ | return s->checkpoints && name |
Branch: 1 branch
| Branch | True | False | Total |
| return s->checkpoints && name |
102 |
0 |
102 |
|
| 257 |
204 |
▶ | && (STORE_HAMT->map_has)(aTHX_ s->checkpoints, name, len, utf8); |
Branch: 2 branches
| Branch | True | False | Total |
| && (STORE_HAMT->map_has)(aTHX_ s->checkpoints, name, len, utf8); |
102 |
0 |
102 |
| && (STORE_HAMT->map_has)(aTHX_ s->checkpoints, name, len, utf8); |
51 |
51 |
102 |
|
| 258 |
|
| } |
| 259 |
|
| |
| 260 |
102 |
| static int store_abi_restore(pTHX_ SV *st, const char *name, STRLEN len, int utf8) { |
| 261 |
102 |
| store *s = store_try(aTHX_ st); |
| 262 |
|
| SV *value; |
| 263 |
102 |
▶ | if (!s) return STATE_STORE_NOTSTORE; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!s) return STATE_STORE_NOTSTORE; |
0 |
102 |
102 |
|
| 264 |
102 |
▶ | if (s->validating || s->txn_depth) return STATE_STORE_BUSY; |
Branch: 2 branches
| Branch | True | False | Total |
| if (s->validating || s->txn_depth) return STATE_STORE_BUSY; |
102 |
0 |
102 |
| if (s->validating || s->txn_depth) return STATE_STORE_BUSY; |
0 |
102 |
102 |
|
| 265 |
102 |
| value = store_abi_checkpoint_value(aTHX_ st, name, len, utf8); |
| 266 |
102 |
▶ | if (!value) return STATE_STORE_NOTFOUND; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!value) return STATE_STORE_NOTFOUND; |
51 |
51 |
102 |
|
| 267 |
51 |
| value = sv_2mortal(SvREFCNT_inc_simple_NN(value)); |
| 268 |
51 |
| return store_abi_put(aTHX_ s, st, value, 0, "State::Store restore"); |
| 269 |
|
| } |
| 270 |
|
| |
| 271 |
102 |
| static int store_abi_drop_checkpoint(pTHX_ SV *st, const char *name, STRLEN len, int utf8) { |
| 272 |
102 |
| store *s = store_try(aTHX_ st); |
| 273 |
102 |
▶ | if (!s) return STATE_STORE_NOTSTORE; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!s) return STATE_STORE_NOTSTORE; |
0 |
102 |
102 |
|
| 274 |
102 |
▶ | if (s->validating) return STATE_STORE_BUSY; |
Branch: 1 branch
| Branch | True | False | Total |
| if (s->validating) return STATE_STORE_BUSY; |
0 |
102 |
102 |
|
| 275 |
102 |
▶ | if (!store_abi_checkpoint_value(aTHX_ st, name, len, utf8)) return STATE_STORE_NOTFOUND; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!store_abi_checkpoint_value(aTHX_ st, name, len, utf8)) return STATE_STORE_NOTFOUND; |
51 |
51 |
102 |
|
| 276 |
51 |
| store_drop_checkpoint(aTHX_ s, store_abi_name(aTHX_ name, len, utf8), "State::Store drop_checkpoint"); |
| 277 |
51 |
| return STATE_STORE_OK; |
| 278 |
|
| } |
| 279 |
|
| |
| 280 |
102 |
| static size_t store_abi_checkpoint_count(pTHX_ SV *st) { |
| 281 |
102 |
| store *s = store_try(aTHX_ st); |
| 282 |
102 |
▶ | return s && s->checkpoints ? (STORE_HAMT->map_count)(aTHX_ s->checkpoints) : 0; |
Branch: 2 branches
| Branch | True | False | Total |
| return s && s->checkpoints ? (STORE_HAMT->map_count)(aTHX_ s->checkpoints) : 0; |
102 |
0 |
102 |
| return s && s->checkpoints ? (STORE_HAMT->map_count)(aTHX_ s->checkpoints) : 0; |
102 |
0 |
102 |
|
| 283 |
|
| } |
| 284 |
|
| |
| 285 |
|
| typedef struct store_abi_walk { state_store_name_fn fn; void *ud; } store_abi_walk; |
| 286 |
|
| |
| 287 |
51 |
| static int store_abi_walk_one(pTHX_ void *ud, const char *key, STRLEN klen, int utf8, SV *value) { |
| 288 |
51 |
| store_abi_walk *w = (store_abi_walk *)ud; |
| 289 |
51 |
| return w->fn(aTHX_ w->ud, key, klen, utf8, value); |
| 290 |
|
| } |
| 291 |
|
| |
| 292 |
51 |
| static int store_abi_checkpoint_walk(pTHX_ SV *st, state_store_name_fn fn, void *ud) { |
| 293 |
51 |
| store *s = store_try(aTHX_ st); |
| 294 |
|
| store_abi_walk w; |
| 295 |
51 |
▶ | if (!s) return STATE_STORE_NOTSTORE; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!s) return STATE_STORE_NOTSTORE; |
0 |
51 |
51 |
|
| 296 |
51 |
▶ | if (!s->checkpoints) return STATE_STORE_OK; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!s->checkpoints) return STATE_STORE_OK; |
0 |
51 |
51 |
|
| 297 |
51 |
| w.fn = fn; |
| 298 |
51 |
| w.ud = ud; |
| 299 |
51 |
| return (STORE_HAMT->map_walk)(aTHX_ s->checkpoints, store_abi_walk_one, &w) == HAMT_ABI_OK |
| 300 |
51 |
▶ | ? STATE_STORE_OK : STATE_STORE_STOPPED; |
Branch: 1 branch
| Branch | True | False | Total |
| ? STATE_STORE_OK : STATE_STORE_STOPPED; |
51 |
0 |
51 |
|
| 301 |
|
| } |
| 302 |
|
| |
| 303 |
|
| /* ---- the table --------------------------------------------------------- */ |
| 304 |
|
| |
| 305 |
|
| static const state_store_abi STORE_ABI = { |
| 306 |
|
| STATE_STORE_ABI_VERSION, |
| 307 |
|
| |
| 308 |
|
| store_abi_new, |
| 309 |
|
| store_abi_is_store, |
| 310 |
|
| |
| 311 |
|
| store_abi_current, |
| 312 |
|
| store_abi_set, |
| 313 |
|
| store_abi_swap, |
| 314 |
|
| |
| 315 |
|
| store_abi_undo, |
| 316 |
|
| store_abi_redo, |
| 317 |
|
| store_abi_undo_count, |
| 318 |
|
| store_abi_redo_count, |
| 319 |
|
| store_abi_clear_history, |
| 320 |
|
| store_abi_history_limit, |
| 321 |
|
| store_abi_set_history_limit, |
| 322 |
|
| |
| 323 |
|
| store_abi_watch, |
| 324 |
|
| store_abi_unwatch, |
| 325 |
|
| store_abi_watchers, |
| 326 |
|
| store_abi_set_validator, |
| 327 |
|
| |
| 328 |
|
| store_abi_txn_begin, |
| 329 |
|
| store_abi_txn_commit, |
| 330 |
|
| store_abi_txn_abort, |
| 331 |
|
| store_abi_in_txn, |
| 332 |
|
| |
| 333 |
|
| store_abi_checkpoint, |
| 334 |
|
| store_abi_restore, |
| 335 |
|
| store_abi_has_checkpoint, |
| 336 |
|
| store_abi_checkpoint_value, |
| 337 |
|
| store_abi_drop_checkpoint, |
| 338 |
|
| store_abi_checkpoint_count, |
| 339 |
|
| store_abi_checkpoint_walk |
| 340 |
|
| }; |
| 341 |
|
| |
| 342 |
|
| #endif |