lib/Global/MutexLock.xs

filter: Statementstmt 100% 29 / 29 Branchbran 92.8% 13 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 97.6% 42 / 43 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« builder/GMBuilder.pm ↑ Summary blib/lib/Global/MutexLock.pm »
1 #ifdef __cplusplus
2 extern "C" {
3 #endif
4  
5 #define PERL_NO_GET_CONTEXT /* we want efficiency */
6 #include <EXTERN.h>
7 #include <perl.h>
8 #include <XSUB.h>
9 #include <sys/shm.h>
10 #include <pthread.h>
11  
12 #ifdef __cplusplus
13 } /* extern "C" */
14 #endif
15  
16 #include "ppport.h"
17  
18 MODULE = Global::MutexLock PACKAGE = Global::MutexLock
19  
20 PROTOTYPES: DISABLE
21  
22 SV*
23 mutex_create()
24 PREINIT:
25 pthread_mutex_t *m;
26 pthread_mutexattr_t mat;
27 int shmid;
28 CODE:
29 3 shmid = shmget(IPC_PRIVATE, sizeof(pthread_mutex_t), 0666);
30 3 ▶ if (shmid >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (shmid >= 0) { 3 0 3
31 3 m = shmat(shmid, NULL, 0);
32 3 pthread_mutexattr_init(&mat);
33 3 pthread_mutexattr_setpshared(&mat, PTHREAD_PROCESS_SHARED);
34 3 pthread_mutex_init(m, &mat);
35 }
36 3 RETVAL = newSViv(shmid);
37 OUTPUT:
38 RETVAL
39  
40 SV*
41 mutex_lock(sv_shmid)
42 SV* sv_shmid;
43 PREINIT:
44 pthread_mutex_t *m;
45 int shmid;
46 CODE:
47 8 ▶ if (SvOK(sv_shmid)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(sv_shmid)) { 5 3 8
48 5 shmid = SvIV(sv_shmid);
49 5 m = (pthread_mutex_t*)shmat(shmid, NULL, 0);
50 5 ▶ if ((long)m != -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ((long)m != -1) { 3 2 5
51 3 pthread_mutex_lock(m);
52 3 RETVAL = newSViv(1);
53 } else {
54 2 RETVAL = &PL_sv_undef;
55 }
56 } else {
57 3 RETVAL = &PL_sv_undef;
58 }
59 OUTPUT:
60 RETVAL
61  
62 SV*
63 mutex_unlock(sv_shmid)
64 SV* sv_shmid;
65 PREINIT:
66 pthread_mutex_t *m;
67 int shmid;
68 CODE:
69 8 ▶ if (SvOK(sv_shmid)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(sv_shmid)) { 5 3 8
70 5 shmid = SvIV(sv_shmid);
71 5 m = (pthread_mutex_t*)shmat(shmid, NULL, 0);
72 5 ▶ if ((long)m != -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ((long)m != -1) { 3 2 5
73 3 pthread_mutex_unlock(m);
74 3 RETVAL = newSViv(1);
75 } else {
76 2 RETVAL = &PL_sv_undef;
77 }
78 } else {
79 3 RETVAL = &PL_sv_undef;
80 }
81 OUTPUT:
82 RETVAL
83  
84 SV*
85 mutex_destory(sv_shmid)
86 SV* sv_shmid;
87 PREINIT:
88 int shmid;
89 CODE:
90 8 ▶ if (SvOK(sv_shmid)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(sv_shmid)) { 5 3 8
91 5 shmid = SvIV(sv_shmid);
92 5 ▶ if (shmctl(shmid, IPC_RMID, NULL) != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (shmctl(shmid, IPC_RMID, NULL) != 0) { 2 3 5
93 2 RETVAL = &PL_sv_undef;
94 } else {
95 3 RETVAL = newSViv(1);
96 }
97 } else {
98 3 RETVAL = &PL_sv_undef;
99 }
100 OUTPUT:
101 RETVAL
« builder/GMBuilder.pm ↑ Summary blib/lib/Global/MutexLock.pm »