FastMmap.xs

filter: Statementstmt 81.8% 167 / 204 Branchbran 57.5% 137 / 238 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 68.7% 304 / 442 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 289026 ▶ FC_ENTRY
Branch: 3 branches
BranchTrueFalseTotal
FC_ENTRY 0 289026 289026
FC_ENTRY 0 289026 289026
FC_ENTRY 0 289026 289026
119  
120 PPCODE:
121  
122 /* Get key length, data pointer */
123 289026 key_ptr = (void *)SvPV(key, pl_key_len);
124 289026 key_len = (int)pl_key_len;
125  
126 /* Hash key to get page and slot */
127 289026 mmc_hash(cache, key_ptr, key_len, &hash_page, &hash_slot);
128  
129 289026 ▶ XPUSHs(sv_2mortal(newSViv((IV)hash_page)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv((IV)hash_page))); 0 289026 289026
130 289026 ▶ XPUSHs(sv_2mortal(newSViv((IV)hash_slot)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv((IV)hash_slot))); 0 289026 289026
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 103744 ▶ FC_ENTRY
Branch: 3 branches
BranchTrueFalseTotal
FC_ENTRY 0 103744 103744
FC_ENTRY 0 103744 103744
FC_ENTRY 0 103744 103744
172  
173 CODE:
174 /* Write value to cache */
175 103744 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 186110 MU32 expire_on = 0;
190 186110 MU32 flags = 0;
191 186110 MU64 modseq = 0;
192 STRLEN pl_key_len;
193 SV * val;
194 SV * modseq_sv;
195  
196 186110 ▶ FC_ENTRY
Branch: 3 branches
BranchTrueFalseTotal
FC_ENTRY 0 186110 186110
FC_ENTRY 0 186110 186110
FC_ENTRY 0 186110 186110
197  
198 PPCODE:
199  
200 /* Get key length, data pointer */
201 186110 key_ptr = (void *)SvPV(key, pl_key_len);
202 186110 key_len = (int)pl_key_len;
203  
204 /* Get value data pointer */
205 186110 found = mmc_read(cache, (MU32)hash_slot, key_ptr, key_len, &val_ptr, &val_len, &expire_on, &flags, &modseq);
206  
207 186110 modseq_sv = &PL_sv_undef;
208  
209 /* If not found, use undef */
210 186110 ▶ if (found == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if (found == -1) { 36300 149810 186110
211 36300 val = &PL_sv_undef;
212 } else {
213  
214 /* Cached an undef value? */
215 149810 ▶ if (flags & FC_UNDEF) {
Branch: 1 branch
BranchTrueFalseTotal
if (flags & FC_UNDEF) { 2359 147451 149810
216 2359 val = &PL_sv_undef;
217  
218 } else {
219  
220 /* Create PERL SV */
221 147451 val = sv_2mortal(newSVpvn((const char *)val_ptr, val_len));
222  
223 /* Make UTF8 if stored from UTF8 */
224 147451 ▶ if (flags & FC_UTF8VAL) {
Branch: 1 branch
BranchTrueFalseTotal
if (flags & FC_UTF8VAL) { 2318 145133 147451
225 2318 SvUTF8_on(val);
226 }
227  
228 }
229  
230 149810 ▶ if (flags & FC_HASMODSEQ) {
Branch: 1 branch
BranchTrueFalseTotal
if (flags & FC_HASMODSEQ) { 10 149800 149810
231 10 modseq_sv = sv_2mortal(newSVuv((UV)modseq));
232 }
233  
234 149810 flags = flags & ~(FC_UTF8KEY | FC_UTF8VAL | FC_UNDEF | FC_HASMODSEQ | FC_TOMBSTONE);
235 }
236  
237 186110 ▶ XPUSHs(val);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(val); 0 186110 186110
238 186110 ▶ XPUSHs(sv_2mortal(newSViv((IV)flags)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv((IV)flags))); 0 186110 186110
239 186110 ▶ XPUSHs(sv_2mortal(newSViv((IV)!found)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv((IV)!found))); 0 186110 186110
240 186110 ▶ XPUSHs(sv_2mortal(newSViv((IV)expire_on)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv((IV)expire_on))); 0 186110 186110
241 186110 ▶ XPUSHs(modseq_sv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(modseq_sv); 0 186110 186110
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 104064 MU64 modseq = 0;
257 STRLEN pl_key_len, pl_val_len;
258  
259 104064 ▶ FC_ENTRY
Branch: 3 branches
BranchTrueFalseTotal
FC_ENTRY 0 104064 104064
FC_ENTRY 0 104064 104064
FC_ENTRY 0 104064 104064
260  
261 CODE:
262  
263 /* Get key length, data pointer */
264 104064 key_ptr = (void *)SvPV(key, pl_key_len);
265 104064 key_len = (int)pl_key_len;
266  
267 /* Storing with a modseq? (see TOMBSTONES AND MODSEQS in the pod) */
268 104064 ▶ if (SvOK(modseq_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(modseq_sv)) { 19 104045 104064
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 104064 ▶ if (!SvOK(val)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(val)) { 8023 96041 104064
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 96041 val_ptr = (void *)SvPV(val, pl_val_len);
286 96041 val_len = (int)pl_val_len;
287  
288 /* Set UTF8-ness flag of stored value */
289 96041 ▶ if (SvUTF8(val)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvUTF8(val)) { 8024 88017 96041
290 8024 in_flags |= FC_UTF8VAL;
291 }
292 96041 ▶ if (SvUTF8(key)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvUTF8(key)) { 4 96037 96041
293 4 in_flags |= FC_UTF8KEY;
294 }
295 }
296  
297 /* Write value to cache (1 stored, 0 no space, -1 refused) */
298 104064 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 104809 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 104809 ▶ FC_ENTRY
Branch: 3 branches
BranchTrueFalseTotal
FC_ENTRY 0 104809 104809
FC_ENTRY 0 104809 104809
FC_ENTRY 0 104809 104809
408  
409 PPCODE:
410  
411 104809 num_expunge = mmc_calc_expunge(cache, mode, len, &new_num_slots, &to_expunge);
412 104809 ▶ if (to_expunge) {
Branch: 1 branch
BranchTrueFalseTotal
if (to_expunge) { 9091 95718 104809
413  
414 /* Want list of expunged keys/values? */
415 9091 ▶ if (wb) {
Branch: 1 branch
BranchTrueFalseTotal
if (wb) { 7175 1916 9091
416  
417 48076 ▶ for (item = 0; item < num_expunge; item++) {
Branch: 1 branch
BranchTrueFalseTotal
for (item = 0; item < num_expunge; item++) { 40901 7175 48076
418 40901 MU64 modseq = 0;
419 40901 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 40901 ▶ if (flags & FC_TOMBSTONE)
Branch: 1 branch
BranchTrueFalseTotal
if (flags & FC_TOMBSTONE) 0 40901 40901
425 0 continue;
426  
427 {
428 40901 HV * ih = (HV *)sv_2mortal((SV *)newHV());
429  
430 40901 SV * key = newSVpvn((const char *)key_ptr, key_len);
431 SV * val;
432  
433 40901 ▶ if (flags & FC_UTF8KEY) {
Branch: 1 branch
BranchTrueFalseTotal
if (flags & FC_UTF8KEY) { 0 40901 40901
434 0 SvUTF8_on(key);
435 0 flags ^= FC_UTF8KEY;
436 }
437  
438 40901 ▶ if (flags & FC_UNDEF) {
Branch: 1 branch
BranchTrueFalseTotal
if (flags & FC_UNDEF) { 3364 37537 40901
439 3364 val = newSV(0);
440 3364 flags ^= FC_UNDEF;
441 } else {
442 37537 val = newSVpvn((const char *)val_ptr, val_len);
443 37537 ▶ if (flags & FC_UTF8VAL) {
Branch: 1 branch
BranchTrueFalseTotal
if (flags & FC_UTF8VAL) { 3450 34087 37537
444 3450 SvUTF8_on(val);
445 3450 flags ^= FC_UTF8VAL;
446 }
447 }
448  
449 /* Store in hash ref */
450 40901 hv_store(ih, "key", 3, key, 0);
451 40901 hv_store(ih, "value", 5, val, 0);
452 40901 hv_store(ih, "last_access", 11, newSViv((IV)last_access), 0);
453 40901 hv_store(ih, "expire_on", 9, newSViv((IV)expire_on), 0);
454 40901 ▶ if (flags & FC_HASMODSEQ) {
Branch: 1 branch
BranchTrueFalseTotal
if (flags & FC_HASMODSEQ) { 0 40901 40901
455 0 hv_store(ih, "modseq", 6, newSVuv((UV)modseq), 0);
456 0 flags ^= FC_HASMODSEQ;
457 }
458 40901 hv_store(ih, "flags", 5, newSViv((IV)flags), 0);
459  
460 /* Create reference to hash */
461 40901 ▶ XPUSHs(sv_2mortal(newRV((SV *)ih)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newRV((SV *)ih))); 0 40901 40901
462 }
463 }
464 }
465  
466 9091 ▶ 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 9091 9091
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 6873317 ▶ while ((entry_ptr = mmc_iterate_next(it))) {
Branch: 1 branch
BranchTrueFalseTotal
while ((entry_ptr = mmc_iterate_next(it))) { 6872693 624 6873317
496 SV * key;
497 6872693 MU64 modseq = 0;
498 6872693 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 6872693 ▶ if (flags & FC_TOMBSTONE)
Branch: 1 branch
BranchTrueFalseTotal
if (flags & FC_TOMBSTONE) 3 6872690 6872693
504 3 continue;
505  
506 /* Create key SV, and set UTF8'ness if needed */
507 6872690 key = newSVpvn((const char *)key_ptr, key_len);
508 6872690 ▶ if (flags & FC_UTF8KEY) {
Branch: 1 branch
BranchTrueFalseTotal
if (flags & FC_UTF8KEY) { 4 6872686 6872690
509 4 SvUTF8_on(key);
510 4 flags ^= FC_UTF8KEY;
511 }
512  
513 /* Mode 0 is just list of keys */
514 6872690 ▶ if (mode == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (mode == 0) { 2290522 4582168 6872690
515 2290522 ▶ XPUSHs(sv_2mortal(key));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(key)); 5 2290517 2290522
516  
517 /* Mode 1/2 is list of hash-refs */
518 4582168 ▶ } else if (mode == 1 || mode == 2) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (mode == 1 || mode == 2) { 2291773 2290395 4582168
} else if (mode == 1 || mode == 2) { 2291773 0 2291773
519 4582168 HV * ih = (HV *)sv_2mortal((SV *)newHV());
520  
521 4582168 ▶ if (flags & FC_HASMODSEQ) {
Branch: 1 branch
BranchTrueFalseTotal
if (flags & FC_HASMODSEQ) { 1 4582167 4582168
522 1 hv_store(ih, "modseq", 6, newSVuv((UV)modseq), 0);
523 1 flags ^= FC_HASMODSEQ;
524 }
525  
526 /* These things by default */
527 4582168 hv_store(ih, "key", 3, key, 0);
528 4582168 hv_store(ih, "last_access", 11, newSViv((IV)last_access), 0);
529 4582168 hv_store(ih, "expire_on", 9, newSViv((IV)expire_on), 0);
530 4582168 hv_store(ih, "flags", 5, newSViv((IV)flags), 0);
531  
532 /* Add value to hash-ref if mode 2 */
533 4582168 ▶ if (mode == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (mode == 2) { 2291773 2290395 4582168
534 SV * val;
535 2291773 ▶ if (flags & FC_UNDEF) {
Branch: 1 branch
BranchTrueFalseTotal
if (flags & FC_UNDEF) { 462300 1829473 2291773
536 462300 val = newSV(0);
537 462300 flags ^= FC_UNDEF;
538 } else {
539 1829473 val = newSVpvn((const char *)val_ptr, val_len);
540 1829473 ▶ if (flags & FC_UTF8VAL) {
Branch: 1 branch
BranchTrueFalseTotal
if (flags & FC_UTF8VAL) { 453457 1376016 1829473
541 453457 SvUTF8_on(val);
542 453457 flags ^= FC_UTF8VAL;
543 }
544 }
545 2291773 hv_store(ih, "value", 5, val, 0);
546 }
547  
548 /* Create reference to hash */
549 4582168 ▶ XPUSHs(sv_2mortal(newRV((SV *)ih)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newRV((SV *)ih))); 0 4582168 4582168
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 UV
645 fc_peek(obj, offset)
646 SV * obj;
647 UV offset;
648 INIT:
649 MU32 val;
650 306 ▶ FC_ENTRY
Branch: 3 branches
BranchTrueFalseTotal
FC_ENTRY 0 306 306
FC_ENTRY 0 306 306
FC_ENTRY 0 306 306
651  
652 CODE:
653 306 ▶ if (mmc_peek(cache, (MU64)offset, &val) != 0)
Branch: 1 branch
BranchTrueFalseTotal
if (mmc_peek(cache, (MU64)offset, &val) != 0) 0 306 306
654 0 croak("%s", mmc_error(cache));
655 306 ▶ RETVAL = (UV)val;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (UV)val; 305 1 306
656 OUTPUT:
657 RETVAL
658  
659 NO_OUTPUT void
660 fc_poke(obj, offset, val)
661 SV * obj;
662 UV offset;
663 UV val;
664 INIT:
665 59 ▶ FC_ENTRY
Branch: 3 branches
BranchTrueFalseTotal
FC_ENTRY 0 59 59
FC_ENTRY 0 59 59
FC_ENTRY 0 59 59
666  
667 CODE:
668 59 ▶ if (mmc_poke(cache, (MU64)offset, (MU32)val) != 0)
Branch: 1 branch
BranchTrueFalseTotal
if (mmc_poke(cache, (MU64)offset, (MU32)val) != 0) 0 59 59
669 0 croak("%s", mmc_error(cache));
670  
671  
672 NO_OUTPUT void
673 fc_dump_page(obj);
674 SV * obj;
675 INIT:
676 0 ▶ FC_ENTRY
Branch: 3 branches
BranchTrueFalseTotal
FC_ENTRY 0 0 0
FC_ENTRY 0 0 0
FC_ENTRY 0 0 0
677  
678 CODE:
679 0 _mmc_dump_page(cache);
680  
681  
682 NO_OUTPUT void
683 fc_set_time_override(set_time);
684 UV set_time;
685  
686 CODE:
687 14 mmc_set_time_override((MU32)set_time);
688  
689  
« unix.c ↑ Summary mmap_cache.c »