FastMmap.xs

filter: Statementstmt 82.2% 162 / 197 Branchbran 57.7% 127 / 220 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 69.3% 289 / 417 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« unix.c ↑ Summary mmap_cache.c »
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 8071 cache = mmc_new();
40  
41 /* Create integer which is pointer to cache object */
42 8071 obj_pnt = newSViv(PTR2IV(cache));
43  
44 /* Create reference to integer value. This will be the object */
45 8071 obj = newRV_noinc((SV *)obj_pnt);
46  
47 8071 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 72632 ▶ FC_ENTRY
Branch: 3 branches
BranchTrueFalseTotal
FC_ENTRY 0 72632 72632
FC_ENTRY 0 72632 72632
FC_ENTRY 0 72632 72632
58  
59 CODE:
60 72632 RETVAL = mmc_set_param(cache, param, val);
61 POSTCALL:
62 72632 ▶ if (RETVAL != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (RETVAL != 0) { 0 72632 72632
63 0 croak("%s", mmc_error(cache));
64 }
65  
66 NO_OUTPUT int
67 fc_init(obj)
68 SV * obj;
69 INIT:
70 8070 ▶ FC_ENTRY
Branch: 3 branches
BranchTrueFalseTotal
FC_ENTRY 0 8070 8070
FC_ENTRY 0 8070 8070
FC_ENTRY 0 8070 8070
71  
72 CODE:
73 8070 RETVAL = mmc_init(cache);
74 POSTCALL:
75 8070 ▶ if (RETVAL != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (RETVAL != 0) { 0 8070 8070
76 0 croak("%s", mmc_error(cache));
77 }
78 8070 ▶ if (mmc_get_param(cache, "repaired_pages") > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (mmc_get_param(cache, "repaired_pages") > 0) { 1 8069 8070
79 1 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 6 ▶ FC_ENTRY
Branch: 3 branches
BranchTrueFalseTotal
FC_ENTRY 0 6 6
FC_ENTRY 0 6 6
FC_ENTRY 0 6 6
90  
91 CODE:
92 6 RETVAL = mmc_get_param(cache, param);
93 OUTPUT:
94 RETVAL
95  
96  
97 void
98 fc_close(obj)
99 SV * obj
100 INIT:
101 8070 ▶ FC_ENTRY
Branch: 3 branches
BranchTrueFalseTotal
FC_ENTRY 0 8070 8070
FC_ENTRY 0 8070 8070
FC_ENTRY 0 8070 8070
102  
103 CODE:
104 8070 mmc_close(cache);
105 8070 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 289025 ▶ FC_ENTRY
Branch: 3 branches
BranchTrueFalseTotal
FC_ENTRY 0 289025 289025
FC_ENTRY 0 289025 289025
FC_ENTRY 0 289025 289025
119  
120 PPCODE:
121  
122 /* Get key length, data pointer */
123 289025 key_ptr = (void *)SvPV(key, pl_key_len);
124 289025 key_len = (int)pl_key_len;
125  
126 /* Hash key to get page and slot */
127 289025 mmc_hash(cache, key_ptr, key_len, &hash_page, &hash_slot);
128  
129 289025 ▶ XPUSHs(sv_2mortal(newSViv((IV)hash_page)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv((IV)hash_page))); 0 289025 289025
130 289025 ▶ XPUSHs(sv_2mortal(newSViv((IV)hash_slot)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv((IV)hash_slot))); 0 289025 289025
131  
132  
133 NO_OUTPUT int
134 fc_lock(obj, page);
135 SV * obj;
136 UV page;
137 INIT:
138 269799 ▶ FC_ENTRY
Branch: 3 branches
BranchTrueFalseTotal
FC_ENTRY 0 269799 269799
FC_ENTRY 0 269799 269799
FC_ENTRY 0 269799 269799
139  
140 CODE:
141 269799 RETVAL = mmc_lock(cache, (MU32)page);
142 POSTCALL:
143 269799 ▶ if (RETVAL != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (RETVAL != 0) { 1 269798 269799
144 1 croak("%s", mmc_error(cache));
145 }
146 269798 ▶ if (mmc_page_repaired(cache)) {
Branch: 1 branch
BranchTrueFalseTotal
if (mmc_page_repaired(cache)) { 1 269797 269798
147 1 warn("Cache::FastMmap: %s", mmc_error(cache));
148 }
149  
150  
151 NO_OUTPUT int
152 fc_unlock(obj);
153 SV * obj;
154 INIT:
155 269798 ▶ FC_ENTRY
Branch: 3 branches
BranchTrueFalseTotal
FC_ENTRY 0 269798 269798
FC_ENTRY 0 269798 269798
FC_ENTRY 0 269798 269798
156  
157 CODE:
158 269798 RETVAL = mmc_unlock(cache);
159 POSTCALL:
160 269798 ▶ if (RETVAL != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (RETVAL != 0) { 0 269798 269798
161 0 croak("%s", mmc_error(cache));
162 }
163 269798 ▶ if (mmc_page_repaired(cache)) {
Branch: 1 branch
BranchTrueFalseTotal
if (mmc_page_repaired(cache)) { 2 269796 269798
164 2 warn("Cache::FastMmap: %s", mmc_error(cache));
165 }
166  
167 int
168 fc_is_locked(obj)
169 SV * obj;
170 INIT:
171 103787 ▶ FC_ENTRY
Branch: 3 branches
BranchTrueFalseTotal
FC_ENTRY 0 103787 103787
FC_ENTRY 0 103787 103787
FC_ENTRY 0 103787 103787
172  
173 CODE:
174 /* Write value to cache */
175 103787 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 186067 MU32 expire_on = 0;
190 186067 MU32 flags = 0;
191 186067 MU64 modseq = 0;
192 STRLEN pl_key_len;
193 SV * val;
194 SV * modseq_sv;
195  
196 186067 ▶ FC_ENTRY
Branch: 3 branches
BranchTrueFalseTotal
FC_ENTRY 0 186067 186067
FC_ENTRY 0 186067 186067
FC_ENTRY 0 186067 186067
197  
198 PPCODE:
199  
200 /* Get key length, data pointer */
201 186067 key_ptr = (void *)SvPV(key, pl_key_len);
202 186067 key_len = (int)pl_key_len;
203  
204 /* Get value data pointer */
205 186067 found = mmc_read(cache, (MU32)hash_slot, key_ptr, key_len, &val_ptr, &val_len, &expire_on, &flags, &modseq);
206  
207 186067 modseq_sv = &PL_sv_undef;
208  
209 /* If not found, use undef */
210 186067 ▶ if (found == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if (found == -1) { 37057 149010 186067
211 37057 val = &PL_sv_undef;
212 } else {
213  
214 /* Cached an undef value? */
215 149010 ▶ if (flags & FC_UNDEF) {
Branch: 1 branch
BranchTrueFalseTotal
if (flags & FC_UNDEF) { 2315 146695 149010
216 2315 val = &PL_sv_undef;
217  
218 } else {
219  
220 /* Create PERL SV */
221 146695 val = sv_2mortal(newSVpvn((const char *)val_ptr, val_len));
222  
223 /* Make UTF8 if stored from UTF8 */
224 146695 ▶ if (flags & FC_UTF8VAL) {
Branch: 1 branch
BranchTrueFalseTotal
if (flags & FC_UTF8VAL) { 2285 144410 146695
225 2285 SvUTF8_on(val);
226 }
227  
228 }
229  
230 149010 ▶ if (flags & FC_HASMODSEQ) {
Branch: 1 branch
BranchTrueFalseTotal
if (flags & FC_HASMODSEQ) { 10 149000 149010
231 10 modseq_sv = sv_2mortal(newSVuv((UV)modseq));
232 }
233  
234 149010 flags = flags & ~(FC_UTF8KEY | FC_UTF8VAL | FC_UNDEF | FC_HASMODSEQ | FC_TOMBSTONE);
235 }
236  
237 186067 ▶ XPUSHs(val);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(val); 0 186067 186067
238 186067 ▶ XPUSHs(sv_2mortal(newSViv((IV)flags)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv((IV)flags))); 0 186067 186067
239 186067 ▶ XPUSHs(sv_2mortal(newSViv((IV)!found)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv((IV)!found))); 0 186067 186067
240 186067 ▶ XPUSHs(sv_2mortal(newSViv((IV)expire_on)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv((IV)expire_on))); 0 186067 186067
241 186067 ▶ XPUSHs(modseq_sv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(modseq_sv); 0 186067 186067
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 103911 MU64 modseq = 0;
257 STRLEN pl_key_len, pl_val_len;
258  
259 103911 ▶ FC_ENTRY
Branch: 3 branches
BranchTrueFalseTotal
FC_ENTRY 0 103911 103911
FC_ENTRY 0 103911 103911
FC_ENTRY 0 103911 103911
260  
261 CODE:
262  
263 /* Get key length, data pointer */
264 103911 key_ptr = (void *)SvPV(key, pl_key_len);
265 103911 key_len = (int)pl_key_len;
266  
267 /* Storing with a modseq? (see TOMBSTONES AND MODSEQS in the pod) */
268 103911 ▶ if (SvOK(modseq_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(modseq_sv)) { 19 103892 103911
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 103911 ▶ if (!SvOK(val)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(val)) { 8023 95888 103911
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 95888 val_ptr = (void *)SvPV(val, pl_val_len);
286 95888 val_len = (int)pl_val_len;
287  
288 /* Set UTF8-ness flag of stored value */
289 95888 ▶ if (SvUTF8(val)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvUTF8(val)) { 8024 87864 95888
290 8024 in_flags |= FC_UTF8VAL;
291 }
292 95888 ▶ if (SvUTF8(key)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvUTF8(key)) { 4 95884 95888
293 4 in_flags |= FC_UTF8KEY;
294 }
295 }
296  
297 /* Write value to cache (1 stored, 0 no space, -1 refused) */
298 103911 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
BranchTrueFalseTotal
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
BranchTrueFalseTotal
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
BranchTrueFalseTotal
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
BranchTrueFalseTotal
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
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv((IV)did_delete))); 0 11396 11396
364 11396 ▶ XPUSHs(sv_2mortal(newSViv((IV)out_flags)));
Branch: 1 branch
BranchTrueFalseTotal
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
BranchTrueFalseTotal
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
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv((IV)nreads))); 0 267 267
379 267 ▶ XPUSHs(sv_2mortal(newSViv((IV)nreadhits)));
Branch: 1 branch
BranchTrueFalseTotal
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
BranchTrueFalseTotal
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 104656 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 104656 ▶ FC_ENTRY
Branch: 3 branches
BranchTrueFalseTotal
FC_ENTRY 0 104656 104656
FC_ENTRY 0 104656 104656
FC_ENTRY 0 104656 104656
408  
409 PPCODE:
410  
411 104656 num_expunge = mmc_calc_expunge(cache, mode, len, &new_num_slots, &to_expunge);
412 104656 ▶ if (to_expunge) {
Branch: 1 branch
BranchTrueFalseTotal
if (to_expunge) { 9050 95606 104656
413  
414 /* Want list of expunged keys/values? */
415 9050 ▶ if (wb) {
Branch: 1 branch
BranchTrueFalseTotal
if (wb) { 7171 1879 9050
416  
417 47533 ▶ for (item = 0; item < num_expunge; item++) {
Branch: 1 branch
BranchTrueFalseTotal
for (item = 0; item < num_expunge; item++) { 40362 7171 47533
418 40362 MU64 modseq = 0;
419 40362 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 40362 ▶ if (flags & FC_TOMBSTONE)
Branch: 1 branch
BranchTrueFalseTotal
if (flags & FC_TOMBSTONE) 0 40362 40362
425 0 continue;
426  
427 {
428 40362 HV * ih = (HV *)sv_2mortal((SV *)newHV());
429  
430 40362 SV * key = newSVpvn((const char *)key_ptr, key_len);
431 SV * val;
432  
433 40362 ▶ if (flags & FC_UTF8KEY) {
Branch: 1 branch
BranchTrueFalseTotal
if (flags & FC_UTF8KEY) { 0 40362 40362
434 0 SvUTF8_on(key);
435 0 flags ^= FC_UTF8KEY;
436 }
437  
438 40362 ▶ if (flags & FC_UNDEF) {
Branch: 1 branch
BranchTrueFalseTotal
if (flags & FC_UNDEF) { 3334 37028 40362
439 3334 val = newSV(0);
440 3334 flags ^= FC_UNDEF;
441 } else {
442 37028 val = newSVpvn((const char *)val_ptr, val_len);
443 37028 ▶ if (flags & FC_UTF8VAL) {
Branch: 1 branch
BranchTrueFalseTotal
if (flags & FC_UTF8VAL) { 3393 33635 37028
444 3393 SvUTF8_on(val);
445 3393 flags ^= FC_UTF8VAL;
446 }
447 }
448  
449 /* Store in hash ref */
450 40362 hv_store(ih, "key", 3, key, 0);
451 40362 hv_store(ih, "value", 5, val, 0);
452 40362 hv_store(ih, "last_access", 11, newSViv((IV)last_access), 0);
453 40362 hv_store(ih, "expire_on", 9, newSViv((IV)expire_on), 0);
454 40362 ▶ if (flags & FC_HASMODSEQ) {
Branch: 1 branch
BranchTrueFalseTotal
if (flags & FC_HASMODSEQ) { 0 40362 40362
455 0 hv_store(ih, "modseq", 6, newSVuv((UV)modseq), 0);
456 0 flags ^= FC_HASMODSEQ;
457 }
458 40362 hv_store(ih, "flags", 5, newSViv((IV)flags), 0);
459  
460 /* Create reference to hash */
461 40362 ▶ XPUSHs(sv_2mortal(newRV((SV *)ih)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newRV((SV *)ih))); 0 40362 40362
462 }
463 }
464 }
465  
466 9050 ▶ if (!mmc_do_expunge(cache, num_expunge, new_num_slots, to_expunge)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!mmc_do_expunge(cache, num_expunge, new_num_slots, to_expunge)) { 0 9050 9050
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 624 ▶ FC_ENTRY
Branch: 3 branches
BranchTrueFalseTotal
FC_ENTRY 0 624 624
FC_ENTRY 0 624 624
FC_ENTRY 0 624 624
488  
489 PPCODE:
490  
491 624 repaired_before = mmc_get_param(cache, "repaired_pages");
492 624 it = mmc_iterate_new(cache);
493  
494 /* Iterate over all items */
495 7077137 ▶ while ((entry_ptr = mmc_iterate_next(it))) {
Branch: 1 branch
BranchTrueFalseTotal
while ((entry_ptr = mmc_iterate_next(it))) { 7076513 624 7077137
496 SV * key;
497 7076513 MU64 modseq = 0;
498 7076513 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 7076513 ▶ if (flags & FC_TOMBSTONE)
Branch: 1 branch
BranchTrueFalseTotal
if (flags & FC_TOMBSTONE) 3 7076510 7076513
504 3 continue;
505  
506 /* Create key SV, and set UTF8'ness if needed */
507 7076510 key = newSVpvn((const char *)key_ptr, key_len);
508 7076510 ▶ if (flags & FC_UTF8KEY) {
Branch: 1 branch
BranchTrueFalseTotal
if (flags & FC_UTF8KEY) { 4 7076506 7076510
509 4 SvUTF8_on(key);
510 4 flags ^= FC_UTF8KEY;
511 }
512  
513 /* Mode 0 is just list of keys */
514 7076510 ▶ if (mode == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (mode == 0) { 2358461 4718049 7076510
515 2358461 ▶ XPUSHs(sv_2mortal(key));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(key)); 6 2358455 2358461
516  
517 /* Mode 1/2 is list of hash-refs */
518 4718049 ▶ } else if (mode == 1 || mode == 2) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (mode == 1 || mode == 2) { 2359716 2358333 4718049
} else if (mode == 1 || mode == 2) { 2359716 0 2359716
519 4718049 HV * ih = (HV *)sv_2mortal((SV *)newHV());
520  
521 4718049 ▶ if (flags & FC_HASMODSEQ) {
Branch: 1 branch
BranchTrueFalseTotal
if (flags & FC_HASMODSEQ) { 1 4718048 4718049
522 1 hv_store(ih, "modseq", 6, newSVuv((UV)modseq), 0);
523 1 flags ^= FC_HASMODSEQ;
524 }
525  
526 /* These things by default */
527 4718049 hv_store(ih, "key", 3, key, 0);
528 4718049 hv_store(ih, "last_access", 11, newSViv((IV)last_access), 0);
529 4718049 hv_store(ih, "expire_on", 9, newSViv((IV)expire_on), 0);
530 4718049 hv_store(ih, "flags", 5, newSViv((IV)flags), 0);
531  
532 /* Add value to hash-ref if mode 2 */
533 4718049 ▶ if (mode == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (mode == 2) { 2359716 2358333 4718049
534 SV * val;
535 2359716 ▶ if (flags & FC_UNDEF) {
Branch: 1 branch
BranchTrueFalseTotal
if (flags & FC_UNDEF) { 477174 1882542 2359716
536 477174 val = newSV(0);
537 477174 flags ^= FC_UNDEF;
538 } else {
539 1882542 val = newSVpvn((const char *)val_ptr, val_len);
540 1882542 ▶ if (flags & FC_UTF8VAL) {
Branch: 1 branch
BranchTrueFalseTotal
if (flags & FC_UTF8VAL) { 471547 1410995 1882542
541 471547 SvUTF8_on(val);
542 471547 flags ^= FC_UTF8VAL;
543 }
544 }
545 2359716 hv_store(ih, "value", 5, val, 0);
546 }
547  
548 /* Create reference to hash */
549 4718049 ▶ XPUSHs(sv_2mortal(newRV((SV *)ih)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newRV((SV *)ih))); 0 4718049 4718049
550 }
551 }
552  
553 624 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 624 ▶ if (mmc_get_param(cache, "repaired_pages") > repaired_before) {
Branch: 1 branch
BranchTrueFalseTotal
if (mmc_get_param(cache, "repaired_pages") > repaired_before) { 1 623 624
558 1 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
BranchTrueFalseTotal
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
BranchTrueFalseTotal
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
BranchTrueFalseTotal
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
BranchTrueFalseTotal
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
BranchTrueFalseTotal
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  
« unix.c ↑ Summary mmap_cache.c »