12using namespace Qt::StringLiterals;
14#if QT_CONFIG(systemsemaphore)
16void QSystemSemaphorePrivate::setWindowsErrorString(QLatin1StringView function)
18 BOOL windowsError = GetLastError();
19 if (windowsError == 0)
22 switch (windowsError) {
23 case ERROR_NO_SYSTEM_RESOURCES:
24 case ERROR_NOT_ENOUGH_MEMORY:
25 error = QSystemSemaphore::OutOfResources;
26 errorString = QCoreApplication::translate(
"QSystemSemaphore",
"%1: out of resources").arg(function);
28 case ERROR_ACCESS_DENIED:
29 error = QSystemSemaphore::PermissionDenied;
30 errorString = QCoreApplication::translate(
"QSystemSemaphore",
"%1: permission denied").arg(function);
33 errorString = QCoreApplication::translate(
"QSystemSemaphore",
"%1: unknown error: %2")
34 .arg(function, qt_error_string(windowsError));
35 error = QSystemSemaphore::UnknownError;
36#if defined QSYSTEMSEMAPHORE_DEBUG
37 qDebug() << errorString <<
"key" << key;
42HANDLE QSystemSemaphoreWin32::handle(QSystemSemaphorePrivate *self, QSystemSemaphore::AccessMode)
45 if (self->nativeKey.isEmpty())
50 semaphore = CreateSemaphore(0, self->initialValue, MAXLONG,
51 reinterpret_cast<
const wchar_t*>(self->nativeKey.nativeKey().utf16()));
52 if (semaphore == NULL)
53 self->setWindowsErrorString(
"QSystemSemaphore::handle"_L1);
59void QSystemSemaphoreWin32::cleanHandle(QSystemSemaphorePrivate *)
61 if (semaphore && !CloseHandle(semaphore)) {
62#if defined QSYSTEMSEMAPHORE_DEBUG
63 qDebug(
"QSystemSemaphoreWin32::CloseHandle: sem failed");
69bool QSystemSemaphoreWin32::modifySemaphore(QSystemSemaphorePrivate *self,
int count)
71 if (handle(self, QSystemSemaphore::Open) ==
nullptr)
75 if (0 == ReleaseSemaphore(semaphore, count, 0)) {
76 self->setWindowsErrorString(
"QSystemSemaphore::modifySemaphore"_L1);
77#if defined QSYSTEMSEMAPHORE_DEBUG
78 qDebug(
"QSystemSemaphore::modifySemaphore ReleaseSemaphore failed");
83 if (WAIT_OBJECT_0 != WaitForSingleObjectEx(semaphore, INFINITE, FALSE)) {
84 self->setWindowsErrorString(
"QSystemSemaphore::modifySemaphore"_L1);
85#if defined QSYSTEMSEMAPHORE_DEBUG
86 qDebug(
"QSystemSemaphore::modifySemaphore WaitForSingleObject failed");
Combined button and popup list for selecting options.