8#if QT_CONFIG(systemsemaphore)
9#include <QtCore/q20memory.h>
14using namespace QtIpcCommon;
15using namespace Qt::StringLiterals;
17inline void QSystemSemaphorePrivate::constructBackend()
19 visit([](
auto p) { q20::construct_at(p); });
22inline void QSystemSemaphorePrivate::destructBackend()
24 visit([](
auto p) { std::destroy_at(p); });
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
74
75
76QSystemSemaphore::QSystemSemaphore(
const QString &key,
int initialValue, AccessMode mode)
77 : QSystemSemaphore(legacyNativeKey(key), initialValue, mode)
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117QSystemSemaphore::QSystemSemaphore(
const QNativeIpcKey &key,
int initialValue, AccessMode mode)
118 : d(
new QSystemSemaphorePrivate(key.type()))
120 setNativeKey(key, initialValue, mode);
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138QSystemSemaphore::~QSystemSemaphore()
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
168
169
170
171
172
173
174
175
176
177
178
179
180void QSystemSemaphore::setNativeKey(
const QNativeIpcKey &key,
int initialValue, AccessMode mode)
182 if (key == d->nativeKey && mode == Open)
184 if (!isKeyTypeSupported(key.type())) {
185 d->setError(KeyError, tr(
"%1: unsupported key type")
186 .arg(
"QSystemSemaphore::setNativeKey"_L1));
192 if (key.type() == d->nativeKey.type()) {
197 d->destructBackend();
199 d->constructBackend();
201 d->initialValue = initialValue;
206
207
208
209
210
211
212
213
214
215QNativeIpcKey QSystemSemaphore::nativeIpcKey()
const
221
222
223
224
225
226
227
228
229
230void QSystemSemaphore::setKey(
const QString &key,
int initialValue, AccessMode mode)
232 setNativeKey(legacyNativeKey(key), initialValue, mode);
236
237
238
239
240
241QString QSystemSemaphore::key()
const
243 return QNativeIpcKeyPrivate::legacyKey(d->nativeKey);
247
248
249
250
251
252
253
254
255
256
257
258
259bool QSystemSemaphore::acquire()
261 return d->modifySemaphore(-1);
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285bool QSystemSemaphore::release(
int n)
290 qWarning(
"QSystemSemaphore::release: n is negative.");
293 return d->modifySemaphore(n);
297
298
299
300
301
302QSystemSemaphore::SystemSemaphoreError QSystemSemaphore::error()
const
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
330
331
332
333
334
335
336
337QString QSystemSemaphore::errorString()
const
339 return d->errorString;
342void QSystemSemaphorePrivate::setUnixErrorString(QLatin1StringView function)
348 errorString = QSystemSemaphore::tr(
"%1: permission denied").arg(function);
349 error = QSystemSemaphore::PermissionDenied;
352 errorString = QSystemSemaphore::tr(
"%1: already exists").arg(function);
353 error = QSystemSemaphore::AlreadyExists;
356 errorString = QSystemSemaphore::tr(
"%1: does not exist").arg(function);
357 error = QSystemSemaphore::NotFound;
362 errorString = QSystemSemaphore::tr(
"%1: out of resources").arg(function);
363 error = QSystemSemaphore::OutOfResources;
366 errorString = QSystemSemaphore::tr(
"%1: key too long").arg(function);
367 error = QSystemSemaphore::KeyError;
370 errorString = QSystemSemaphore::tr(
"%1: unknown error: %2")
371 .arg(function, qt_error_string(errno));
372 error = QSystemSemaphore::UnknownError;
373#if defined QSYSTEMSEMAPHORE_DEBUG
374 qDebug() << errorString <<
"key" << key <<
"errno" << errno << EINVAL;
379bool QSystemSemaphore::isKeyTypeSupported(QNativeIpcKey::Type type)
381 if (!isIpcSupported(IpcType::SystemSemaphore, type))
383 using Variant =
decltype(QSystemSemaphorePrivate::backend);
384 return Variant::staticVisit(type, [](
auto ptr) {
385 using Impl = std::decay_t<
decltype(*ptr)>;
386 return Impl::runtimeSupportCheck();
390QNativeIpcKey QSystemSemaphore::platformSafeKey(
const QString &key, QNativeIpcKey::Type type)
392 return QtIpcCommon::platformSafeKey(key, IpcType::SystemSemaphore, type);
395QNativeIpcKey QSystemSemaphore::legacyNativeKey(
const QString &key, QNativeIpcKey::Type type)
397 return QtIpcCommon::legacyPlatformSafeKey(key, IpcType::SystemSemaphore, type);
402#include "moc_qsystemsemaphore.cpp"