7#if QT_CONFIG(systemsemaphore)
8#include <QtCore/q20memory.h>
13using namespace QtIpcCommon;
14using namespace Qt::StringLiterals;
16inline void QSystemSemaphorePrivate::constructBackend()
18 visit([](
auto p) { q20::construct_at(p); });
21inline void QSystemSemaphorePrivate::destructBackend()
23 visit([](
auto p) { std::destroy_at(p); });
27
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
73
74
75QSystemSemaphore::QSystemSemaphore(
const QString &key,
int initialValue, AccessMode mode)
76 : QSystemSemaphore(legacyNativeKey(key), initialValue, mode)
81
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
116QSystemSemaphore::QSystemSemaphore(
const QNativeIpcKey &key,
int initialValue, AccessMode mode)
117 : d(
new QSystemSemaphorePrivate(key.type()))
119 setNativeKey(key, initialValue, mode);
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137QSystemSemaphore::~QSystemSemaphore()
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
167
168
169
170
171
172
173
174
175
176
177
178
179void QSystemSemaphore::setNativeKey(
const QNativeIpcKey &key,
int initialValue, AccessMode mode)
181 if (key == d->nativeKey && mode == Open)
183 if (!isKeyTypeSupported(key.type())) {
184 d->setError(KeyError, tr(
"%1: unsupported key type")
185 .arg(
"QSystemSemaphore::setNativeKey"_L1));
191 if (key.type() == d->nativeKey.type()) {
196 d->destructBackend();
198 d->constructBackend();
200 d->initialValue = initialValue;
205
206
207
208
209
210
211
212
213
214QNativeIpcKey QSystemSemaphore::nativeIpcKey()
const
220
221
222
223
224
225
226
227
228
229void QSystemSemaphore::setKey(
const QString &key,
int initialValue, AccessMode mode)
231 setNativeKey(legacyNativeKey(key), initialValue, mode);
235
236
237
238
239
240QString QSystemSemaphore::key()
const
242 return QNativeIpcKeyPrivate::legacyKey(d->nativeKey);
246
247
248
249
250
251
252
253
254
255
256
257
258bool QSystemSemaphore::acquire()
260 return d->modifySemaphore(-1);
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284bool QSystemSemaphore::release(
int n)
289 qWarning(
"QSystemSemaphore::release: n is negative.");
292 return d->modifySemaphore(n);
296
297
298
299
300
301QSystemSemaphore::SystemSemaphoreError QSystemSemaphore::error()
const
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
329
330
331
332
333
334
335
336QString QSystemSemaphore::errorString()
const
338 return d->errorString;
341void QSystemSemaphorePrivate::setUnixErrorString(QLatin1StringView function)
347 errorString = QSystemSemaphore::tr(
"%1: permission denied").arg(function);
348 error = QSystemSemaphore::PermissionDenied;
351 errorString = QSystemSemaphore::tr(
"%1: already exists").arg(function);
352 error = QSystemSemaphore::AlreadyExists;
355 errorString = QSystemSemaphore::tr(
"%1: does not exist").arg(function);
356 error = QSystemSemaphore::NotFound;
361 errorString = QSystemSemaphore::tr(
"%1: out of resources").arg(function);
362 error = QSystemSemaphore::OutOfResources;
365 errorString = QSystemSemaphore::tr(
"%1: key too long").arg(function);
366 error = QSystemSemaphore::KeyError;
369 errorString = QSystemSemaphore::tr(
"%1: unknown error: %2")
370 .arg(function, qt_error_string(errno));
371 error = QSystemSemaphore::UnknownError;
372#if defined QSYSTEMSEMAPHORE_DEBUG
373 qDebug() << errorString <<
"key" << key <<
"errno" << errno << EINVAL;
378bool QSystemSemaphore::isKeyTypeSupported(QNativeIpcKey::Type type)
380 if (!isIpcSupported(IpcType::SystemSemaphore, type))
382 using Variant =
decltype(QSystemSemaphorePrivate::backend);
383 return Variant::staticVisit(type, [](
auto ptr) {
384 using Impl = std::decay_t<
decltype(*ptr)>;
385 return Impl::runtimeSupportCheck();
389QNativeIpcKey QSystemSemaphore::platformSafeKey(
const QString &key, QNativeIpcKey::Type type)
391 return QtIpcCommon::platformSafeKey(key, IpcType::SystemSemaphore, type);
394QNativeIpcKey QSystemSemaphore::legacyNativeKey(
const QString &key, QNativeIpcKey::Type type)
396 return QtIpcCommon::legacyPlatformSafeKey(key, IpcType::SystemSemaphore, type);
401#include "moc_qsystemsemaphore.cpp"