| 1 |
|
| #include "EXTERN.h" |
| 2 |
|
| #include "perl.h" |
| 3 |
|
| #include "XSUB.h" |
| 4 |
|
| |
| 5 |
|
| #include "ppport.h" |
| 6 |
|
| #include "mmap_cache.h" |
| 7 |
|
| |
| 8 |
|
| #define FC_UTF8VAL (1<<31) |
| 9 |
|
| #define FC_UTF8KEY (1<<30) |
| 10 |
|
| #define FC_UNDEF (1<<29) |
| 11 |
|
| |
| 12 |
|
| #define FC_ENTRY \ |
| 13 |
|
| mmap_cache * cache; \ |
| 14 |
|
| if (!SvROK(obj)) { \ |
| 15 |
|
| croak("Object not reference"); \ |
| 16 |
|
| XSRETURN_UNDEF; \ |
| 17 |
|
| } \ |
| 18 |
|
| obj = SvRV(obj); \ |
| 19 |
|
| if (!SvIOKp(obj)) { \ |
| 20 |
|
| croak("Object not initialised correctly"); \ |
| 21 |
|
| XSRETURN_UNDEF; \ |
| 22 |
|
| } \ |
| 23 |
|
| cache = INT2PTR(mmap_cache *, SvIV(obj) ); \ |
| 24 |
|
| if (!cache) { \ |
| 25 |
|
| croak("Object not created correctly"); \ |
| 26 |
|
| XSRETURN_UNDEF; \ |
| 27 |
|
| } |
| 28 |
|
| |
| 29 |
|
| |
| 30 |
|
| MODULE = Cache::FastMmap PACKAGE = Cache::FastMmap |
| 31 |
|
| PROTOTYPES: ENABLE |
| 32 |
|
| |
| 33 |
|
| SV * |
| 34 |
|
| fc_new() |
| 35 |
|
| INIT: |
| 36 |
|
| mmap_cache * cache; |
| 37 |
|
| SV * obj_pnt, * obj; |
| 38 |
|
| CODE: |
| 39 |
8068 |
| cache = mmc_new(); |
| 40 |
|
| |
| 41 |
|
| /* Create integer which is pointer to cache object */ |
| 42 |
8068 |
| obj_pnt = newSViv(PTR2IV(cache)); |
| 43 |
|
| |
| 44 |
|
| /* Create reference to integer value. This will be the object */ |
| 45 |
8068 |
| obj = newRV_noinc((SV *)obj_pnt); |
| 46 |
|
| |
| 47 |
8068 |
| RETVAL = obj; |
| 48 |
|
| OUTPUT: |
| 49 |
|
| RETVAL |
| 50 |
|
| |
| 51 |
|
| NO_OUTPUT int |
| 52 |
|
| fc_set_param(obj, param, val) |
| 53 |
|
| SV * obj; |
| 54 |
|
| char * param; |
| 55 |
|
| char * val; |
| 56 |
|
| INIT: |
| 57 |
72614 |
▶ | FC_ENTRY |
Branch: 3 branches
| Branch | True | False | Total |
| FC_ENTRY |
0 |
72614 |
72614 |
| FC_ENTRY |
0 |
72614 |
72614 |
| FC_ENTRY |
0 |
72614 |
72614 |
|
| 58 |
|
| |
| 59 |
|
| CODE: |
| 60 |
72614 |
| RETVAL = mmc_set_param(cache, param, val); |
| 61 |
|
| POSTCALL: |
| 62 |
72614 |
▶ | if (RETVAL != 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (RETVAL != 0) { |
0 |
72614 |
72614 |
|
| 63 |
0 |
| croak("%s", mmc_error(cache)); |
| 64 |
|
| } |
| 65 |
|
| |
| 66 |
|
| NO_OUTPUT int |
| 67 |
|
| fc_init(obj) |
| 68 |
|
| SV * obj; |
| 69 |
|
| INIT: |
| 70 |
8068 |
▶ | FC_ENTRY |
Branch: 3 branches
| Branch | True | False | Total |
| FC_ENTRY |
0 |
8068 |
8068 |
| FC_ENTRY |
0 |
8068 |
8068 |
| FC_ENTRY |
0 |
8068 |
8068 |
|
| 71 |
|
| |
| 72 |
|
| CODE: |
| 73 |
8068 |
| RETVAL = mmc_init(cache); |
| 74 |
|
| POSTCALL: |
| 75 |
8068 |
▶ | if (RETVAL != 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (RETVAL != 0) { |
0 |
8068 |
8068 |
|
| 76 |
0 |
| croak("%s", mmc_error(cache)); |
| 77 |
|
| } |
| 78 |
8068 |
▶ | if (mmc_get_param(cache, "repaired_pages") > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (mmc_get_param(cache, "repaired_pages") > 0) { |
0 |
8068 |
8068 |
|
| 79 |
0 |
| warn("Cache::FastMmap: %d page(s) reinitialised on open, last: %s", |
| 80 |
|
| mmc_get_param(cache, "repaired_pages"), mmc_error(cache)); |
| 81 |
|
| } |
| 82 |
|
| |
| 83 |
|
| |
| 84 |
|
| int |
| 85 |
|
| fc_get_param(obj, param) |
| 86 |
|
| SV * obj; |
| 87 |
|
| char * param; |
| 88 |
|
| INIT: |
| 89 |
0 |
▶ | FC_ENTRY |
Branch: 3 branches
| Branch | True | False | Total |
| FC_ENTRY |
0 |
0 |
0 |
| FC_ENTRY |
0 |
0 |
0 |
| FC_ENTRY |
0 |
0 |
0 |
|
| 90 |
|
| |
| 91 |
|
| CODE: |
| 92 |
0 |
| RETVAL = mmc_get_param(cache, param); |
| 93 |
|
| OUTPUT: |
| 94 |
|
| RETVAL |
| 95 |
|
| |
| 96 |
|
| |
| 97 |
|
| void |
| 98 |
|
| fc_close(obj) |
| 99 |
|
| SV * obj |
| 100 |
|
| INIT: |
| 101 |
8068 |
▶ | FC_ENTRY |
Branch: 3 branches
| Branch | True | False | Total |
| FC_ENTRY |
0 |
8068 |
8068 |
| FC_ENTRY |
0 |
8068 |
8068 |
| FC_ENTRY |
0 |
8068 |
8068 |
|
| 102 |
|
| |
| 103 |
|
| CODE: |
| 104 |
8068 |
| mmc_close(cache); |
| 105 |
8068 |
| sv_setiv(obj, 0); |
| 106 |
|
| |
| 107 |
|
| |
| 108 |
|
| void |
| 109 |
|
| fc_hash(obj, key); |
| 110 |
|
| SV * obj; |
| 111 |
|
| SV * key; |
| 112 |
|
| INIT: |
| 113 |
|
| int key_len; |
| 114 |
|
| void * key_ptr; |
| 115 |
|
| MU32 hash_page, hash_slot; |
| 116 |
|
| STRLEN pl_key_len; |
| 117 |
|
| |
| 118 |
288611 |
▶ | FC_ENTRY |
Branch: 3 branches
| Branch | True | False | Total |
| FC_ENTRY |
0 |
288611 |
288611 |
| FC_ENTRY |
0 |
288611 |
288611 |
| FC_ENTRY |
0 |
288611 |
288611 |
|
| 119 |
|
| |
| 120 |
|
| PPCODE: |
| 121 |
|
| |
| 122 |
|
| /* Get key length, data pointer */ |
| 123 |
288611 |
| key_ptr = (void *)SvPV(key, pl_key_len); |
| 124 |
288611 |
| key_len = (int)pl_key_len; |
| 125 |
|
| |
| 126 |
|
| /* Hash key to get page and slot */ |
| 127 |
288611 |
| mmc_hash(cache, key_ptr, key_len, &hash_page, &hash_slot); |
| 128 |
|
| |
| 129 |
288611 |
▶ | XPUSHs(sv_2mortal(newSViv((IV)hash_page))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSViv((IV)hash_page))); |
0 |
288611 |
288611 |
|
| 130 |
288611 |
▶ | XPUSHs(sv_2mortal(newSViv((IV)hash_slot))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSViv((IV)hash_slot))); |
0 |
288611 |
288611 |
|
| 131 |
|
| |
| 132 |
|
| |
| 133 |
|
| NO_OUTPUT int |
| 134 |
|
| fc_lock(obj, page); |
| 135 |
|
| SV * obj; |
| 136 |
|
| UV page; |
| 137 |
|
| INIT: |
| 138 |
269587 |
▶ | FC_ENTRY |
Branch: 3 branches
| Branch | True | False | Total |
| FC_ENTRY |
0 |
269587 |
269587 |
| FC_ENTRY |
0 |
269587 |
269587 |
| FC_ENTRY |
0 |
269587 |
269587 |
|
| 139 |
|
| |
| 140 |
|
| CODE: |
| 141 |
269587 |
| RETVAL = mmc_lock(cache, (MU32)page); |
| 142 |
|
| POSTCALL: |
| 143 |
269587 |
▶ | if (RETVAL != 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (RETVAL != 0) { |
1 |
269586 |
269587 |
|
| 144 |
1 |
| croak("%s", mmc_error(cache)); |
| 145 |
|
| } |
| 146 |
269586 |
▶ | if (mmc_page_repaired(cache)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (mmc_page_repaired(cache)) { |
0 |
269586 |
269586 |
|
| 147 |
0 |
| warn("Cache::FastMmap: %s", mmc_error(cache)); |
| 148 |
|
| } |
| 149 |
|
| |
| 150 |
|
| |
| 151 |
|
| NO_OUTPUT int |
| 152 |
|
| fc_unlock(obj); |
| 153 |
|
| SV * obj; |
| 154 |
|
| INIT: |
| 155 |
269586 |
▶ | FC_ENTRY |
Branch: 3 branches
| Branch | True | False | Total |
| FC_ENTRY |
0 |
269586 |
269586 |
| FC_ENTRY |
0 |
269586 |
269586 |
| FC_ENTRY |
0 |
269586 |
269586 |
|
| 156 |
|
| |
| 157 |
|
| CODE: |
| 158 |
269586 |
| RETVAL = mmc_unlock(cache); |
| 159 |
|
| POSTCALL: |
| 160 |
269586 |
▶ | if (RETVAL != 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (RETVAL != 0) { |
0 |
269586 |
269586 |
|
| 161 |
0 |
| croak("%s", mmc_error(cache)); |
| 162 |
|
| } |
| 163 |
269586 |
▶ | if (mmc_page_repaired(cache)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (mmc_page_repaired(cache)) { |
0 |
269586 |
269586 |
|
| 164 |
0 |
| warn("Cache::FastMmap: %s", mmc_error(cache)); |
| 165 |
|
| } |
| 166 |
|
| |
| 167 |
|
| int |
| 168 |
|
| fc_is_locked(obj) |
| 169 |
|
| SV * obj; |
| 170 |
|
| INIT: |
| 171 |
103572 |
▶ | FC_ENTRY |
Branch: 3 branches
| Branch | True | False | Total |
| FC_ENTRY |
0 |
103572 |
103572 |
| FC_ENTRY |
0 |
103572 |
103572 |
| FC_ENTRY |
0 |
103572 |
103572 |
|
| 172 |
|
| |
| 173 |
|
| CODE: |
| 174 |
|
| /* Write value to cache */ |
| 175 |
103572 |
| RETVAL = mmc_is_locked(cache); |
| 176 |
|
| |
| 177 |
|
| OUTPUT: |
| 178 |
|
| RETVAL |
| 179 |
|
| |
| 180 |
|
| |
| 181 |
|
| void |
| 182 |
|
| fc_read(obj, hash_slot, key) |
| 183 |
|
| SV * obj; |
| 184 |
|
| U32 hash_slot; |
| 185 |
|
| SV * key; |
| 186 |
|
| INIT: |
| 187 |
|
| int key_len, val_len, found; |
| 188 |
|
| void * key_ptr, * val_ptr; |
| 189 |
186070 |
| MU32 expire_on = 0; |
| 190 |
186070 |
| MU32 flags = 0; |
| 191 |
186070 |
| MU64 modseq = 0; |
| 192 |
|
| STRLEN pl_key_len; |
| 193 |
|
| SV * val; |
| 194 |
|
| SV * modseq_sv; |
| 195 |
|
| |
| 196 |
186070 |
▶ | FC_ENTRY |
Branch: 3 branches
| Branch | True | False | Total |
| FC_ENTRY |
0 |
186070 |
186070 |
| FC_ENTRY |
0 |
186070 |
186070 |
| FC_ENTRY |
0 |
186070 |
186070 |
|
| 197 |
|
| |
| 198 |
|
| PPCODE: |
| 199 |
|
| |
| 200 |
|
| /* Get key length, data pointer */ |
| 201 |
186070 |
| key_ptr = (void *)SvPV(key, pl_key_len); |
| 202 |
186070 |
| key_len = (int)pl_key_len; |
| 203 |
|
| |
| 204 |
|
| /* Get value data pointer */ |
| 205 |
186070 |
| found = mmc_read(cache, (MU32)hash_slot, key_ptr, key_len, &val_ptr, &val_len, &expire_on, &flags, &modseq); |
| 206 |
|
| |
| 207 |
186070 |
| modseq_sv = &PL_sv_undef; |
| 208 |
|
| |
| 209 |
|
| /* If not found, use undef */ |
| 210 |
186070 |
▶ | if (found == -1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (found == -1) { |
39485 |
146585 |
186070 |
|
| 211 |
39485 |
| val = &PL_sv_undef; |
| 212 |
|
| } else { |
| 213 |
|
| |
| 214 |
|
| /* Cached an undef value? */ |
| 215 |
146585 |
▶ | if (flags & FC_UNDEF) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (flags & FC_UNDEF) { |
1883 |
144702 |
146585 |
|
| 216 |
1883 |
| val = &PL_sv_undef; |
| 217 |
|
| |
| 218 |
|
| } else { |
| 219 |
|
| |
| 220 |
|
| /* Create PERL SV */ |
| 221 |
144702 |
| val = sv_2mortal(newSVpvn((const char *)val_ptr, val_len)); |
| 222 |
|
| |
| 223 |
|
| /* Make UTF8 if stored from UTF8 */ |
| 224 |
144702 |
▶ | if (flags & FC_UTF8VAL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (flags & FC_UTF8VAL) { |
1891 |
142811 |
144702 |
|
| 225 |
1891 |
| SvUTF8_on(val); |
| 226 |
|
| } |
| 227 |
|
| |
| 228 |
|
| } |
| 229 |
|
| |
| 230 |
146585 |
▶ | if (flags & FC_HASMODSEQ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (flags & FC_HASMODSEQ) { |
10 |
146575 |
146585 |
|
| 231 |
10 |
| modseq_sv = sv_2mortal(newSVuv((UV)modseq)); |
| 232 |
|
| } |
| 233 |
|
| |
| 234 |
146585 |
| flags = flags & ~(FC_UTF8KEY | FC_UTF8VAL | FC_UNDEF | FC_HASMODSEQ | FC_TOMBSTONE); |
| 235 |
|
| } |
| 236 |
|
| |
| 237 |
186070 |
▶ | XPUSHs(val); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(val); |
0 |
186070 |
186070 |
|
| 238 |
186070 |
▶ | XPUSHs(sv_2mortal(newSViv((IV)flags))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSViv((IV)flags))); |
0 |
186070 |
186070 |
|
| 239 |
186070 |
▶ | XPUSHs(sv_2mortal(newSViv((IV)!found))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSViv((IV)!found))); |
0 |
186070 |
186070 |
|
| 240 |
186070 |
▶ | XPUSHs(sv_2mortal(newSViv((IV)expire_on))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSViv((IV)expire_on))); |
0 |
186070 |
186070 |
|
| 241 |
186070 |
▶ | XPUSHs(modseq_sv); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(modseq_sv); |
0 |
186070 |
186070 |
|
| 242 |
|
| |
| 243 |
|
| |
| 244 |
|
| int |
| 245 |
|
| fc_write(obj, hash_slot, key, val, expire_on, in_flags, modseq_sv = &PL_sv_undef) |
| 246 |
|
| SV * obj; |
| 247 |
|
| U32 hash_slot; |
| 248 |
|
| SV * key; |
| 249 |
|
| SV * val; |
| 250 |
|
| U32 expire_on; |
| 251 |
|
| U32 in_flags; |
| 252 |
|
| SV * modseq_sv; |
| 253 |
|
| INIT: |
| 254 |
|
| int key_len, val_len; |
| 255 |
|
| void * key_ptr, * val_ptr; |
| 256 |
103714 |
| MU64 modseq = 0; |
| 257 |
|
| STRLEN pl_key_len, pl_val_len; |
| 258 |
|
| |
| 259 |
103714 |
▶ | FC_ENTRY |
Branch: 3 branches
| Branch | True | False | Total |
| FC_ENTRY |
0 |
103714 |
103714 |
| FC_ENTRY |
0 |
103714 |
103714 |
| FC_ENTRY |
0 |
103714 |
103714 |
|
| 260 |
|
| |
| 261 |
|
| CODE: |
| 262 |
|
| |
| 263 |
|
| /* Get key length, data pointer */ |
| 264 |
103714 |
| key_ptr = (void *)SvPV(key, pl_key_len); |
| 265 |
103714 |
| key_len = (int)pl_key_len; |
| 266 |
|
| |
| 267 |
|
| /* Storing with a modseq? (see TOMBSTONES AND MODSEQS in the pod) */ |
| 268 |
103714 |
▶ | if (SvOK(modseq_sv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvOK(modseq_sv)) { |
19 |
103695 |
103714 |
|
| 269 |
|
| if (sizeof(UV) < sizeof(MU64)) |
| 270 |
|
| croak("modseq support requires a 64 bit perl"); |
| 271 |
19 |
| in_flags |= FC_HASMODSEQ; |
| 272 |
19 |
| modseq = (MU64)SvUV(modseq_sv); |
| 273 |
|
| } |
| 274 |
|
| |
| 275 |
|
| /* Check for storing undef, and store empty string with undef flag set */ |
| 276 |
103714 |
▶ | if (!SvOK(val)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvOK(val)) { |
8023 |
95691 |
103714 |
|
| 277 |
8023 |
| in_flags |= FC_UNDEF; |
| 278 |
|
| |
| 279 |
8023 |
| val_ptr = ""; |
| 280 |
8023 |
| val_len = 0; |
| 281 |
|
| |
| 282 |
|
| } else { |
| 283 |
|
| |
| 284 |
|
| /* Get key length, data pointer */ |
| 285 |
95691 |
| val_ptr = (void *)SvPV(val, pl_val_len); |
| 286 |
95691 |
| val_len = (int)pl_val_len; |
| 287 |
|
| |
| 288 |
|
| /* Set UTF8-ness flag of stored value */ |
| 289 |
95691 |
▶ | if (SvUTF8(val)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvUTF8(val)) { |
8024 |
87667 |
95691 |
|
| 290 |
8024 |
| in_flags |= FC_UTF8VAL; |
| 291 |
|
| } |
| 292 |
95691 |
▶ | if (SvUTF8(key)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvUTF8(key)) { |
4 |
95687 |
95691 |
|
| 293 |
4 |
| in_flags |= FC_UTF8KEY; |
| 294 |
|
| } |
| 295 |
|
| } |
| 296 |
|
| |
| 297 |
|
| /* Write value to cache (1 stored, 0 no space, -1 refused) */ |
| 298 |
103714 |
| RETVAL = mmc_write(cache, (MU32)hash_slot, key_ptr, key_len, val_ptr, val_len, (MU32)expire_on, (MU32)in_flags, modseq); |
| 299 |
|
| |
| 300 |
|
| OUTPUT: |
| 301 |
|
| RETVAL |
| 302 |
|
| |
| 303 |
|
| int |
| 304 |
|
| fc_tombstone(obj, hash_slot, key, expire_on, modseq_sv) |
| 305 |
|
| SV * obj; |
| 306 |
|
| U32 hash_slot; |
| 307 |
|
| SV * key; |
| 308 |
|
| U32 expire_on; |
| 309 |
|
| SV * modseq_sv; |
| 310 |
|
| INIT: |
| 311 |
|
| int key_len; |
| 312 |
|
| void * key_ptr; |
| 313 |
7 |
| MU32 in_flags = FC_TOMBSTONE | FC_HASMODSEQ; |
| 314 |
|
| MU64 modseq; |
| 315 |
|
| STRLEN pl_key_len; |
| 316 |
|
| |
| 317 |
7 |
▶ | FC_ENTRY |
Branch: 3 branches
| Branch | True | False | Total |
| FC_ENTRY |
0 |
7 |
7 |
| FC_ENTRY |
0 |
7 |
7 |
| FC_ENTRY |
0 |
7 |
7 |
|
| 318 |
|
| |
| 319 |
|
| CODE: |
| 320 |
|
| |
| 321 |
|
| if (sizeof(UV) < sizeof(MU64)) |
| 322 |
|
| croak("modseq support requires a 64 bit perl"); |
| 323 |
7 |
▶ | if (!SvOK(modseq_sv)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvOK(modseq_sv)) |
0 |
7 |
7 |
|
| 324 |
0 |
| croak("fc_tombstone requires a modseq"); |
| 325 |
7 |
| modseq = (MU64)SvUV(modseq_sv); |
| 326 |
|
| |
| 327 |
|
| /* Get key length, data pointer */ |
| 328 |
7 |
| key_ptr = (void *)SvPV(key, pl_key_len); |
| 329 |
7 |
| key_len = (int)pl_key_len; |
| 330 |
7 |
▶ | if (SvUTF8(key)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvUTF8(key)) { |
0 |
7 |
7 |
|
| 331 |
0 |
| in_flags |= FC_UTF8KEY; |
| 332 |
|
| } |
| 333 |
|
| |
| 334 |
|
| /* A tombstone is an empty value with the modseq prefix; mmc_write |
| 335 |
|
| * enforces never lowering an existing tombstone's modseq */ |
| 336 |
7 |
| RETVAL = mmc_write(cache, (MU32)hash_slot, key_ptr, key_len, "", 0, (MU32)expire_on, in_flags, modseq); |
| 337 |
|
| |
| 338 |
|
| OUTPUT: |
| 339 |
|
| RETVAL |
| 340 |
|
| |
| 341 |
|
| int |
| 342 |
|
| fc_delete(obj, hash_slot, key) |
| 343 |
|
| SV * obj; |
| 344 |
|
| U32 hash_slot; |
| 345 |
|
| SV * key; |
| 346 |
|
| INIT: |
| 347 |
|
| MU32 out_flags; |
| 348 |
|
| int key_len, did_delete; |
| 349 |
|
| void * key_ptr; |
| 350 |
|
| STRLEN pl_key_len; |
| 351 |
|
| |
| 352 |
11396 |
▶ | FC_ENTRY |
Branch: 3 branches
| Branch | True | False | Total |
| FC_ENTRY |
0 |
11396 |
11396 |
| FC_ENTRY |
0 |
11396 |
11396 |
| FC_ENTRY |
0 |
11396 |
11396 |
|
| 353 |
|
| |
| 354 |
|
| PPCODE: |
| 355 |
|
| |
| 356 |
|
| /* Get key length, data pointer */ |
| 357 |
11396 |
| key_ptr = (void *)SvPV(key, pl_key_len); |
| 358 |
11396 |
| key_len = (int)pl_key_len; |
| 359 |
|
| |
| 360 |
|
| /* Write value to cache */ |
| 361 |
11396 |
| did_delete = mmc_delete(cache, (MU32)hash_slot, key_ptr, key_len, &out_flags); |
| 362 |
|
| |
| 363 |
11396 |
▶ | XPUSHs(sv_2mortal(newSViv((IV)did_delete))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSViv((IV)did_delete))); |
0 |
11396 |
11396 |
|
| 364 |
11396 |
▶ | XPUSHs(sv_2mortal(newSViv((IV)out_flags))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSViv((IV)out_flags))); |
0 |
11396 |
11396 |
|
| 365 |
|
| |
| 366 |
|
| |
| 367 |
|
| void |
| 368 |
|
| fc_get_page_details(obj) |
| 369 |
|
| SV * obj; |
| 370 |
|
| INIT: |
| 371 |
267 |
| MU32 nreads = 0, nreadhits = 0; |
| 372 |
|
| |
| 373 |
267 |
▶ | FC_ENTRY |
Branch: 3 branches
| Branch | True | False | Total |
| FC_ENTRY |
0 |
267 |
267 |
| FC_ENTRY |
0 |
267 |
267 |
| FC_ENTRY |
0 |
267 |
267 |
|
| 374 |
|
| |
| 375 |
|
| PPCODE: |
| 376 |
267 |
| mmc_get_page_details(cache, &nreads, &nreadhits); |
| 377 |
|
| |
| 378 |
267 |
▶ | XPUSHs(sv_2mortal(newSViv((IV)nreads))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSViv((IV)nreads))); |
0 |
267 |
267 |
|
| 379 |
267 |
▶ | XPUSHs(sv_2mortal(newSViv((IV)nreadhits))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSViv((IV)nreadhits))); |
0 |
267 |
267 |
|
| 380 |
|
| |
| 381 |
|
| |
| 382 |
|
| NO_OUTPUT void |
| 383 |
|
| fc_reset_page_details(obj) |
| 384 |
|
| SV * obj; |
| 385 |
|
| INIT: |
| 386 |
178 |
▶ | FC_ENTRY |
Branch: 3 branches
| Branch | True | False | Total |
| FC_ENTRY |
0 |
178 |
178 |
| FC_ENTRY |
0 |
178 |
178 |
| FC_ENTRY |
0 |
178 |
178 |
|
| 387 |
|
| |
| 388 |
|
| CODE: |
| 389 |
178 |
| mmc_reset_page_details(cache); |
| 390 |
|
| |
| 391 |
|
| |
| 392 |
|
| |
| 393 |
|
| void |
| 394 |
|
| fc_expunge(obj, mode, wb, len) |
| 395 |
|
| SV * obj; |
| 396 |
|
| int mode; |
| 397 |
|
| int wb; |
| 398 |
|
| int len; |
| 399 |
|
| INIT: |
| 400 |
104459 |
| MU32 new_num_slots = 0, ** to_expunge = 0; |
| 401 |
|
| int num_expunge, item; |
| 402 |
|
| |
| 403 |
|
| void * key_ptr, * val_ptr; |
| 404 |
|
| int key_len, val_len; |
| 405 |
|
| MU32 last_access, expire_on, flags; |
| 406 |
|
| |
| 407 |
104459 |
▶ | FC_ENTRY |
Branch: 3 branches
| Branch | True | False | Total |
| FC_ENTRY |
0 |
104459 |
104459 |
| FC_ENTRY |
0 |
104459 |
104459 |
| FC_ENTRY |
0 |
104459 |
104459 |
|
| 408 |
|
| |
| 409 |
|
| PPCODE: |
| 410 |
|
| |
| 411 |
104459 |
| num_expunge = mmc_calc_expunge(cache, mode, len, &new_num_slots, &to_expunge); |
| 412 |
104459 |
▶ | if (to_expunge) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (to_expunge) { |
9065 |
95394 |
104459 |
|
| 413 |
|
| |
| 414 |
|
| /* Want list of expunged keys/values? */ |
| 415 |
9065 |
▶ | if (wb) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (wb) { |
7190 |
1875 |
9065 |
|
| 416 |
|
| |
| 417 |
48596 |
▶ | for (item = 0; item < num_expunge; item++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (item = 0; item < num_expunge; item++) { |
41406 |
7190 |
48596 |
|
| 418 |
41406 |
| MU64 modseq = 0; |
| 419 |
41406 |
| mmc_get_details(cache, to_expunge[item], |
| 420 |
|
| &key_ptr, &key_len, &val_ptr, &val_len, |
| 421 |
|
| &last_access, &expire_on, &flags, &modseq); |
| 422 |
|
| |
| 423 |
|
| /* Tombstones have nothing to write back */ |
| 424 |
41406 |
▶ | if (flags & FC_TOMBSTONE) |
Branch: 1 branch
| Branch | True | False | Total |
| if (flags & FC_TOMBSTONE) |
0 |
41406 |
41406 |
|
| 425 |
0 |
| continue; |
| 426 |
|
| |
| 427 |
|
| { |
| 428 |
41406 |
| HV * ih = (HV *)sv_2mortal((SV *)newHV()); |
| 429 |
|
| |
| 430 |
41406 |
| SV * key = newSVpvn((const char *)key_ptr, key_len); |
| 431 |
|
| SV * val; |
| 432 |
|
| |
| 433 |
41406 |
▶ | if (flags & FC_UTF8KEY) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (flags & FC_UTF8KEY) { |
0 |
41406 |
41406 |
|
| 434 |
0 |
| SvUTF8_on(key); |
| 435 |
0 |
| flags ^= FC_UTF8KEY; |
| 436 |
|
| } |
| 437 |
|
| |
| 438 |
41406 |
▶ | if (flags & FC_UNDEF) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (flags & FC_UNDEF) { |
3752 |
37654 |
41406 |
|
| 439 |
3752 |
| val = newSV(0); |
| 440 |
3752 |
| flags ^= FC_UNDEF; |
| 441 |
|
| } else { |
| 442 |
37654 |
| val = newSVpvn((const char *)val_ptr, val_len); |
| 443 |
37654 |
▶ | if (flags & FC_UTF8VAL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (flags & FC_UTF8VAL) { |
3783 |
33871 |
37654 |
|
| 444 |
3783 |
| SvUTF8_on(val); |
| 445 |
3783 |
| flags ^= FC_UTF8VAL; |
| 446 |
|
| } |
| 447 |
|
| } |
| 448 |
|
| |
| 449 |
|
| /* Store in hash ref */ |
| 450 |
41406 |
| hv_store(ih, "key", 3, key, 0); |
| 451 |
41406 |
| hv_store(ih, "value", 5, val, 0); |
| 452 |
41406 |
| hv_store(ih, "last_access", 11, newSViv((IV)last_access), 0); |
| 453 |
41406 |
| hv_store(ih, "expire_on", 9, newSViv((IV)expire_on), 0); |
| 454 |
41406 |
▶ | if (flags & FC_HASMODSEQ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (flags & FC_HASMODSEQ) { |
0 |
41406 |
41406 |
|
| 455 |
0 |
| hv_store(ih, "modseq", 6, newSVuv((UV)modseq), 0); |
| 456 |
0 |
| flags ^= FC_HASMODSEQ; |
| 457 |
|
| } |
| 458 |
41406 |
| hv_store(ih, "flags", 5, newSViv((IV)flags), 0); |
| 459 |
|
| |
| 460 |
|
| /* Create reference to hash */ |
| 461 |
41406 |
▶ | XPUSHs(sv_2mortal(newRV((SV *)ih))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newRV((SV *)ih))); |
0 |
41406 |
41406 |
|
| 462 |
|
| } |
| 463 |
|
| } |
| 464 |
|
| } |
| 465 |
|
| |
| 466 |
9065 |
▶ | if (!mmc_do_expunge(cache, num_expunge, new_num_slots, to_expunge)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!mmc_do_expunge(cache, num_expunge, new_num_slots, to_expunge)) { |
0 |
9065 |
9065 |
|
| 467 |
0 |
| croak("%s", mmc_error(cache)); |
| 468 |
|
| XSRETURN_UNDEF; |
| 469 |
|
| } |
| 470 |
|
| } |
| 471 |
|
| |
| 472 |
|
| |
| 473 |
|
| |
| 474 |
|
| |
| 475 |
|
| void |
| 476 |
|
| fc_get_keys(obj, mode) |
| 477 |
|
| SV * obj; |
| 478 |
|
| int mode; |
| 479 |
|
| INIT: |
| 480 |
|
| mmap_cache_it * it; |
| 481 |
|
| MU32 * entry_ptr; |
| 482 |
|
| void * key_ptr, * val_ptr; |
| 483 |
|
| int key_len, val_len; |
| 484 |
|
| MU32 last_access, expire_on, flags; |
| 485 |
|
| int repaired_before; |
| 486 |
|
| |
| 487 |
623 |
▶ | FC_ENTRY |
Branch: 3 branches
| Branch | True | False | Total |
| FC_ENTRY |
0 |
623 |
623 |
| FC_ENTRY |
0 |
623 |
623 |
| FC_ENTRY |
0 |
623 |
623 |
|
| 488 |
|
| |
| 489 |
|
| PPCODE: |
| 490 |
|
| |
| 491 |
623 |
| repaired_before = mmc_get_param(cache, "repaired_pages"); |
| 492 |
623 |
| it = mmc_iterate_new(cache); |
| 493 |
|
| |
| 494 |
|
| /* Iterate over all items */ |
| 495 |
7080022 |
▶ | while ((entry_ptr = mmc_iterate_next(it))) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ((entry_ptr = mmc_iterate_next(it))) { |
7079399 |
623 |
7080022 |
|
| 496 |
|
| SV * key; |
| 497 |
7079399 |
| MU64 modseq = 0; |
| 498 |
7079399 |
| mmc_get_details(cache, entry_ptr, |
| 499 |
|
| &key_ptr, &key_len, &val_ptr, &val_len, |
| 500 |
|
| &last_access, &expire_on, &flags, &modseq); |
| 501 |
|
| |
| 502 |
|
| /* Tombstones are misses, so hide them */ |
| 503 |
7079399 |
▶ | if (flags & FC_TOMBSTONE) |
Branch: 1 branch
| Branch | True | False | Total |
| if (flags & FC_TOMBSTONE) |
3 |
7079396 |
7079399 |
|
| 504 |
3 |
| continue; |
| 505 |
|
| |
| 506 |
|
| /* Create key SV, and set UTF8'ness if needed */ |
| 507 |
7079396 |
| key = newSVpvn((const char *)key_ptr, key_len); |
| 508 |
7079396 |
▶ | if (flags & FC_UTF8KEY) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (flags & FC_UTF8KEY) { |
4 |
7079392 |
7079396 |
|
| 509 |
4 |
| SvUTF8_on(key); |
| 510 |
4 |
| flags ^= FC_UTF8KEY; |
| 511 |
|
| } |
| 512 |
|
| |
| 513 |
|
| /* Mode 0 is just list of keys */ |
| 514 |
7079396 |
▶ | if (mode == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (mode == 0) { |
2359348 |
4720048 |
7079396 |
|
| 515 |
2359348 |
▶ | XPUSHs(sv_2mortal(key)); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(key)); |
6 |
2359342 |
2359348 |
|
| 516 |
|
| |
| 517 |
|
| /* Mode 1/2 is list of hash-refs */ |
| 518 |
4720048 |
▶ | } else if (mode == 1 || mode == 2) { |
Branch: 2 branches
| Branch | True | False | Total |
| } else if (mode == 1 || mode == 2) { |
2360710 |
2359338 |
4720048 |
| } else if (mode == 1 || mode == 2) { |
2360710 |
0 |
2360710 |
|
| 519 |
4720048 |
| HV * ih = (HV *)sv_2mortal((SV *)newHV()); |
| 520 |
|
| |
| 521 |
4720048 |
▶ | if (flags & FC_HASMODSEQ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (flags & FC_HASMODSEQ) { |
1 |
4720047 |
4720048 |
|
| 522 |
1 |
| hv_store(ih, "modseq", 6, newSVuv((UV)modseq), 0); |
| 523 |
1 |
| flags ^= FC_HASMODSEQ; |
| 524 |
|
| } |
| 525 |
|
| |
| 526 |
|
| /* These things by default */ |
| 527 |
4720048 |
| hv_store(ih, "key", 3, key, 0); |
| 528 |
4720048 |
| hv_store(ih, "last_access", 11, newSViv((IV)last_access), 0); |
| 529 |
4720048 |
| hv_store(ih, "expire_on", 9, newSViv((IV)expire_on), 0); |
| 530 |
4720048 |
| hv_store(ih, "flags", 5, newSViv((IV)flags), 0); |
| 531 |
|
| |
| 532 |
|
| /* Add value to hash-ref if mode 2 */ |
| 533 |
4720048 |
▶ | if (mode == 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (mode == 2) { |
2360710 |
2359338 |
4720048 |
|
| 534 |
|
| SV * val; |
| 535 |
2360710 |
▶ | if (flags & FC_UNDEF) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (flags & FC_UNDEF) { |
479988 |
1880722 |
2360710 |
|
| 536 |
479988 |
| val = newSV(0); |
| 537 |
479988 |
| flags ^= FC_UNDEF; |
| 538 |
|
| } else { |
| 539 |
1880722 |
| val = newSVpvn((const char *)val_ptr, val_len); |
| 540 |
1880722 |
▶ | if (flags & FC_UTF8VAL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (flags & FC_UTF8VAL) { |
472351 |
1408371 |
1880722 |
|
| 541 |
472351 |
| SvUTF8_on(val); |
| 542 |
472351 |
| flags ^= FC_UTF8VAL; |
| 543 |
|
| } |
| 544 |
|
| } |
| 545 |
2360710 |
| hv_store(ih, "value", 5, val, 0); |
| 546 |
|
| } |
| 547 |
|
| |
| 548 |
|
| /* Create reference to hash */ |
| 549 |
4720048 |
▶ | XPUSHs(sv_2mortal(newRV((SV *)ih))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newRV((SV *)ih))); |
0 |
4720048 |
4720048 |
|
| 550 |
|
| } |
| 551 |
|
| } |
| 552 |
|
| |
| 553 |
623 |
| mmc_iterate_close(it); |
| 554 |
|
| |
| 555 |
|
| /* Pages are locked and unlocked inside the iterator, so a repair |
| 556 |
|
| * there isn't seen by fc_lock/fc_unlock; report it here */ |
| 557 |
623 |
▶ | if (mmc_get_param(cache, "repaired_pages") > repaired_before) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (mmc_get_param(cache, "repaired_pages") > repaired_before) { |
0 |
623 |
623 |
|
| 558 |
0 |
| warn("Cache::FastMmap: %s", mmc_error(cache)); |
| 559 |
|
| } |
| 560 |
|
| |
| 561 |
|
| |
| 562 |
|
| |
| 563 |
|
| |
| 564 |
|
| |
| 565 |
|
| SV * |
| 566 |
|
| fc_get(obj, key) |
| 567 |
|
| SV * obj; |
| 568 |
|
| SV * key; |
| 569 |
|
| INIT: |
| 570 |
|
| int key_len, val_len, found; |
| 571 |
|
| void * key_ptr, * val_ptr; |
| 572 |
|
| MU32 hash_page, hash_slot, expire_on, flags; |
| 573 |
0 |
| MU64 modseq = 0; |
| 574 |
|
| STRLEN pl_key_len; |
| 575 |
|
| SV * val; |
| 576 |
|
| |
| 577 |
0 |
▶ | FC_ENTRY |
Branch: 3 branches
| Branch | True | False | Total |
| FC_ENTRY |
0 |
0 |
0 |
| FC_ENTRY |
0 |
0 |
0 |
| FC_ENTRY |
0 |
0 |
0 |
|
| 578 |
|
| |
| 579 |
|
| CODE: |
| 580 |
|
| |
| 581 |
|
| /* Get key length, data pointer */ |
| 582 |
0 |
| key_ptr = (void *)SvPV(key, pl_key_len); |
| 583 |
0 |
| key_len = (int)pl_key_len; |
| 584 |
|
| |
| 585 |
|
| /* Hash key to get page and slot */ |
| 586 |
0 |
| mmc_hash(cache, key_ptr, key_len, &hash_page, &hash_slot); |
| 587 |
|
| |
| 588 |
|
| /* Get and lock the page */ |
| 589 |
0 |
| mmc_lock(cache, hash_page); |
| 590 |
|
| |
| 591 |
|
| /* Get value data pointer */ |
| 592 |
0 |
| found = mmc_read(cache, hash_slot, key_ptr, key_len, &val_ptr, &val_len, &expire_on, &flags, &modseq); |
| 593 |
|
| |
| 594 |
|
| /* If not found, use undef */ |
| 595 |
0 |
▶ | if (found == -1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (found == -1) { |
0 |
0 |
0 |
|
| 596 |
0 |
| val = &PL_sv_undef; |
| 597 |
|
| } else { |
| 598 |
|
| |
| 599 |
|
| /* Create PERL SV */ |
| 600 |
0 |
| val = newSVpvn((const char *)val_ptr, val_len); |
| 601 |
|
| } |
| 602 |
|
| |
| 603 |
0 |
| mmc_unlock(cache); |
| 604 |
0 |
| RETVAL = val; |
| 605 |
|
| OUTPUT: |
| 606 |
|
| RETVAL |
| 607 |
|
| |
| 608 |
|
| |
| 609 |
|
| void |
| 610 |
|
| fc_set(obj, key, val) |
| 611 |
|
| SV * obj; |
| 612 |
|
| SV * key; |
| 613 |
|
| SV * val; |
| 614 |
|
| INIT: |
| 615 |
|
| int key_len, val_len; |
| 616 |
|
| void * key_ptr, * val_ptr; |
| 617 |
0 |
| MU32 hash_page, hash_slot, flags = 0; |
| 618 |
|
| STRLEN pl_key_len, pl_val_len; |
| 619 |
|
| |
| 620 |
0 |
▶ | FC_ENTRY |
Branch: 3 branches
| Branch | True | False | Total |
| FC_ENTRY |
0 |
0 |
0 |
| FC_ENTRY |
0 |
0 |
0 |
| FC_ENTRY |
0 |
0 |
0 |
|
| 621 |
|
| |
| 622 |
|
| CODE: |
| 623 |
|
| |
| 624 |
|
| /* Get key length, data pointer */ |
| 625 |
0 |
| key_ptr = (void *)SvPV(key, pl_key_len); |
| 626 |
0 |
▶ | key_len = (int)pl_key_len; |
Branch: 1 branch
| Branch | True | False | Total |
| key_len = (int)pl_key_len; |
0 |
0 |
0 |
|
| 627 |
|
| |
| 628 |
|
| /* Get key length, data pointer */ |
| 629 |
0 |
| val_ptr = (void *)SvPV(val, pl_val_len); |
| 630 |
0 |
| val_len = (int)pl_val_len; |
| 631 |
|
| |
| 632 |
|
| /* Hash key to get page and slot */ |
| 633 |
0 |
| mmc_hash(cache, key_ptr, key_len, &hash_page, &hash_slot); |
| 634 |
|
| |
| 635 |
|
| /* Get and lock the page */ |
| 636 |
0 |
| mmc_lock(cache, hash_page); |
| 637 |
|
| |
| 638 |
|
| /* Get value data pointer */ |
| 639 |
0 |
| mmc_write(cache, hash_slot, key_ptr, key_len, val_ptr, val_len, -1, flags, 0); |
| 640 |
|
| |
| 641 |
0 |
| mmc_unlock(cache); |
| 642 |
|
| |
| 643 |
|
| |
| 644 |
|
| NO_OUTPUT void |
| 645 |
|
| fc_dump_page(obj); |
| 646 |
|
| SV * obj; |
| 647 |
|
| INIT: |
| 648 |
0 |
▶ | FC_ENTRY |
Branch: 3 branches
| Branch | True | False | Total |
| FC_ENTRY |
0 |
0 |
0 |
| FC_ENTRY |
0 |
0 |
0 |
| FC_ENTRY |
0 |
0 |
0 |
|
| 649 |
|
| |
| 650 |
|
| CODE: |
| 651 |
0 |
| _mmc_dump_page(cache); |
| 652 |
|
| |
| 653 |
|
| |
| 654 |
|
| NO_OUTPUT void |
| 655 |
|
| fc_set_time_override(set_time); |
| 656 |
|
| UV set_time; |
| 657 |
|
| |
| 658 |
|
| CODE: |
| 659 |
14 |
| mmc_set_time_override((MU32)set_time); |
| 660 |
|
| |
| 661 |
|
| |