Shared.xs

filter: Statementstmt 90.7% 371 / 409 Branchbran 47.5% 449 / 944 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 60.6% 820 / 1353 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/Data/Sync/Shared/RWLock.pm ↑ Summary sync.h »
1 #define PERL_NO_GET_CONTEXT
2 #include "EXTERN.h"
3 #include "perl.h"
4 #include "XSUB.h"
5  
6 #include "ppport.h"
7 #include "sync.h"
8  
9 #define EXTRACT_HANDLE(classname, sv) \
10 if (!sv_isobject(sv) || !sv_derived_from(sv, classname)) \
11 croak("Expected a %s object", classname); \
12 SyncHandle *h = INT2PTR(SyncHandle*, SvIV(SvRV(sv))); \
13 if (!h) croak("Attempted to use a destroyed %s object", classname); \
14 SyncHandle *h0 = h; PERL_UNUSED_VAR(h0); \
15 sv_2mortal(SvREFCNT_inc(SvRV(sv)))
16  
17 /* Re-read the handle after a call that can run Perl code (tied/overloaded
18 * argument magic, tied-array fetches). That code may call $obj->DESTROY
19 * explicitly, which frees the handle and zeroes the IV; EXTRACT_HANDLE's
20 * mortal pins the referent only against refcount-driven destruction, not an
21 * explicit DESTROY, so the local h would dangle. Used only where magic
22 * can actually intervene between EXTRACT_HANDLE and the first use of h. */
23 /* The same Perl that can destroy the handle can also REPLACE the invocant
24 * ($obj = 42 from an overload handler mutates ST(0), because Perl passes
25 * aliases), so SvROK must be re-checked before SvRV -- otherwise SvRV would
26 * run on a non-reference. */
27 #define REEXTRACT(sv) \
28 if (!SvROK(sv)) \
29 croak("Data::Sync::Shared object was replaced during the call"); \
30 h = INT2PTR(SyncHandle*, SvIV(SvRV(sv))); \
31 if (h != h0) croak("Data::Sync::Shared object replaced or destroyed during the call")
32  
33 #define MAKE_OBJ(class, handle) \
34 SV *obj = newSViv(PTR2IV(handle)); \
35 SV *ref = newRV_noinc(obj); \
36 sv_bless(ref, gv_stashpv(class, GV_ADD)); \
37 RETVAL = ref
38  
39 MODULE = Data::Sync::Shared PACKAGE = Data::Sync::Shared::Semaphore
40  
41 PROTOTYPES: DISABLE
42  
43 SV *
44 new(class, path, max, ...)
45 const char *class
46 SV *path
47 UV max
48 PREINIT:
49 char errbuf[SYNC_ERR_BUFLEN];
50 CODE:
51 35 ▶ uint32_t initial = (items > 3 && (SvGETMAGIC(ST(3)), SvOK(ST(3)))) ? (uint32_t)SvUV(ST(3)) : (uint32_t)max;
Branch: 4 branches
BranchTrueFalseTotal
uint32_t initial = (items > 3 && (SvGETMAGIC(ST(3)), SvOK(ST(3)))) ? (uint32_t)SvUV(ST(3)) : (uint32_t)max; 10 25 35
uint32_t initial = (items > 3 && (SvGETMAGIC(ST(3)), SvOK(ST(3)))) ? (uint32_t)SvUV(ST(3)) : (uint32_t)max; 0 10 10
uint32_t initial = (items > 3 && (SvGETMAGIC(ST(3)), SvOK(ST(3)))) ? (uint32_t)SvUV(ST(3)) : (uint32_t)max; 0 0 0
uint32_t initial = (items > 3 && (SvGETMAGIC(ST(3)), SvOK(ST(3)))) ? (uint32_t)SvUV(ST(3)) : (uint32_t)max; 10 0 10
52 35 ▶ mode_t mode = (items > 4 && (SvGETMAGIC(ST(4)), SvOK(ST(4)))) ? (mode_t)SvUV(ST(4)) : 0600;
Branch: 4 branches
BranchTrueFalseTotal
mode_t mode = (items > 4 && (SvGETMAGIC(ST(4)), SvOK(ST(4)))) ? (mode_t)SvUV(ST(4)) : 0600; 0 35 35
mode_t mode = (items > 4 && (SvGETMAGIC(ST(4)), SvOK(ST(4)))) ? (mode_t)SvUV(ST(4)) : 0600; 0 0 0
mode_t mode = (items > 4 && (SvGETMAGIC(ST(4)), SvOK(ST(4)))) ? (mode_t)SvUV(ST(4)) : 0600; 0 0 0
mode_t mode = (items > 4 && (SvGETMAGIC(ST(4)), SvOK(ST(4)))) ? (mode_t)SvUV(ST(4)) : 0600; 0 0 0
53 47 ▶ const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL;
Branch: 3 branches
BranchTrueFalseTotal
const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL; 0 35 35
const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL; 0 0 0
const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL; 12 23 35
54 35 SyncHandle *h = sync_create(p, SYNC_TYPE_SEMAPHORE, (uint32_t)max, initial, mode, errbuf);
55 35 ▶ if (!h) croak("Data::Sync::Shared::Semaphore->new: %s", errbuf[0] ? errbuf : "out of memory");
Branch: 2 branches
BranchTrueFalseTotal
if (!h) croak("Data::Sync::Shared::Semaphore->new: %s", errbuf[0] ? errbuf : "out of memory"); 6 29 35
if (!h) croak("Data::Sync::Shared::Semaphore->new: %s", errbuf[0] ? errbuf : "out of memory"); 6 0 6
56 29 MAKE_OBJ(class, h);
57 OUTPUT:
58 RETVAL
59  
60 SV *
61 new_memfd(class, name, max, ...)
62 const char *class
63 const char *name
64 UV max
65 PREINIT:
66 char errbuf[SYNC_ERR_BUFLEN];
67 CODE:
68 2 ▶ uint32_t initial = (items > 3 && (SvGETMAGIC(ST(3)), SvOK(ST(3)))) ? (uint32_t)SvUV(ST(3)) : (uint32_t)max;
Branch: 4 branches
BranchTrueFalseTotal
uint32_t initial = (items > 3 && (SvGETMAGIC(ST(3)), SvOK(ST(3)))) ? (uint32_t)SvUV(ST(3)) : (uint32_t)max; 0 2 2
uint32_t initial = (items > 3 && (SvGETMAGIC(ST(3)), SvOK(ST(3)))) ? (uint32_t)SvUV(ST(3)) : (uint32_t)max; 0 0 0
uint32_t initial = (items > 3 && (SvGETMAGIC(ST(3)), SvOK(ST(3)))) ? (uint32_t)SvUV(ST(3)) : (uint32_t)max; 0 0 0
uint32_t initial = (items > 3 && (SvGETMAGIC(ST(3)), SvOK(ST(3)))) ? (uint32_t)SvUV(ST(3)) : (uint32_t)max; 0 0 0
69 2 SyncHandle *h = sync_create_memfd(name, SYNC_TYPE_SEMAPHORE, (uint32_t)max, initial, errbuf);
70 2 ▶ if (!h) croak("Data::Sync::Shared::Semaphore->new_memfd: %s", errbuf[0] ? errbuf : "out of memory");
Branch: 2 branches
BranchTrueFalseTotal
if (!h) croak("Data::Sync::Shared::Semaphore->new_memfd: %s", errbuf[0] ? errbuf : "out of memory"); 0 2 2
if (!h) croak("Data::Sync::Shared::Semaphore->new_memfd: %s", errbuf[0] ? errbuf : "out of memory"); 0 0 0
71 2 MAKE_OBJ(class, h);
72 OUTPUT:
73 RETVAL
74  
75 SV *
76 new_from_fd(class, fd)
77 const char *class
78 int fd
79 PREINIT:
80 char errbuf[SYNC_ERR_BUFLEN];
81 CODE:
82 2 SyncHandle *h = sync_open_fd(fd, SYNC_TYPE_SEMAPHORE, errbuf);
83 2 ▶ if (!h) croak("Data::Sync::Shared::Semaphore->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory");
Branch: 2 branches
BranchTrueFalseTotal
if (!h) croak("Data::Sync::Shared::Semaphore->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory"); 1 1 2
if (!h) croak("Data::Sync::Shared::Semaphore->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory"); 1 0 1
84 1 MAKE_OBJ(class, h);
85 OUTPUT:
86 RETVAL
87  
88 void
89 DESTROY(self)
90 SV *self
91 CODE:
92 33 ▶ if (!sv_isobject(self) || !sv_derived_from(self, "Data::Sync::Shared::Semaphore")) return;
Branch: 2 branches
BranchTrueFalseTotal
if (!sv_isobject(self) || !sv_derived_from(self, "Data::Sync::Shared::Semaphore")) return; 33 0 33
if (!sv_isobject(self) || !sv_derived_from(self, "Data::Sync::Shared::Semaphore")) return; 0 33 33
93 33 SyncHandle *h = INT2PTR(SyncHandle*, SvIV(SvRV(self)));
94 33 ▶ if (!h) return;
Branch: 1 branch
BranchTrueFalseTotal
if (!h) return; 1 32 33
95 32 sv_setiv(SvRV(self), 0);
96 32 sync_destroy(h);
97  
98 bool
99 acquire(self, ...)
100 SV *self
101 PREINIT:
102 4 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 4 0 4
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 0 4 4
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 0 4 4
103 4 double timeout = -1;
104 CODE:
105 4 ▶ if (items > 1 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) timeout = SvNV(ST(1));
Branch: 4 branches
BranchTrueFalseTotal
if (items > 1 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) timeout = SvNV(ST(1)); 3 1 4
if (items > 1 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) timeout = SvNV(ST(1)); 0 3 3
if (items > 1 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) timeout = SvNV(ST(1)); 0 0 0
if (items > 1 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) timeout = SvNV(ST(1)); 3 0 3
106 4 ▶ REEXTRACT(self);
Branch: 2 branches
BranchTrueFalseTotal
REEXTRACT(self); 0 4 4
REEXTRACT(self); 0 4 4
107 4 ▶ RETVAL = sync_sem_acquire(h, timeout);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = sync_sem_acquire(h, timeout); 2 2 4
108 OUTPUT:
109 RETVAL
110  
111 bool
112 try_acquire(self)
113 SV *self
114 PREINIT:
115 26 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 26 0 26
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 0 26 26
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 0 26 26
116 CODE:
117 26 ▶ RETVAL = sync_sem_try_acquire(h);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = sync_sem_try_acquire(h); 24 2 26
118 OUTPUT:
119 RETVAL
120  
121 bool
122 acquire_n(self, n, ...)
123 SV *self
124 UV n
125 PREINIT:
126 3 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 3 0 3
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 0 3 3
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 0 3 3
127 3 double timeout = -1;
128 CODE:
129 3 ▶ if (items > 2 && (SvGETMAGIC(ST(2)), SvOK(ST(2)))) timeout = SvNV(ST(2));
Branch: 4 branches
BranchTrueFalseTotal
if (items > 2 && (SvGETMAGIC(ST(2)), SvOK(ST(2)))) timeout = SvNV(ST(2)); 2 1 3
if (items > 2 && (SvGETMAGIC(ST(2)), SvOK(ST(2)))) timeout = SvNV(ST(2)); 0 2 2
if (items > 2 && (SvGETMAGIC(ST(2)), SvOK(ST(2)))) timeout = SvNV(ST(2)); 0 0 0
if (items > 2 && (SvGETMAGIC(ST(2)), SvOK(ST(2)))) timeout = SvNV(ST(2)); 2 0 2
130 3 ▶ REEXTRACT(self);
Branch: 2 branches
BranchTrueFalseTotal
REEXTRACT(self); 0 3 3
REEXTRACT(self); 0 3 3
131 /* n is a UV: reject n > max up front. Otherwise a huge n truncates to uint32,
132 * and any n above the semaphore max makes the wait condition (cur >= n)
133 * unsatisfiable -> a blocking acquire_n hangs forever. */
134 3 ▶ if (n > (UV)h->hdr->param)
Branch: 1 branch
BranchTrueFalseTotal
if (n > (UV)h->hdr->param) 0 3 3
135 0 croak("Data::Sync::Shared::Semaphore->acquire_n: n (%" UVuf ") exceeds max (%u)",
136 n, (unsigned)h->hdr->param);
137 3 ▶ RETVAL = sync_sem_acquire_n(h, (uint32_t)n, timeout);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = sync_sem_acquire_n(h, (uint32_t)n, timeout); 2 1 3
138 OUTPUT:
139 RETVAL
140  
141 bool
142 try_acquire_n(self, n)
143 SV *self
144 UV n
145 PREINIT:
146 6 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 6 0 6
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 0 6 6
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 0 6 6
147 CODE:
148 6 ▶ RETVAL = sync_sem_try_acquire_n(h, (uint32_t)n);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = sync_sem_try_acquire_n(h, (uint32_t)n); 4 2 6
149 OUTPUT:
150 RETVAL
151  
152 void
153 release(self, ...)
154 SV *self
155 PREINIT:
156 23 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 23 0 23
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 0 23 23
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 0 23 23
157 CODE:
158 23 ▶ if (items > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (items > 1) { 15 8 23
159 15 uint32_t n = (uint32_t)SvUV(ST(1));
160 15 ▶ REEXTRACT(self);
Branch: 2 branches
BranchTrueFalseTotal
REEXTRACT(self); 0 15 15
REEXTRACT(self); 0 15 15
161 15 sync_sem_release_n(h, n);
162 } else {
163 8 sync_sem_release(h);
164 }
165  
166 UV
167 drain(self)
168 SV *self
169 PREINIT:
170 4 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 4 0 4
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 0 4 4
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 0 4 4
171 CODE:
172 4 ▶ RETVAL = sync_sem_drain(h);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = sync_sem_drain(h); 0 4 4
173 OUTPUT:
174 RETVAL
175  
176 UV
177 value(self)
178 SV *self
179 PREINIT:
180 38 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 38 0 38
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 0 38 38
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 1 37 38
181 CODE:
182 37 ▶ RETVAL = sync_sem_value(h);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = sync_sem_value(h); 1 36 37
183 OUTPUT:
184 RETVAL
185  
186 UV
187 max(self)
188 SV *self
189 PREINIT:
190 5 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 5 0 5
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 0 5 5
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 0 5 5
191 CODE:
192 5 ▶ RETVAL = h->hdr->param;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = h->hdr->param; 0 5 5
193 OUTPUT:
194 RETVAL
195  
196 SV *
197 path(self)
198 SV *self
199 PREINIT:
200 2 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 2 0 2
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 0 2 2
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 0 2 2
201 CODE:
202 2 ▶ RETVAL = h->path ? newSVpv(h->path, 0) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = h->path ? newSVpv(h->path, 0) : &PL_sv_undef; 1 1 2
203 OUTPUT:
204 RETVAL
205  
206 IV
207 memfd(self)
208 SV *self
209 PREINIT:
210 2 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 2 0 2
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 0 2 2
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 0 2 2
211 CODE:
212 2 ▶ RETVAL = h->backing_fd;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = h->backing_fd; 0 2 2
213 OUTPUT:
214 RETVAL
215  
216 IV
217 eventfd(self)
218 SV *self
219 PREINIT:
220 3 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 3 0 3
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 0 3 3
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 0 3 3
221 CODE:
222 3 RETVAL = sync_create_eventfd(h);
223 3 ▶ if (RETVAL < 0) croak("eventfd: %s", strerror(errno));
Branch: 1 branch
BranchTrueFalseTotal
if (RETVAL < 0) croak("eventfd: %s", strerror(errno)); 0 3 3
224 OUTPUT:
225 RETVAL
226  
227 void
228 eventfd_set(self, fd)
229 SV *self
230 int fd
231 PREINIT:
232 1 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 1 0 1
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 0 1 1
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 0 1 1
233 CODE:
234 1 ▶ if (h->notify_fd >= 0 && h->notify_fd != fd) close(h->notify_fd);
Branch: 2 branches
BranchTrueFalseTotal
if (h->notify_fd >= 0 && h->notify_fd != fd) close(h->notify_fd); 1 0 1
if (h->notify_fd >= 0 && h->notify_fd != fd) close(h->notify_fd); 1 0 1
235 1 h->notify_fd = fd;
236  
237 IV
238 fileno(self)
239 SV *self
240 PREINIT:
241 3 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 3 0 3
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 0 3 3
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 0 3 3
242 CODE:
243 3 ▶ RETVAL = h->notify_fd;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = h->notify_fd; 0 3 3
244 OUTPUT:
245 RETVAL
246  
247 bool
248 notify(self)
249 SV *self
250 PREINIT:
251 2 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 2 0 2
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 0 2 2
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 0 2 2
252 CODE:
253 2 ▶ RETVAL = sync_notify(h);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = sync_notify(h); 2 0 2
254 OUTPUT:
255 RETVAL
256  
257 SV *
258 eventfd_consume(self)
259 SV *self
260 PREINIT:
261 3 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 3 0 3
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 0 3 3
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 0 3 3
262 CODE:
263 3 int64_t v = sync_eventfd_consume(h);
264 3 ▶ RETVAL = (v >= 0) ? newSViv((IV)v) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (v >= 0) ? newSViv((IV)v) : &PL_sv_undef; 2 1 3
265 OUTPUT:
266 RETVAL
267  
268 void
269 sync(self)
270 SV *self
271 PREINIT:
272 0 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 0 0 0
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 0 0 0
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 0 0 0
273 CODE:
274 0 ▶ if (sync_msync(h) != 0) croak("msync: %s", strerror(errno));
Branch: 1 branch
BranchTrueFalseTotal
if (sync_msync(h) != 0) croak("msync: %s", strerror(errno)); 0 0 0
275  
276 void
277 unlink(self_or_class, ...)
278 SV *self_or_class
279 CODE:
280 const char *p;
281 4 ▶ if (sv_isobject(self_or_class) && sv_derived_from(self_or_class, "Data::Sync::Shared::Semaphore")) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv_isobject(self_or_class) && sv_derived_from(self_or_class, "Data::Sync::Shared::Semaphore")) { 3 1 4
if (sv_isobject(self_or_class) && sv_derived_from(self_or_class, "Data::Sync::Shared::Semaphore")) { 3 0 3
282 3 SyncHandle *h = INT2PTR(SyncHandle*, SvIV(SvRV(self_or_class)));
283 3 ▶ if (!h) croak("Attempted to use a destroyed object");
Branch: 1 branch
BranchTrueFalseTotal
if (!h) croak("Attempted to use a destroyed object"); 0 3 3
284 3 p = h->path;
285 } else {
286 1 ▶ if (items < 2) croak("Usage: ...->unlink($path)");
Branch: 1 branch
BranchTrueFalseTotal
if (items < 2) croak("Usage: ...->unlink($path)"); 1 0 1
287 0 p = SvPV_nolen(ST(1));
288 }
289 3 ▶ if (!p) croak("cannot unlink anonymous or memfd object");
Branch: 1 branch
BranchTrueFalseTotal
if (!p) croak("cannot unlink anonymous or memfd object"); 1 2 3
290 2 ▶ if (unlink(p) != 0 && errno != ENOENT)
Branch: 2 branches
BranchTrueFalseTotal
if (unlink(p) != 0 && errno != ENOENT) 0 2 2
if (unlink(p) != 0 && errno != ENOENT) 0 0 0
291 0 croak("unlink(%s): %s", p, strerror(errno));
292  
293 SV *
294 stats(self)
295 SV *self
296 PREINIT:
297 24 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 24 0 24
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 0 24 24
EXTRACT_HANDLE("Data::Sync::Shared::Semaphore", self); 0 24 24
298 CODE:
299 24 HV *hv = newHV();
300 24 SyncHeader *hdr = h->hdr;
301 24 hv_store(hv, "value", 5, newSVuv(sync_sem_value(h)), 0);
302 24 hv_store(hv, "max", 3, newSVuv(hdr->param), 0);
303 24 hv_store(hv, "waiters", 7, newSVuv((UV)__atomic_load_n(&hdr->waiters, __ATOMIC_RELAXED)), 0);
304 24 hv_store(hv, "mmap_size", 9, newSVuv((UV)h->mmap_size), 0);
305 24 hv_store(hv, "acquires", 8, newSVuv((UV)__atomic_load_n(&hdr->stat_acquires, __ATOMIC_RELAXED)), 0);
306 24 hv_store(hv, "releases", 8, newSVuv((UV)__atomic_load_n(&hdr->stat_releases, __ATOMIC_RELAXED)), 0);
307 24 hv_store(hv, "waits", 5, newSVuv((UV)__atomic_load_n(&hdr->stat_waits, __ATOMIC_RELAXED)), 0);
308 24 hv_store(hv, "timeouts", 8, newSVuv((UV)__atomic_load_n(&hdr->stat_timeouts, __ATOMIC_RELAXED)), 0);
309 24 hv_store(hv, "recoveries", 10, newSVuv((UV)__atomic_load_n(&hdr->stat_recoveries, __ATOMIC_RELAXED)), 0);
310 24 RETVAL = newRV_noinc((SV *)hv);
311 OUTPUT:
312 RETVAL
313  
314 MODULE = Data::Sync::Shared PACKAGE = Data::Sync::Shared::Barrier
315  
316 PROTOTYPES: DISABLE
317  
318 SV *
319 new(class, path, parties, ...)
320 const char *class
321 SV *path
322 UV parties
323 PREINIT:
324 char errbuf[SYNC_ERR_BUFLEN];
325 CODE:
326 14 ▶ mode_t mode = (items > 3 && (SvGETMAGIC(ST(3)), SvOK(ST(3)))) ? (mode_t)SvUV(ST(3)) : 0600;
Branch: 4 branches
BranchTrueFalseTotal
mode_t mode = (items > 3 && (SvGETMAGIC(ST(3)), SvOK(ST(3)))) ? (mode_t)SvUV(ST(3)) : 0600; 0 14 14
mode_t mode = (items > 3 && (SvGETMAGIC(ST(3)), SvOK(ST(3)))) ? (mode_t)SvUV(ST(3)) : 0600; 0 0 0
mode_t mode = (items > 3 && (SvGETMAGIC(ST(3)), SvOK(ST(3)))) ? (mode_t)SvUV(ST(3)) : 0600; 0 0 0
mode_t mode = (items > 3 && (SvGETMAGIC(ST(3)), SvOK(ST(3)))) ? (mode_t)SvUV(ST(3)) : 0600; 0 0 0
327 17 ▶ const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL;
Branch: 3 branches
BranchTrueFalseTotal
const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL; 0 14 14
const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL; 0 0 0
const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL; 3 11 14
328 14 SyncHandle *h = sync_create(p, SYNC_TYPE_BARRIER, (uint32_t)parties, 0, mode, errbuf);
329 14 ▶ if (!h) croak("Data::Sync::Shared::Barrier->new: %s", errbuf[0] ? errbuf : "out of memory");
Branch: 2 branches
BranchTrueFalseTotal
if (!h) croak("Data::Sync::Shared::Barrier->new: %s", errbuf[0] ? errbuf : "out of memory"); 3 11 14
if (!h) croak("Data::Sync::Shared::Barrier->new: %s", errbuf[0] ? errbuf : "out of memory"); 3 0 3
330 11 MAKE_OBJ(class, h);
331 OUTPUT:
332 RETVAL
333  
334 SV *
335 new_memfd(class, name, parties)
336 const char *class
337 const char *name
338 UV parties
339 PREINIT:
340 char errbuf[SYNC_ERR_BUFLEN];
341 CODE:
342 1 SyncHandle *h = sync_create_memfd(name, SYNC_TYPE_BARRIER, (uint32_t)parties, 0, errbuf);
343 1 ▶ if (!h) croak("Data::Sync::Shared::Barrier->new_memfd: %s", errbuf[0] ? errbuf : "out of memory");
Branch: 2 branches
BranchTrueFalseTotal
if (!h) croak("Data::Sync::Shared::Barrier->new_memfd: %s", errbuf[0] ? errbuf : "out of memory"); 0 1 1
if (!h) croak("Data::Sync::Shared::Barrier->new_memfd: %s", errbuf[0] ? errbuf : "out of memory"); 0 0 0
344 1 MAKE_OBJ(class, h);
345 OUTPUT:
346 RETVAL
347  
348 SV *
349 new_from_fd(class, fd)
350 const char *class
351 int fd
352 PREINIT:
353 char errbuf[SYNC_ERR_BUFLEN];
354 CODE:
355 1 SyncHandle *h = sync_open_fd(fd, SYNC_TYPE_BARRIER, errbuf);
356 1 ▶ if (!h) croak("Data::Sync::Shared::Barrier->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory");
Branch: 2 branches
BranchTrueFalseTotal
if (!h) croak("Data::Sync::Shared::Barrier->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory"); 1 0 1
if (!h) croak("Data::Sync::Shared::Barrier->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory"); 1 0 1
357 0 MAKE_OBJ(class, h);
358 OUTPUT:
359 RETVAL
360  
361 void
362 DESTROY(self)
363 SV *self
364 CODE:
365 12 ▶ if (!sv_isobject(self) || !sv_derived_from(self, "Data::Sync::Shared::Barrier")) return;
Branch: 2 branches
BranchTrueFalseTotal
if (!sv_isobject(self) || !sv_derived_from(self, "Data::Sync::Shared::Barrier")) return; 12 0 12
if (!sv_isobject(self) || !sv_derived_from(self, "Data::Sync::Shared::Barrier")) return; 0 12 12
366 12 SyncHandle *h = INT2PTR(SyncHandle*, SvIV(SvRV(self)));
367 12 ▶ if (!h) return;
Branch: 1 branch
BranchTrueFalseTotal
if (!h) return; 0 12 12
368 12 sv_setiv(SvRV(self), 0);
369 12 sync_destroy(h);
370  
371 IV
372 wait(self, ...)
373 SV *self
374 PREINIT:
375 11 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 11 0 11
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 0 11 11
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 0 11 11
376 11 ▶ double timeout = -1;
Branch: 1 branch
BranchTrueFalseTotal
double timeout = -1; 11 0 11
377 CODE:
378 11 ▶ if (items > 1 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) timeout = SvNV(ST(1));
Branch: 4 branches
BranchTrueFalseTotal
if (items > 1 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) timeout = SvNV(ST(1)); 11 0 11
if (items > 1 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) timeout = SvNV(ST(1)); 0 11 11
if (items > 1 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) timeout = SvNV(ST(1)); 0 0 0
if (items > 1 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) timeout = SvNV(ST(1)); 11 0 11
379 11 ▶ REEXTRACT(self);
Branch: 2 branches
BranchTrueFalseTotal
REEXTRACT(self); 0 11 11
REEXTRACT(self); 0 11 11
380 11 ▶ RETVAL = sync_barrier_wait(h, timeout);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = sync_barrier_wait(h, timeout); 2 9 11
381 OUTPUT:
382 RETVAL
383  
384 UV
385 generation(self)
386 SV *self
387 PREINIT:
388 5 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 5 0 5
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 0 5 5
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 0 5 5
389 CODE:
390 5 ▶ RETVAL = sync_barrier_generation(h);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = sync_barrier_generation(h); 2 3 5
391 OUTPUT:
392 RETVAL
393  
394 UV
395 arrived(self)
396 SV *self
397 PREINIT:
398 3 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 3 0 3
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 0 3 3
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 0 3 3
399 CODE:
400 3 ▶ RETVAL = sync_barrier_arrived(h);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = sync_barrier_arrived(h); 0 3 3
401 OUTPUT:
402 RETVAL
403  
404 UV
405 parties(self)
406 SV *self
407 PREINIT:
408 1 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 1 0 1
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 0 1 1
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 0 1 1
409 CODE:
410 1 ▶ RETVAL = h->hdr->param;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = h->hdr->param; 0 1 1
411 OUTPUT:
412 RETVAL
413  
414 bool
415 is_broken(self)
416 SV *self
417 PREINIT:
418 3 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 3 0 3
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 0 3 3
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 0 3 3
419 CODE:
420 3 ▶ RETVAL = sync_barrier_is_broken(h) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = sync_barrier_is_broken(h) ? 1 : 0; 2 1 3
421 OUTPUT:
422 RETVAL
423  
424 void
425 reset(self)
426 SV *self
427 PREINIT:
428 2 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 2 0 2
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 0 2 2
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 0 2 2
429 CODE:
430 2 sync_barrier_reset(h);
431  
432 SV *
433 path(self)
434 SV *self
435 PREINIT:
436 2 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 2 0 2
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 0 2 2
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 0 2 2
437 CODE:
438 2 ▶ RETVAL = h->path ? newSVpv(h->path, 0) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = h->path ? newSVpv(h->path, 0) : &PL_sv_undef; 1 1 2
439 OUTPUT:
440 RETVAL
441  
442 IV
443 memfd(self)
444 SV *self
445 PREINIT:
446 1 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 1 0 1
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 0 1 1
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 0 1 1
447 CODE:
448 1 ▶ RETVAL = h->backing_fd;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = h->backing_fd; 0 1 1
449 OUTPUT:
450 RETVAL
451  
452 IV
453 eventfd(self)
454 SV *self
455 PREINIT:
456 2 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 2 0 2
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 0 2 2
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 0 2 2
457 CODE:
458 2 RETVAL = sync_create_eventfd(h);
459 2 ▶ if (RETVAL < 0) croak("eventfd: %s", strerror(errno));
Branch: 1 branch
BranchTrueFalseTotal
if (RETVAL < 0) croak("eventfd: %s", strerror(errno)); 0 2 2
460 OUTPUT:
461 RETVAL
462  
463 void
464 eventfd_set(self, fd)
465 SV *self
466 int fd
467 PREINIT:
468 1 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 1 0 1
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 0 1 1
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 0 1 1
469 CODE:
470 1 ▶ if (h->notify_fd >= 0 && h->notify_fd != fd) close(h->notify_fd);
Branch: 2 branches
BranchTrueFalseTotal
if (h->notify_fd >= 0 && h->notify_fd != fd) close(h->notify_fd); 1 0 1
if (h->notify_fd >= 0 && h->notify_fd != fd) close(h->notify_fd); 1 0 1
471 1 h->notify_fd = fd;
472  
473 IV
474 fileno(self)
475 SV *self
476 PREINIT:
477 3 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 3 0 3
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 0 3 3
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 0 3 3
478 CODE:
479 3 ▶ RETVAL = h->notify_fd;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = h->notify_fd; 3 0 3
480 OUTPUT:
481 RETVAL
482  
483 bool
484 notify(self)
485 SV *self
486 PREINIT:
487 2 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 2 0 2
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 0 2 2
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 0 2 2
488 CODE:
489 2 ▶ RETVAL = sync_notify(h);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = sync_notify(h); 2 0 2
490 OUTPUT:
491 RETVAL
492  
493 SV *
494 eventfd_consume(self)
495 SV *self
496 PREINIT:
497 2 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 2 0 2
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 0 2 2
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 0 2 2
498 CODE:
499 2 int64_t v = sync_eventfd_consume(h);
500 2 ▶ RETVAL = (v >= 0) ? newSViv((IV)v) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (v >= 0) ? newSViv((IV)v) : &PL_sv_undef; 1 1 2
501 OUTPUT:
502 RETVAL
503  
504 void
505 sync(self)
506 SV *self
507 PREINIT:
508 0 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 0 0 0
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 0 0 0
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 0 0 0
509 CODE:
510 0 ▶ if (sync_msync(h) != 0) croak("msync: %s", strerror(errno));
Branch: 1 branch
BranchTrueFalseTotal
if (sync_msync(h) != 0) croak("msync: %s", strerror(errno)); 0 0 0
511  
512 void
513 unlink(self_or_class, ...)
514 SV *self_or_class
515 CODE:
516 const char *p;
517 1 ▶ if (sv_isobject(self_or_class) && sv_derived_from(self_or_class, "Data::Sync::Shared::Barrier")) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv_isobject(self_or_class) && sv_derived_from(self_or_class, "Data::Sync::Shared::Barrier")) { 1 0 1
if (sv_isobject(self_or_class) && sv_derived_from(self_or_class, "Data::Sync::Shared::Barrier")) { 1 0 1
518 1 SyncHandle *h = INT2PTR(SyncHandle*, SvIV(SvRV(self_or_class)));
519 1 ▶ if (!h) croak("Attempted to use a destroyed object");
Branch: 1 branch
BranchTrueFalseTotal
if (!h) croak("Attempted to use a destroyed object"); 0 1 1
520 1 p = h->path;
521 } else {
522 0 ▶ if (items < 2) croak("Usage: ...->unlink($path)");
Branch: 1 branch
BranchTrueFalseTotal
if (items < 2) croak("Usage: ...->unlink($path)"); 0 0 0
523 0 p = SvPV_nolen(ST(1));
524 }
525 1 ▶ if (!p) croak("cannot unlink anonymous or memfd object");
Branch: 1 branch
BranchTrueFalseTotal
if (!p) croak("cannot unlink anonymous or memfd object"); 0 1 1
526 1 ▶ if (unlink(p) != 0 && errno != ENOENT)
Branch: 2 branches
BranchTrueFalseTotal
if (unlink(p) != 0 && errno != ENOENT) 0 1 1
if (unlink(p) != 0 && errno != ENOENT) 0 0 0
527 0 croak("unlink(%s): %s", p, strerror(errno));
528  
529 SV *
530 stats(self)
531 SV *self
532 PREINIT:
533 5 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 5 0 5
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 0 5 5
EXTRACT_HANDLE("Data::Sync::Shared::Barrier", self); 0 5 5
534 CODE:
535 5 HV *hv = newHV();
536 5 SyncHeader *hdr = h->hdr;
537 5 hv_store(hv, "parties", 7, newSVuv(hdr->param), 0);
538 5 hv_store(hv, "arrived", 7, newSVuv(sync_barrier_arrived(h)), 0);
539 5 hv_store(hv, "generation", 10, newSVuv(sync_barrier_generation(h)), 0);
540 5 hv_store(hv, "waiters", 7, newSVuv((UV)__atomic_load_n(&hdr->waiters, __ATOMIC_RELAXED)), 0);
541 5 hv_store(hv, "mmap_size", 9, newSVuv((UV)h->mmap_size), 0);
542 5 hv_store(hv, "waits", 5, newSVuv((UV)__atomic_load_n(&hdr->stat_waits, __ATOMIC_RELAXED)), 0);
543 5 hv_store(hv, "releases", 8, newSVuv((UV)__atomic_load_n(&hdr->stat_releases, __ATOMIC_RELAXED)), 0);
544 5 hv_store(hv, "timeouts", 8, newSVuv((UV)__atomic_load_n(&hdr->stat_timeouts, __ATOMIC_RELAXED)), 0);
545 5 RETVAL = newRV_noinc((SV *)hv);
546 OUTPUT:
547 RETVAL
548  
549 MODULE = Data::Sync::Shared PACKAGE = Data::Sync::Shared::RWLock
550  
551 PROTOTYPES: DISABLE
552  
553 SV *
554 new(class, path, ...)
555 const char *class
556 SV *path
557 PREINIT:
558 char errbuf[SYNC_ERR_BUFLEN];
559 CODE:
560 14 ▶ mode_t mode = (items > 2 && (SvGETMAGIC(ST(2)), SvOK(ST(2)))) ? (mode_t)SvUV(ST(2)) : 0600;
Branch: 4 branches
BranchTrueFalseTotal
mode_t mode = (items > 2 && (SvGETMAGIC(ST(2)), SvOK(ST(2)))) ? (mode_t)SvUV(ST(2)) : 0600; 0 14 14
mode_t mode = (items > 2 && (SvGETMAGIC(ST(2)), SvOK(ST(2)))) ? (mode_t)SvUV(ST(2)) : 0600; 0 0 0
mode_t mode = (items > 2 && (SvGETMAGIC(ST(2)), SvOK(ST(2)))) ? (mode_t)SvUV(ST(2)) : 0600; 0 0 0
mode_t mode = (items > 2 && (SvGETMAGIC(ST(2)), SvOK(ST(2)))) ? (mode_t)SvUV(ST(2)) : 0600; 0 0 0
561 17 ▶ const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL;
Branch: 3 branches
BranchTrueFalseTotal
const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL; 0 14 14
const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL; 0 0 0
const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL; 3 11 14
562 14 SyncHandle *h = sync_create(p, SYNC_TYPE_RWLOCK, 0, 0, mode, errbuf);
563 14 ▶ if (!h) croak("Data::Sync::Shared::RWLock->new: %s", errbuf[0] ? errbuf : "out of memory");
Branch: 2 branches
BranchTrueFalseTotal
if (!h) croak("Data::Sync::Shared::RWLock->new: %s", errbuf[0] ? errbuf : "out of memory"); 1 13 14
if (!h) croak("Data::Sync::Shared::RWLock->new: %s", errbuf[0] ? errbuf : "out of memory"); 1 0 1
564 13 MAKE_OBJ(class, h);
565 OUTPUT:
566 RETVAL
567  
568 SV *
569 new_memfd(class, name)
570 const char *class
571 const char *name
572 PREINIT:
573 char errbuf[SYNC_ERR_BUFLEN];
574 CODE:
575 1 SyncHandle *h = sync_create_memfd(name, SYNC_TYPE_RWLOCK, 0, 0, errbuf);
576 1 ▶ if (!h) croak("Data::Sync::Shared::RWLock->new_memfd: %s", errbuf[0] ? errbuf : "out of memory");
Branch: 2 branches
BranchTrueFalseTotal
if (!h) croak("Data::Sync::Shared::RWLock->new_memfd: %s", errbuf[0] ? errbuf : "out of memory"); 0 1 1
if (!h) croak("Data::Sync::Shared::RWLock->new_memfd: %s", errbuf[0] ? errbuf : "out of memory"); 0 0 0
577 1 MAKE_OBJ(class, h);
578 OUTPUT:
579 RETVAL
580  
581 SV *
582 new_from_fd(class, fd)
583 const char *class
584 int fd
585 PREINIT:
586 char errbuf[SYNC_ERR_BUFLEN];
587 CODE:
588 1 SyncHandle *h = sync_open_fd(fd, SYNC_TYPE_RWLOCK, errbuf);
589 1 ▶ if (!h) croak("Data::Sync::Shared::RWLock->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory");
Branch: 2 branches
BranchTrueFalseTotal
if (!h) croak("Data::Sync::Shared::RWLock->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory"); 0 1 1
if (!h) croak("Data::Sync::Shared::RWLock->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory"); 0 0 0
590 1 MAKE_OBJ(class, h);
591 OUTPUT:
592 RETVAL
593  
594 void
595 DESTROY(self)
596 SV *self
597 CODE:
598 16 ▶ if (!sv_isobject(self) || !sv_derived_from(self, "Data::Sync::Shared::RWLock")) return;
Branch: 2 branches
BranchTrueFalseTotal
if (!sv_isobject(self) || !sv_derived_from(self, "Data::Sync::Shared::RWLock")) return; 16 0 16
if (!sv_isobject(self) || !sv_derived_from(self, "Data::Sync::Shared::RWLock")) return; 0 16 16
599 16 SyncHandle *h = INT2PTR(SyncHandle*, SvIV(SvRV(self)));
600 16 ▶ if (!h) return;
Branch: 1 branch
BranchTrueFalseTotal
if (!h) return; 1 15 16
601 15 sv_setiv(SvRV(self), 0);
602 15 sync_destroy(h);
603  
604 void
605 rdlock(self, ...)
606 SV *self
607 PREINIT:
608 8 ▶ EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 8 0 8
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 0 8 8
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 1 7 8
609 CODE:
610 7 ▶ if (items > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (items > 1) { 0 7 7
611 0 double timeout = SvNV(ST(1));
612 0 ▶ REEXTRACT(self);
Branch: 2 branches
BranchTrueFalseTotal
REEXTRACT(self); 0 0 0
REEXTRACT(self); 0 0 0
613 0 ▶ if (!sync_rwlock_rdlock_timed(h, timeout))
Branch: 1 branch
BranchTrueFalseTotal
if (!sync_rwlock_rdlock_timed(h, timeout)) 0 0 0
614 0 croak("rdlock: timeout");
615 } else {
616 7 sync_rwlock_rdlock(h);
617 }
618 7 __atomic_add_fetch(&h->hdr->stat_acquires, 1, __ATOMIC_RELAXED);
619  
620 bool
621 try_rdlock(self)
622 SV *self
623 PREINIT:
624 3 ▶ EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 3 0 3
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 0 3 3
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 0 3 3
625 CODE:
626 3 RETVAL = sync_rwlock_try_rdlock(h);
627 3 ▶ if (RETVAL)
Branch: 1 branch
BranchTrueFalseTotal
if (RETVAL) 2 1 3
628 2 __atomic_add_fetch(&h->hdr->stat_acquires, 1, __ATOMIC_RELAXED);
629 OUTPUT:
630 RETVAL
631  
632 bool
633 rdlock_timed(self, timeout)
634 SV *self
635 double timeout
636 PREINIT:
637 3 ▶ EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 3 0 3
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 0 3 3
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 0 3 3
638 CODE:
639 3 RETVAL = sync_rwlock_rdlock_timed(h, timeout);
640 3 ▶ if (RETVAL)
Branch: 1 branch
BranchTrueFalseTotal
if (RETVAL) 2 1 3
641 2 __atomic_add_fetch(&h->hdr->stat_acquires, 1, __ATOMIC_RELAXED);
642 OUTPUT:
643 RETVAL
644  
645 void
646 rdunlock(self)
647 SV *self
648 PREINIT:
649 12 ▶ EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 12 0 12
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 0 12 12
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 0 12 12
650 CODE:
651 12 sync_rwlock_rdunlock(h);
652 12 __atomic_add_fetch(&h->hdr->stat_releases, 1, __ATOMIC_RELAXED);
653  
654 void
655 wrlock(self, ...)
656 SV *self
657 PREINIT:
658 5 ▶ EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 5 0 5
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 0 5 5
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 0 5 5
659 CODE:
660 5 ▶ if (items > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (items > 1) { 0 5 5
661 0 double timeout = SvNV(ST(1));
662 0 ▶ REEXTRACT(self);
Branch: 2 branches
BranchTrueFalseTotal
REEXTRACT(self); 0 0 0
REEXTRACT(self); 0 0 0
663 0 ▶ if (!sync_rwlock_wrlock_timed(h, timeout))
Branch: 1 branch
BranchTrueFalseTotal
if (!sync_rwlock_wrlock_timed(h, timeout)) 0 0 0
664 0 croak("wrlock: timeout");
665 } else {
666 5 sync_rwlock_wrlock(h);
667 }
668 5 __atomic_add_fetch(&h->hdr->stat_acquires, 1, __ATOMIC_RELAXED);
669  
670 bool
671 try_wrlock(self)
672 SV *self
673 PREINIT:
674 3 ▶ EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 3 0 3
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 0 3 3
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 0 3 3
675 CODE:
676 3 RETVAL = sync_rwlock_try_wrlock(h);
677 3 ▶ if (RETVAL)
Branch: 1 branch
BranchTrueFalseTotal
if (RETVAL) 1 2 3
678 1 __atomic_add_fetch(&h->hdr->stat_acquires, 1, __ATOMIC_RELAXED);
679 OUTPUT:
680 RETVAL
681  
682 bool
683 wrlock_timed(self, timeout)
684 SV *self
685 double timeout
686 PREINIT:
687 4 ▶ EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 4 0 4
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 0 4 4
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 0 4 4
688 CODE:
689 4 RETVAL = sync_rwlock_wrlock_timed(h, timeout);
690 4 ▶ if (RETVAL)
Branch: 1 branch
BranchTrueFalseTotal
if (RETVAL) 3 1 4
691 3 __atomic_add_fetch(&h->hdr->stat_acquires, 1, __ATOMIC_RELAXED);
692 OUTPUT:
693 RETVAL
694  
695 void
696 wrunlock(self)
697 SV *self
698 PREINIT:
699 8 ▶ EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 8 0 8
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 0 8 8
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 0 8 8
700 CODE:
701 8 sync_rwlock_wrunlock(h);
702 8 __atomic_add_fetch(&h->hdr->stat_releases, 1, __ATOMIC_RELAXED);
703  
704 void
705 downgrade(self)
706 SV *self
707 PREINIT:
708 1 ▶ EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 1 0 1
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 0 1 1
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 0 1 1
709 CODE:
710 1 sync_rwlock_downgrade(h);
711 1 __atomic_add_fetch(&h->hdr->stat_releases, 1, __ATOMIC_RELAXED);
712 1 __atomic_add_fetch(&h->hdr->stat_acquires, 1, __ATOMIC_RELAXED);
713  
714 SV *
715 path(self)
716 SV *self
717 PREINIT:
718 2 ▶ EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 2 0 2
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 0 2 2
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 0 2 2
719 CODE:
720 2 ▶ RETVAL = h->path ? newSVpv(h->path, 0) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = h->path ? newSVpv(h->path, 0) : &PL_sv_undef; 1 1 2
721 OUTPUT:
722 RETVAL
723  
724 IV
725 memfd(self)
726 SV *self
727 PREINIT:
728 2 ▶ EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 2 0 2
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 0 2 2
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 0 2 2
729 CODE:
730 2 ▶ RETVAL = h->backing_fd;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = h->backing_fd; 0 2 2
731 OUTPUT:
732 RETVAL
733  
734 IV
735 eventfd(self)
736 SV *self
737 PREINIT:
738 2 ▶ EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 2 0 2
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 0 2 2
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 0 2 2
739 CODE:
740 2 RETVAL = sync_create_eventfd(h);
741 2 ▶ if (RETVAL < 0) croak("eventfd: %s", strerror(errno));
Branch: 1 branch
BranchTrueFalseTotal
if (RETVAL < 0) croak("eventfd: %s", strerror(errno)); 0 2 2
742 OUTPUT:
743 RETVAL
744  
745 void
746 eventfd_set(self, fd)
747 SV *self
748 int fd
749 PREINIT:
750 1 ▶ EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 1 0 1
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 0 1 1
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 0 1 1
751 CODE:
752 1 ▶ if (h->notify_fd >= 0 && h->notify_fd != fd) close(h->notify_fd);
Branch: 2 branches
BranchTrueFalseTotal
if (h->notify_fd >= 0 && h->notify_fd != fd) close(h->notify_fd); 1 0 1
if (h->notify_fd >= 0 && h->notify_fd != fd) close(h->notify_fd); 1 0 1
753 1 h->notify_fd = fd;
754  
755 IV
756 fileno(self)
757 SV *self
758 PREINIT:
759 3 ▶ EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 3 0 3
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 0 3 3
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 0 3 3
760 CODE:
761 3 ▶ RETVAL = h->notify_fd;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = h->notify_fd; 3 0 3
762 OUTPUT:
763 RETVAL
764  
765 bool
766 notify(self)
767 SV *self
768 PREINIT:
769 2 ▶ EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 2 0 2
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 0 2 2
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 0 2 2
770 CODE:
771 2 ▶ RETVAL = sync_notify(h);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = sync_notify(h); 2 0 2
772 OUTPUT:
773 RETVAL
774  
775 SV *
776 eventfd_consume(self)
777 SV *self
778 PREINIT:
779 2 ▶ EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 2 0 2
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 0 2 2
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 0 2 2
780 CODE:
781 2 int64_t v = sync_eventfd_consume(h);
782 2 ▶ RETVAL = (v >= 0) ? newSViv((IV)v) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (v >= 0) ? newSViv((IV)v) : &PL_sv_undef; 1 1 2
783 OUTPUT:
784 RETVAL
785  
786 void
787 sync(self)
788 SV *self
789 PREINIT:
790 0 ▶ EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 0 0 0
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 0 0 0
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 0 0 0
791 CODE:
792 0 ▶ if (sync_msync(h) != 0) croak("msync: %s", strerror(errno));
Branch: 1 branch
BranchTrueFalseTotal
if (sync_msync(h) != 0) croak("msync: %s", strerror(errno)); 0 0 0
793  
794 void
795 unlink(self_or_class, ...)
796 SV *self_or_class
797 CODE:
798 const char *p;
799 1 ▶ if (sv_isobject(self_or_class) && sv_derived_from(self_or_class, "Data::Sync::Shared::RWLock")) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv_isobject(self_or_class) && sv_derived_from(self_or_class, "Data::Sync::Shared::RWLock")) { 1 0 1
if (sv_isobject(self_or_class) && sv_derived_from(self_or_class, "Data::Sync::Shared::RWLock")) { 1 0 1
800 1 SyncHandle *h = INT2PTR(SyncHandle*, SvIV(SvRV(self_or_class)));
801 1 ▶ if (!h) croak("Attempted to use a destroyed object");
Branch: 1 branch
BranchTrueFalseTotal
if (!h) croak("Attempted to use a destroyed object"); 0 1 1
802 1 p = h->path;
803 } else {
804 0 ▶ if (items < 2) croak("Usage: ...->unlink($path)");
Branch: 1 branch
BranchTrueFalseTotal
if (items < 2) croak("Usage: ...->unlink($path)"); 0 0 0
805 0 p = SvPV_nolen(ST(1));
806 }
807 1 ▶ if (!p) croak("cannot unlink anonymous or memfd object");
Branch: 1 branch
BranchTrueFalseTotal
if (!p) croak("cannot unlink anonymous or memfd object"); 0 1 1
808 1 ▶ if (unlink(p) != 0 && errno != ENOENT)
Branch: 2 branches
BranchTrueFalseTotal
if (unlink(p) != 0 && errno != ENOENT) 0 1 1
if (unlink(p) != 0 && errno != ENOENT) 0 0 0
809 0 croak("unlink(%s): %s", p, strerror(errno));
810  
811 SV *
812 stats(self)
813 SV *self
814 PREINIT:
815 13 ▶ EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 13 0 13
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 0 13 13
EXTRACT_HANDLE("Data::Sync::Shared::RWLock", self); 0 13 13
816 CODE:
817 13 HV *hv = newHV();
818 13 SyncHeader *hdr = h->hdr;
819 13 uint32_t val = __atomic_load_n(&hdr->value, __ATOMIC_RELAXED);
820 const char *state;
821 13 UV readers = 0;
822 13 ▶ if (val >= SYNC_RWLOCK_WRITER_BIT) {
Branch: 1 branch
BranchTrueFalseTotal
if (val >= SYNC_RWLOCK_WRITER_BIT) { 3 10 13
823 3 state = "write_locked";
824 } else {
825 /* Reader-slots-only rwlock: the reader count is NOT stored in `value`
826 * (which is now the writer word only). Derive it by summing each
827 * process's rdepth across the shared reader-slot table, plus the
828 * slotless residual. Best-effort snapshot (taken without the lock);
829 * a not-yet-reclaimed dead reader may transiently inflate it. */
830 10 ▶ if (h->reader_slots) {
Branch: 1 branch
BranchTrueFalseTotal
if (h->reader_slots) { 10 0 10
831 10250 ▶ for (uint32_t i = 0; i < SYNC_READER_SLOTS; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (uint32_t i = 0; i < SYNC_READER_SLOTS; i++) { 10240 10 10250
832 10240 ▶ if (__atomic_load_n(&h->reader_slots[i].pid, __ATOMIC_ACQUIRE) == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (__atomic_load_n(&h->reader_slots[i].pid, __ATOMIC_ACQUIRE) == 0) 10230 10 10240
833 10230 continue;
834 10 readers += __atomic_load_n(&h->reader_slots[i].rdepth, __ATOMIC_RELAXED);
835 }
836 }
837 10 readers += (UV)__atomic_load_n(&hdr->slotless_rdepth, __ATOMIC_RELAXED);
838 10 ▶ state = readers > 0 ? "read_locked" : "unlocked";
Branch: 1 branch
BranchTrueFalseTotal
state = readers > 0 ? "read_locked" : "unlocked"; 5 5 10
839 }
840 13 hv_store(hv, "state", 5, newSVpv(state, 0), 0);
841 13 hv_store(hv, "readers", 7, newSVuv(readers), 0);
842 13 hv_store(hv, "waiters", 7, newSVuv((UV)__atomic_load_n(&hdr->waiters, __ATOMIC_RELAXED)), 0);
843 13 hv_store(hv, "mmap_size", 9, newSVuv((UV)h->mmap_size), 0);
844 13 hv_store(hv, "acquires", 8, newSVuv((UV)__atomic_load_n(&hdr->stat_acquires, __ATOMIC_RELAXED)), 0);
845 13 hv_store(hv, "releases", 8, newSVuv((UV)__atomic_load_n(&hdr->stat_releases, __ATOMIC_RELAXED)), 0);
846 13 hv_store(hv, "recoveries", 10, newSVuv((UV)__atomic_load_n(&hdr->stat_recoveries, __ATOMIC_RELAXED)), 0);
847 13 RETVAL = newRV_noinc((SV *)hv);
848 OUTPUT:
849 RETVAL
850  
851 MODULE = Data::Sync::Shared PACKAGE = Data::Sync::Shared::Condvar
852  
853 PROTOTYPES: DISABLE
854  
855 SV *
856 new(class, path, ...)
857 const char *class
858 SV *path
859 PREINIT:
860 char errbuf[SYNC_ERR_BUFLEN];
861 CODE:
862 14 ▶ mode_t mode = (items > 2 && (SvGETMAGIC(ST(2)), SvOK(ST(2)))) ? (mode_t)SvUV(ST(2)) : 0600;
Branch: 4 branches
BranchTrueFalseTotal
mode_t mode = (items > 2 && (SvGETMAGIC(ST(2)), SvOK(ST(2)))) ? (mode_t)SvUV(ST(2)) : 0600; 0 14 14
mode_t mode = (items > 2 && (SvGETMAGIC(ST(2)), SvOK(ST(2)))) ? (mode_t)SvUV(ST(2)) : 0600; 0 0 0
mode_t mode = (items > 2 && (SvGETMAGIC(ST(2)), SvOK(ST(2)))) ? (mode_t)SvUV(ST(2)) : 0600; 0 0 0
mode_t mode = (items > 2 && (SvGETMAGIC(ST(2)), SvOK(ST(2)))) ? (mode_t)SvUV(ST(2)) : 0600; 0 0 0
863 16 ▶ const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL;
Branch: 3 branches
BranchTrueFalseTotal
const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL; 0 14 14
const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL; 0 0 0
const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL; 2 12 14
864 14 SyncHandle *h = sync_create(p, SYNC_TYPE_CONDVAR, 0, 0, mode, errbuf);
865 14 ▶ if (!h) croak("Data::Sync::Shared::Condvar->new: %s", errbuf[0] ? errbuf : "out of memory");
Branch: 2 branches
BranchTrueFalseTotal
if (!h) croak("Data::Sync::Shared::Condvar->new: %s", errbuf[0] ? errbuf : "out of memory"); 0 14 14
if (!h) croak("Data::Sync::Shared::Condvar->new: %s", errbuf[0] ? errbuf : "out of memory"); 0 0 0
866 14 MAKE_OBJ(class, h);
867 OUTPUT:
868 RETVAL
869  
870 SV *
871 new_memfd(class, name)
872 const char *class
873 const char *name
874 PREINIT:
875 char errbuf[SYNC_ERR_BUFLEN];
876 CODE:
877 1 SyncHandle *h = sync_create_memfd(name, SYNC_TYPE_CONDVAR, 0, 0, errbuf);
878 1 ▶ if (!h) croak("Data::Sync::Shared::Condvar->new_memfd: %s", errbuf[0] ? errbuf : "out of memory");
Branch: 2 branches
BranchTrueFalseTotal
if (!h) croak("Data::Sync::Shared::Condvar->new_memfd: %s", errbuf[0] ? errbuf : "out of memory"); 0 1 1
if (!h) croak("Data::Sync::Shared::Condvar->new_memfd: %s", errbuf[0] ? errbuf : "out of memory"); 0 0 0
879 1 MAKE_OBJ(class, h);
880 OUTPUT:
881 RETVAL
882  
883 SV *
884 new_from_fd(class, fd)
885 const char *class
886 int fd
887 PREINIT:
888 char errbuf[SYNC_ERR_BUFLEN];
889 CODE:
890 0 SyncHandle *h = sync_open_fd(fd, SYNC_TYPE_CONDVAR, errbuf);
891 0 ▶ if (!h) croak("Data::Sync::Shared::Condvar->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory");
Branch: 2 branches
BranchTrueFalseTotal
if (!h) croak("Data::Sync::Shared::Condvar->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory"); 0 0 0
if (!h) croak("Data::Sync::Shared::Condvar->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory"); 0 0 0
892 0 MAKE_OBJ(class, h);
893 OUTPUT:
894 RETVAL
895  
896 void
897 DESTROY(self)
898 SV *self
899 CODE:
900 15 ▶ if (!sv_isobject(self) || !sv_derived_from(self, "Data::Sync::Shared::Condvar")) return;
Branch: 2 branches
BranchTrueFalseTotal
if (!sv_isobject(self) || !sv_derived_from(self, "Data::Sync::Shared::Condvar")) return; 15 0 15
if (!sv_isobject(self) || !sv_derived_from(self, "Data::Sync::Shared::Condvar")) return; 0 15 15
901 15 SyncHandle *h = INT2PTR(SyncHandle*, SvIV(SvRV(self)));
902 15 ▶ if (!h) return;
Branch: 1 branch
BranchTrueFalseTotal
if (!h) return; 0 15 15
903 15 sv_setiv(SvRV(self), 0);
904 15 sync_destroy(h);
905  
906 void
907 lock(self)
908 SV *self
909 PREINIT:
910 13 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 13 0 13
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 0 13 13
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 0 13 13
911 CODE:
912 13 sync_condvar_lock(h);
913  
914 bool
915 try_lock(self)
916 SV *self
917 PREINIT:
918 1 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 1 0 1
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 0 1 1
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 0 1 1
919 CODE:
920 1 ▶ RETVAL = sync_condvar_try_lock(h);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = sync_condvar_try_lock(h); 1 0 1
921 OUTPUT:
922 RETVAL
923  
924 void
925 unlock(self)
926 SV *self
927 PREINIT:
928 14 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 14 0 14
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 0 14 14
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 0 14 14
929 CODE:
930 14 sync_condvar_unlock(h);
931  
932 bool
933 wait(self, ...)
934 SV *self
935 PREINIT:
936 5 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 5 0 5
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 0 5 5
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 0 5 5
937 5 double timeout = -1;
938 CODE:
939 5 ▶ if (items > 1 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) timeout = SvNV(ST(1));
Branch: 4 branches
BranchTrueFalseTotal
if (items > 1 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) timeout = SvNV(ST(1)); 5 0 5
if (items > 1 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) timeout = SvNV(ST(1)); 0 5 5
if (items > 1 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) timeout = SvNV(ST(1)); 0 0 0
if (items > 1 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) timeout = SvNV(ST(1)); 5 0 5
940 5 ▶ REEXTRACT(self);
Branch: 2 branches
BranchTrueFalseTotal
REEXTRACT(self); 0 5 5
REEXTRACT(self); 0 5 5
941 5 ▶ RETVAL = sync_condvar_wait(h, timeout);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = sync_condvar_wait(h, timeout); 1 4 5
942 OUTPUT:
943 RETVAL
944  
945 void
946 signal(self)
947 SV *self
948 PREINIT:
949 1 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 1 0 1
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 0 1 1
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 0 1 1
950 CODE:
951 1 sync_condvar_signal(h);
952  
953 void
954 broadcast(self)
955 SV *self
956 PREINIT:
957 1 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 1 0 1
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 0 1 1
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 0 1 1
958 CODE:
959 1 sync_condvar_broadcast(h);
960  
961 SV *
962 path(self)
963 SV *self
964 PREINIT:
965 2 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 2 0 2
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 0 2 2
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 0 2 2
966 CODE:
967 2 ▶ RETVAL = h->path ? newSVpv(h->path, 0) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = h->path ? newSVpv(h->path, 0) : &PL_sv_undef; 1 1 2
968 OUTPUT:
969 RETVAL
970  
971 IV
972 memfd(self)
973 SV *self
974 PREINIT:
975 1 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 1 0 1
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 0 1 1
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 0 1 1
976 CODE:
977 1 ▶ RETVAL = h->backing_fd;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = h->backing_fd; 0 1 1
978 OUTPUT:
979 RETVAL
980  
981 IV
982 eventfd(self)
983 SV *self
984 PREINIT:
985 2 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 2 0 2
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 0 2 2
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 0 2 2
986 CODE:
987 2 RETVAL = sync_create_eventfd(h);
988 2 ▶ if (RETVAL < 0) croak("eventfd: %s", strerror(errno));
Branch: 1 branch
BranchTrueFalseTotal
if (RETVAL < 0) croak("eventfd: %s", strerror(errno)); 0 2 2
989 OUTPUT:
990 RETVAL
991  
992 void
993 eventfd_set(self, fd)
994 SV *self
995 int fd
996 PREINIT:
997 1 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 1 0 1
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 0 1 1
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 0 1 1
998 CODE:
999 1 ▶ if (h->notify_fd >= 0 && h->notify_fd != fd) close(h->notify_fd);
Branch: 2 branches
BranchTrueFalseTotal
if (h->notify_fd >= 0 && h->notify_fd != fd) close(h->notify_fd); 1 0 1
if (h->notify_fd >= 0 && h->notify_fd != fd) close(h->notify_fd); 1 0 1
1000 1 h->notify_fd = fd;
1001  
1002 IV
1003 fileno(self)
1004 SV *self
1005 PREINIT:
1006 3 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 3 0 3
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 0 3 3
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 0 3 3
1007 CODE:
1008 3 ▶ RETVAL = h->notify_fd;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = h->notify_fd; 3 0 3
1009 OUTPUT:
1010 RETVAL
1011  
1012 bool
1013 notify(self)
1014 SV *self
1015 PREINIT:
1016 2 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 2 0 2
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 0 2 2
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 0 2 2
1017 CODE:
1018 2 ▶ RETVAL = sync_notify(h);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = sync_notify(h); 2 0 2
1019 OUTPUT:
1020 RETVAL
1021  
1022 SV *
1023 eventfd_consume(self)
1024 SV *self
1025 PREINIT:
1026 2 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 2 0 2
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 0 2 2
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 0 2 2
1027 CODE:
1028 2 int64_t v = sync_eventfd_consume(h);
1029 2 ▶ RETVAL = (v >= 0) ? newSViv((IV)v) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (v >= 0) ? newSViv((IV)v) : &PL_sv_undef; 1 1 2
1030 OUTPUT:
1031 RETVAL
1032  
1033 void
1034 sync(self)
1035 SV *self
1036 PREINIT:
1037 0 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 0 0 0
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 0 0 0
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 0 0 0
1038 CODE:
1039 0 ▶ if (sync_msync(h) != 0) croak("msync: %s", strerror(errno));
Branch: 1 branch
BranchTrueFalseTotal
if (sync_msync(h) != 0) croak("msync: %s", strerror(errno)); 0 0 0
1040  
1041 void
1042 unlink(self_or_class, ...)
1043 SV *self_or_class
1044 CODE:
1045 const char *p;
1046 1 ▶ if (sv_isobject(self_or_class) && sv_derived_from(self_or_class, "Data::Sync::Shared::Condvar")) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv_isobject(self_or_class) && sv_derived_from(self_or_class, "Data::Sync::Shared::Condvar")) { 1 0 1
if (sv_isobject(self_or_class) && sv_derived_from(self_or_class, "Data::Sync::Shared::Condvar")) { 1 0 1
1047 1 SyncHandle *h = INT2PTR(SyncHandle*, SvIV(SvRV(self_or_class)));
1048 1 ▶ if (!h) croak("Attempted to use a destroyed object");
Branch: 1 branch
BranchTrueFalseTotal
if (!h) croak("Attempted to use a destroyed object"); 0 1 1
1049 1 p = h->path;
1050 } else {
1051 0 ▶ if (items < 2) croak("Usage: ...->unlink($path)");
Branch: 1 branch
BranchTrueFalseTotal
if (items < 2) croak("Usage: ...->unlink($path)"); 0 0 0
1052 0 p = SvPV_nolen(ST(1));
1053 }
1054 1 ▶ if (!p) croak("cannot unlink anonymous or memfd object");
Branch: 1 branch
BranchTrueFalseTotal
if (!p) croak("cannot unlink anonymous or memfd object"); 0 1 1
1055 1 ▶ if (unlink(p) != 0 && errno != ENOENT)
Branch: 2 branches
BranchTrueFalseTotal
if (unlink(p) != 0 && errno != ENOENT) 0 1 1
if (unlink(p) != 0 && errno != ENOENT) 0 0 0
1056 0 croak("unlink(%s): %s", p, strerror(errno));
1057  
1058 SV *
1059 stats(self)
1060 SV *self
1061 PREINIT:
1062 1 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 1 0 1
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 0 1 1
EXTRACT_HANDLE("Data::Sync::Shared::Condvar", self); 0 1 1
1063 CODE:
1064 1 HV *hv = newHV();
1065 1 SyncHeader *hdr = h->hdr;
1066 1 hv_store(hv, "waiters", 7, newSVuv((UV)__atomic_load_n(&hdr->waiters, __ATOMIC_RELAXED)), 0);
1067 1 hv_store(hv, "signals", 7, newSVuv((UV)__atomic_load_n(&hdr->stat_signals, __ATOMIC_RELAXED)), 0);
1068 1 hv_store(hv, "mmap_size", 9, newSVuv((UV)h->mmap_size), 0);
1069 1 hv_store(hv, "acquires", 8, newSVuv((UV)__atomic_load_n(&hdr->stat_acquires, __ATOMIC_RELAXED)), 0);
1070 1 hv_store(hv, "releases", 8, newSVuv((UV)__atomic_load_n(&hdr->stat_releases, __ATOMIC_RELAXED)), 0);
1071 1 hv_store(hv, "waits", 5, newSVuv((UV)__atomic_load_n(&hdr->stat_waits, __ATOMIC_RELAXED)), 0);
1072 1 hv_store(hv, "timeouts", 8, newSVuv((UV)__atomic_load_n(&hdr->stat_timeouts, __ATOMIC_RELAXED)), 0);
1073 1 hv_store(hv, "recoveries", 10, newSVuv((UV)__atomic_load_n(&hdr->stat_recoveries, __ATOMIC_RELAXED)), 0);
1074 1 RETVAL = newRV_noinc((SV *)hv);
1075 OUTPUT:
1076 RETVAL
1077  
1078 MODULE = Data::Sync::Shared PACKAGE = Data::Sync::Shared::Once
1079  
1080 PROTOTYPES: DISABLE
1081  
1082 SV *
1083 new(class, path, ...)
1084 const char *class
1085 SV *path
1086 PREINIT:
1087 char errbuf[SYNC_ERR_BUFLEN];
1088 CODE:
1089 9 ▶ mode_t mode = (items > 2 && (SvGETMAGIC(ST(2)), SvOK(ST(2)))) ? (mode_t)SvUV(ST(2)) : 0600;
Branch: 4 branches
BranchTrueFalseTotal
mode_t mode = (items > 2 && (SvGETMAGIC(ST(2)), SvOK(ST(2)))) ? (mode_t)SvUV(ST(2)) : 0600; 0 9 9
mode_t mode = (items > 2 && (SvGETMAGIC(ST(2)), SvOK(ST(2)))) ? (mode_t)SvUV(ST(2)) : 0600; 0 0 0
mode_t mode = (items > 2 && (SvGETMAGIC(ST(2)), SvOK(ST(2)))) ? (mode_t)SvUV(ST(2)) : 0600; 0 0 0
mode_t mode = (items > 2 && (SvGETMAGIC(ST(2)), SvOK(ST(2)))) ? (mode_t)SvUV(ST(2)) : 0600; 0 0 0
1090 12 ▶ const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL;
Branch: 3 branches
BranchTrueFalseTotal
const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL; 0 9 9
const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL; 0 0 0
const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL; 3 6 9
1091 9 SyncHandle *h = sync_create(p, SYNC_TYPE_ONCE, 0, 0, mode, errbuf);
1092 9 ▶ if (!h) croak("Data::Sync::Shared::Once->new: %s", errbuf[0] ? errbuf : "out of memory");
Branch: 2 branches
BranchTrueFalseTotal
if (!h) croak("Data::Sync::Shared::Once->new: %s", errbuf[0] ? errbuf : "out of memory"); 1 8 9
if (!h) croak("Data::Sync::Shared::Once->new: %s", errbuf[0] ? errbuf : "out of memory"); 1 0 1
1093 8 MAKE_OBJ(class, h);
1094 OUTPUT:
1095 RETVAL
1096  
1097 SV *
1098 new_memfd(class, name)
1099 const char *class
1100 const char *name
1101 PREINIT:
1102 char errbuf[SYNC_ERR_BUFLEN];
1103 CODE:
1104 1 SyncHandle *h = sync_create_memfd(name, SYNC_TYPE_ONCE, 0, 0, errbuf);
1105 1 ▶ if (!h) croak("Data::Sync::Shared::Once->new_memfd: %s", errbuf[0] ? errbuf : "out of memory");
Branch: 2 branches
BranchTrueFalseTotal
if (!h) croak("Data::Sync::Shared::Once->new_memfd: %s", errbuf[0] ? errbuf : "out of memory"); 0 1 1
if (!h) croak("Data::Sync::Shared::Once->new_memfd: %s", errbuf[0] ? errbuf : "out of memory"); 0 0 0
1106 1 MAKE_OBJ(class, h);
1107 OUTPUT:
1108 RETVAL
1109  
1110 SV *
1111 new_from_fd(class, fd)
1112 const char *class
1113 int fd
1114 PREINIT:
1115 char errbuf[SYNC_ERR_BUFLEN];
1116 CODE:
1117 1 SyncHandle *h = sync_open_fd(fd, SYNC_TYPE_ONCE, errbuf);
1118 1 ▶ if (!h) croak("Data::Sync::Shared::Once->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory");
Branch: 2 branches
BranchTrueFalseTotal
if (!h) croak("Data::Sync::Shared::Once->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory"); 0 1 1
if (!h) croak("Data::Sync::Shared::Once->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory"); 0 0 0
1119 1 MAKE_OBJ(class, h);
1120 OUTPUT:
1121 RETVAL
1122  
1123 void
1124 DESTROY(self)
1125 SV *self
1126 CODE:
1127 10 ▶ if (!sv_isobject(self) || !sv_derived_from(self, "Data::Sync::Shared::Once")) return;
Branch: 2 branches
BranchTrueFalseTotal
if (!sv_isobject(self) || !sv_derived_from(self, "Data::Sync::Shared::Once")) return; 10 0 10
if (!sv_isobject(self) || !sv_derived_from(self, "Data::Sync::Shared::Once")) return; 0 10 10
1128 10 SyncHandle *h = INT2PTR(SyncHandle*, SvIV(SvRV(self)));
1129 10 ▶ if (!h) return;
Branch: 1 branch
BranchTrueFalseTotal
if (!h) return; 0 10 10
1130 10 sv_setiv(SvRV(self), 0);
1131 10 sync_destroy(h);
1132  
1133 bool
1134 enter(self, ...)
1135 SV *self
1136 PREINIT:
1137 6 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Once", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 6 0 6
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 0 6 6
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 0 6 6
1138 6 double timeout = -1;
1139 CODE:
1140 6 ▶ if (items > 1 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) timeout = SvNV(ST(1));
Branch: 4 branches
BranchTrueFalseTotal
if (items > 1 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) timeout = SvNV(ST(1)); 3 3 6
if (items > 1 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) timeout = SvNV(ST(1)); 0 3 3
if (items > 1 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) timeout = SvNV(ST(1)); 0 0 0
if (items > 1 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) timeout = SvNV(ST(1)); 3 0 3
1141 6 ▶ REEXTRACT(self);
Branch: 2 branches
BranchTrueFalseTotal
REEXTRACT(self); 0 6 6
REEXTRACT(self); 0 6 6
1142 6 ▶ RETVAL = sync_once_enter(h, timeout);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = sync_once_enter(h, timeout); 4 2 6
1143 OUTPUT:
1144 RETVAL
1145  
1146 void
1147 done(self)
1148 SV *self
1149 PREINIT:
1150 4 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Once", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 4 0 4
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 0 4 4
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 0 4 4
1151 CODE:
1152 4 sync_once_done(h);
1153  
1154 bool
1155 is_done(self)
1156 SV *self
1157 PREINIT:
1158 8 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Once", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 8 0 8
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 0 8 8
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 0 8 8
1159 CODE:
1160 8 ▶ RETVAL = sync_once_is_done(h);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = sync_once_is_done(h); 4 4 8
1161 OUTPUT:
1162 RETVAL
1163  
1164 void
1165 reset(self)
1166 SV *self
1167 PREINIT:
1168 2 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Once", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 2 0 2
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 0 2 2
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 0 2 2
1169 CODE:
1170 2 sync_once_reset(h);
1171  
1172 SV *
1173 path(self)
1174 SV *self
1175 PREINIT:
1176 2 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Once", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 2 0 2
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 0 2 2
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 0 2 2
1177 CODE:
1178 2 ▶ RETVAL = h->path ? newSVpv(h->path, 0) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = h->path ? newSVpv(h->path, 0) : &PL_sv_undef; 1 1 2
1179 OUTPUT:
1180 RETVAL
1181  
1182 IV
1183 memfd(self)
1184 SV *self
1185 PREINIT:
1186 2 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Once", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 2 0 2
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 0 2 2
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 0 2 2
1187 CODE:
1188 2 ▶ RETVAL = h->backing_fd;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = h->backing_fd; 0 2 2
1189 OUTPUT:
1190 RETVAL
1191  
1192 IV
1193 eventfd(self)
1194 SV *self
1195 PREINIT:
1196 2 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Once", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 2 0 2
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 0 2 2
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 0 2 2
1197 CODE:
1198 2 RETVAL = sync_create_eventfd(h);
1199 2 ▶ if (RETVAL < 0) croak("eventfd: %s", strerror(errno));
Branch: 1 branch
BranchTrueFalseTotal
if (RETVAL < 0) croak("eventfd: %s", strerror(errno)); 0 2 2
1200 OUTPUT:
1201 RETVAL
1202  
1203 void
1204 eventfd_set(self, fd)
1205 SV *self
1206 int fd
1207 PREINIT:
1208 1 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Once", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 1 0 1
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 0 1 1
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 0 1 1
1209 CODE:
1210 1 ▶ if (h->notify_fd >= 0 && h->notify_fd != fd) close(h->notify_fd);
Branch: 2 branches
BranchTrueFalseTotal
if (h->notify_fd >= 0 && h->notify_fd != fd) close(h->notify_fd); 1 0 1
if (h->notify_fd >= 0 && h->notify_fd != fd) close(h->notify_fd); 1 0 1
1211 1 h->notify_fd = fd;
1212  
1213 IV
1214 fileno(self)
1215 SV *self
1216 PREINIT:
1217 3 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Once", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 3 0 3
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 0 3 3
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 0 3 3
1218 CODE:
1219 3 ▶ RETVAL = h->notify_fd;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = h->notify_fd; 3 0 3
1220 OUTPUT:
1221 RETVAL
1222  
1223 bool
1224 notify(self)
1225 SV *self
1226 PREINIT:
1227 2 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Once", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 2 0 2
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 0 2 2
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 0 2 2
1228 CODE:
1229 2 ▶ RETVAL = sync_notify(h);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = sync_notify(h); 2 0 2
1230 OUTPUT:
1231 RETVAL
1232  
1233 SV *
1234 eventfd_consume(self)
1235 SV *self
1236 PREINIT:
1237 2 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Once", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 2 0 2
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 0 2 2
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 0 2 2
1238 CODE:
1239 2 int64_t v = sync_eventfd_consume(h);
1240 2 ▶ RETVAL = (v >= 0) ? newSViv((IV)v) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (v >= 0) ? newSViv((IV)v) : &PL_sv_undef; 1 1 2
1241 OUTPUT:
1242 RETVAL
1243  
1244 void
1245 sync(self)
1246 SV *self
1247 PREINIT:
1248 0 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Once", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 0 0 0
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 0 0 0
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 0 0 0
1249 CODE:
1250 0 ▶ if (sync_msync(h) != 0) croak("msync: %s", strerror(errno));
Branch: 1 branch
BranchTrueFalseTotal
if (sync_msync(h) != 0) croak("msync: %s", strerror(errno)); 0 0 0
1251  
1252 void
1253 unlink(self_or_class, ...)
1254 SV *self_or_class
1255 CODE:
1256 const char *p;
1257 1 ▶ if (sv_isobject(self_or_class) && sv_derived_from(self_or_class, "Data::Sync::Shared::Once")) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv_isobject(self_or_class) && sv_derived_from(self_or_class, "Data::Sync::Shared::Once")) { 1 0 1
if (sv_isobject(self_or_class) && sv_derived_from(self_or_class, "Data::Sync::Shared::Once")) { 1 0 1
1258 1 SyncHandle *h = INT2PTR(SyncHandle*, SvIV(SvRV(self_or_class)));
1259 1 ▶ if (!h) croak("Attempted to use a destroyed object");
Branch: 1 branch
BranchTrueFalseTotal
if (!h) croak("Attempted to use a destroyed object"); 0 1 1
1260 1 p = h->path;
1261 } else {
1262 0 ▶ if (items < 2) croak("Usage: ...->unlink($path)");
Branch: 1 branch
BranchTrueFalseTotal
if (items < 2) croak("Usage: ...->unlink($path)"); 0 0 0
1263 0 p = SvPV_nolen(ST(1));
1264 }
1265 1 ▶ if (!p) croak("cannot unlink anonymous or memfd object");
Branch: 1 branch
BranchTrueFalseTotal
if (!p) croak("cannot unlink anonymous or memfd object"); 0 1 1
1266 1 ▶ if (unlink(p) != 0 && errno != ENOENT)
Branch: 2 branches
BranchTrueFalseTotal
if (unlink(p) != 0 && errno != ENOENT) 0 1 1
if (unlink(p) != 0 && errno != ENOENT) 0 0 0
1267 0 croak("unlink(%s): %s", p, strerror(errno));
1268  
1269 SV *
1270 stats(self)
1271 SV *self
1272 PREINIT:
1273 2 ▶ EXTRACT_HANDLE("Data::Sync::Shared::Once", self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 2 0 2
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 0 2 2
EXTRACT_HANDLE("Data::Sync::Shared::Once", self); 0 2 2
1274 CODE:
1275 2 HV *hv = newHV();
1276 2 SyncHeader *hdr = h->hdr;
1277 const char *state;
1278 2 uint32_t val = __atomic_load_n(&hdr->value, __ATOMIC_RELAXED);
1279 2 ▶ if (val == SYNC_ONCE_INIT) state = "init";
Branch: 1 branch
BranchTrueFalseTotal
if (val == SYNC_ONCE_INIT) state = "init"; 1 1 2
1280 1 ▶ else if (val == SYNC_ONCE_DONE) state = "done";
Branch: 1 branch
BranchTrueFalseTotal
else if (val == SYNC_ONCE_DONE) state = "done"; 1 0 1
1281 0 else state = "running";
1282 2 hv_store(hv, "state", 5, newSVpv(state, 0), 0);
1283 2 hv_store(hv, "is_done", 7, newSVuv(val == SYNC_ONCE_DONE), 0);
1284 2 hv_store(hv, "waiters", 7, newSVuv((UV)__atomic_load_n(&hdr->waiters, __ATOMIC_RELAXED)), 0);
1285 2 hv_store(hv, "mmap_size", 9, newSVuv((UV)h->mmap_size), 0);
1286 2 hv_store(hv, "acquires", 8, newSVuv((UV)__atomic_load_n(&hdr->stat_acquires, __ATOMIC_RELAXED)), 0);
1287 2 hv_store(hv, "releases", 8, newSVuv((UV)__atomic_load_n(&hdr->stat_releases, __ATOMIC_RELAXED)), 0);
1288 2 hv_store(hv, "waits", 5, newSVuv((UV)__atomic_load_n(&hdr->stat_waits, __ATOMIC_RELAXED)), 0);
1289 2 hv_store(hv, "timeouts", 8, newSVuv((UV)__atomic_load_n(&hdr->stat_timeouts, __ATOMIC_RELAXED)), 0);
1290 2 hv_store(hv, "recoveries", 10, newSVuv((UV)__atomic_load_n(&hdr->stat_recoveries, __ATOMIC_RELAXED)), 0);
1291 2 RETVAL = newRV_noinc((SV *)hv);
1292 OUTPUT:
1293 RETVAL
« blib/lib/Data/Sync/Shared/RWLock.pm ↑ Summary sync.h »