kernel/qsystemsemaphore_unix.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6 -
7 -
8 -
9 -
10 -
11 -
12 -
13 -
14 -
15 -
16 -
17 -
18QSystemSemaphorePrivate::QSystemSemaphorePrivate() : -
19 semaphore(-1), createdFile(false), -
20 createdSemaphore(false), unix_key(-1), error(QSystemSemaphore::NoError) -
21{ -
22}
executed: }
Execution Count:47
47
23 -
24void QSystemSemaphorePrivate::setErrorString(const QString &function) -
25{ -
26 -
27 switch ((*__errno_location ())) { -
28 case 1: -
29 case 13: -
30 errorString = QCoreApplication::translate("QSystemSemaphore", "%1: permission denied").arg(function); -
31 error = QSystemSemaphore::PermissionDenied; -
32 break;
never executed: break;
0
33 case 17: -
34 errorString = QCoreApplication::translate("QSystemSemaphore", "%1: already exists").arg(function); -
35 error = QSystemSemaphore::AlreadyExists; -
36 break;
never executed: break;
0
37 case 2: -
38 errorString = QCoreApplication::translate("QSystemSemaphore", "%1: does not exist").arg(function); -
39 error = QSystemSemaphore::NotFound; -
40 break;
never executed: break;
0
41 case 34: -
42 case 28: -
43 errorString = QCoreApplication::translate("QSystemSemaphore", "%1: out of resources").arg(function); -
44 error = QSystemSemaphore::OutOfResources; -
45 break;
never executed: break;
0
46 default: -
47 errorString = QCoreApplication::translate("QSystemSemaphore", "%1: unknown error %2").arg(function).arg((*__errno_location ())); -
48 error = QSystemSemaphore::UnknownError; -
49 -
50 -
51 -
52 }
never executed: }
0
53}
never executed: }
0
54 -
55 -
56 -
57 -
58 -
59 -
60key_t QSystemSemaphorePrivate::handle(QSystemSemaphore::AccessMode mode) -
61{ -
62 if (key.isEmpty()){
partially evaluated: key.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:56
0-56
63 errorString = QCoreApplication::tr("%1: key is empty", "QSystemSemaphore").arg(QLatin1String("QSystemSemaphore::handle:")); -
64 error = QSystemSemaphore::KeyError; -
65 return -1;
never executed: return -1;
0
66 } -
67 -
68 -
69 if (-1 != unix_key)
evaluated: -1 != unix_key
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:46
10-46
70 return unix_key;
executed: return unix_key;
Execution Count:10
10
71 -
72 -
73 int built = QSharedMemoryPrivate::createUnixKeyFile(fileName); -
74 if (-1 == built) {
partially evaluated: -1 == built
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:46
0-46
75 errorString = QCoreApplication::tr("%1: unable to make key", "QSystemSemaphore").arg(QLatin1String("QSystemSemaphore::handle:")); -
76 error = QSystemSemaphore::KeyError; -
77 return -1;
never executed: return -1;
0
78 } -
79 createdFile = (1 == built); -
80 -
81 -
82 unix_key = ftok(QFile::encodeName(fileName).constData(), 'Q'); -
83 if (-1 == unix_key) {
partially evaluated: -1 == unix_key
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:46
0-46
84 errorString = QCoreApplication::tr("%1: ftok failed", "QSystemSemaphore").arg(QLatin1String("QSystemSemaphore::handle:")); -
85 error = QSystemSemaphore::KeyError; -
86 return -1;
never executed: return -1;
0
87 } -
88 -
89 -
90 semaphore = semget(unix_key, 1, 0600 | 01000 | 02000); -
91 if (-1 == semaphore) {
partially evaluated: -1 == semaphore
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:46
0-46
92 if ((*__errno_location ()) == 17)
never evaluated: (*__errno_location ()) == 17
0
93 semaphore = semget(unix_key, 1, 0600 | 01000);
never executed: semaphore = semget(unix_key, 1, 0600 | 01000);
0
94 if (-1 == semaphore) {
never evaluated: -1 == semaphore
0
95 setErrorString(QLatin1String("QSystemSemaphore::handle")); -
96 cleanHandle(); -
97 return -1;
never executed: return -1;
0
98 } -
99 } else {
never executed: }
0
100 createdSemaphore = true; -
101 -
102 createdFile = true; -
103 }
executed: }
Execution Count:46
46
104 -
105 if (mode == QSystemSemaphore::Create) {
evaluated: mode == QSystemSemaphore::Create
TRUEFALSE
yes
Evaluation Count:43
yes
Evaluation Count:3
3-43
106 createdSemaphore = true; -
107 createdFile = true; -
108 }
executed: }
Execution Count:43
43
109 -
110 -
111 if (createdSemaphore && initialValue >= 0) {
partially evaluated: createdSemaphore
TRUEFALSE
yes
Evaluation Count:46
no
Evaluation Count:0
partially evaluated: initialValue >= 0
TRUEFALSE
yes
Evaluation Count:46
no
Evaluation Count:0
0-46
112 qt_semun init_op; -
113 init_op.val = initialValue; -
114 if (-1 == semctl(semaphore, 0, 16, init_op)) {
partially evaluated: -1 == semctl(semaphore, 0, 16, init_op)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:46
0-46
115 setErrorString(QLatin1String("QSystemSemaphore::handle")); -
116 cleanHandle(); -
117 return -1;
never executed: return -1;
0
118 } -
119 }
executed: }
Execution Count:46
46
120 -
121 return unix_key;
executed: return unix_key;
Execution Count:46
46
122} -
123 -
124 -
125 -
126 -
127 -
128 -
129void QSystemSemaphorePrivate::cleanHandle() -
130{ -
131 unix_key = -1; -
132 -
133 -
134 if (createdFile) {
evaluated: createdFile
TRUEFALSE
yes
Evaluation Count:46
yes
Evaluation Count:47
46-47
135 QFile::remove(fileName); -
136 createdFile = false; -
137 }
executed: }
Execution Count:46
46
138 -
139 if (createdSemaphore) {
evaluated: createdSemaphore
TRUEFALSE
yes
Evaluation Count:46
yes
Evaluation Count:47
46-47
140 if (-1 != semaphore) {
partially evaluated: -1 != semaphore
TRUEFALSE
yes
Evaluation Count:46
no
Evaluation Count:0
0-46
141 if (-1 == semctl(semaphore, 0, 0, 0)) {
partially evaluated: -1 == semctl(semaphore, 0, 0, 0)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:46
0-46
142 setErrorString(QLatin1String("QSystemSemaphore::cleanHandle")); -
143 -
144 -
145 -
146 }
never executed: }
0
147 semaphore = -1; -
148 }
executed: }
Execution Count:46
46
149 createdSemaphore = false; -
150 }
executed: }
Execution Count:46
46
151}
executed: }
Execution Count:93
93
152 -
153 -
154 -
155 -
156bool QSystemSemaphorePrivate::modifySemaphore(int count) -
157{ -
158 if (-1 == handle())
partially evaluated: -1 == handle()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10
0-10
159 return false;
never executed: return false;
0
160 -
161 struct sembuf operation; -
162 operation.sem_num = 0; -
163 operation.sem_op = count; -
164 operation.sem_flg = 0x1000; -
165 -
166 register int res; -
167 do { res = semop(semaphore, &operation, 1); } while (res == -1 && (*__errno_location ()) == 4);
executed: }
Execution Count:10
partially evaluated: res == -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10
never evaluated: (*__errno_location ()) == 4
0-10
168 if (-1 == res) {
partially evaluated: -1 == res
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10
0-10
169 -
170 if ((*__errno_location ()) == 22 || (*__errno_location ()) == 43) {
never evaluated: (*__errno_location ()) == 22
never evaluated: (*__errno_location ()) == 43
0
171 semaphore = -1; -
172 cleanHandle(); -
173 handle(); -
174 return modifySemaphore(count);
never executed: return modifySemaphore(count);
0
175 } -
176 setErrorString(QLatin1String("QSystemSemaphore::modifySemaphore")); -
177 -
178 -
179 -
180 return false;
never executed: return false;
0
181 } -
182 -
183 return true;
executed: return true;
Execution Count:10
10
184} -
185 -
186 -
187 -
188 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial