13using namespace Qt::StringLiterals;
15#if QT_CONFIG(systemsemaphore)
17void QSystemSemaphorePrivate::setWindowsErrorString(QLatin1StringView function)
19 BOOL windowsError = GetLastError();
20 if (windowsError == 0)
23 switch (windowsError) {
24 case ERROR_NO_SYSTEM_RESOURCES:
25 case ERROR_NOT_ENOUGH_MEMORY:
26 error = QSystemSemaphore::OutOfResources;
27 errorString = QCoreApplication::translate(
"QSystemSemaphore",
"%1: out of resources").arg(function);
29 case ERROR_ACCESS_DENIED:
30 error = QSystemSemaphore::PermissionDenied;
31 errorString = QCoreApplication::translate(
"QSystemSemaphore",
"%1: permission denied").arg(function);
34 errorString = QCoreApplication::translate(
"QSystemSemaphore",
"%1: unknown error: %2")
35 .arg(function, qt_error_string(windowsError));
36 error = QSystemSemaphore::UnknownError;
37#if defined QSYSTEMSEMAPHORE_DEBUG
38 qDebug() << errorString <<
"key" << key;
43HANDLE QSystemSemaphoreWin32::handle(QSystemSemaphorePrivate *self, QSystemSemaphore::AccessMode)
46 if (self->nativeKey.isEmpty())
51 semaphore = CreateSemaphore(0, self->initialValue, MAXLONG,
52 reinterpret_cast<
const wchar_t*>(self->nativeKey.nativeKey().utf16()));
53 if (semaphore == NULL)
54 self->setWindowsErrorString(
"QSystemSemaphore::handle"_L1);
60void QSystemSemaphoreWin32::cleanHandle(QSystemSemaphorePrivate *)
62 if (semaphore && !CloseHandle(semaphore)) {
63#if defined QSYSTEMSEMAPHORE_DEBUG
64 qDebug(
"QSystemSemaphoreWin32::CloseHandle: sem failed");
70bool QSystemSemaphoreWin32::modifySemaphore(QSystemSemaphorePrivate *self,
int count)
72 if (handle(self, QSystemSemaphore::Open) ==
nullptr)
76 if (0 == ReleaseSemaphore(semaphore, count, 0)) {
77 self->setWindowsErrorString(
"QSystemSemaphore::modifySemaphore"_L1);
78#if defined QSYSTEMSEMAPHORE_DEBUG
79 qDebug(
"QSystemSemaphore::modifySemaphore ReleaseSemaphore failed");
84 if (WAIT_OBJECT_0 != WaitForSingleObjectEx(semaphore, INFINITE, FALSE)) {
85 self->setWindowsErrorString(
"QSystemSemaphore::modifySemaphore"_L1);
86#if defined QSYSTEMSEMAPHORE_DEBUG
87 qDebug(
"QSystemSemaphore::modifySemaphore WaitForSingleObject failed");
Combined button and popup list for selecting options.