14#if QT_CONFIG(posix_sem)
21# include "private/qcore_unix_p.h"
23#define EINTR_LOOP_VAL(var, val, cmd) \
25#define EINTR_LOOP(var, cmd) EINTR_LOOP_VAL(var, -1, cmd)
30#if defined(Q_OS_OPENBSD) && !defined(EIDRM)
38bool QSystemSemaphorePosix::runtimeSupportCheck()
40 static const bool result = []() {
41 sem_open(
"/", 0, 0, 0);
42 return errno != ENOSYS;
47bool QSystemSemaphorePosix::handle(QSystemSemaphorePrivate *self, QSystemSemaphore::AccessMode
mode)
49 if (semaphore != SEM_FAILED)
54 self->setError(QSystemSemaphore::KeyError,
55 QSystemSemaphore::tr(
"%1: key is empty")
56 .
arg(
"QSystemSemaphore::handle"_L1));
61 int oflag = O_CREAT | O_EXCL;
62 for (
int tryNum = 0, maxTries = 1; tryNum < maxTries; ++tryNum) {
64 semaphore = ::sem_open(semName.
constData(), oflag, 0600,
self->initialValue);
65 }
while (semaphore == SEM_FAILED && errno == EINTR);
66 if (semaphore == SEM_FAILED && errno == EEXIST) {
67 if (
mode == QSystemSemaphore::Create) {
68 if (::sem_unlink(semName.
constData()) == -1 && errno != ENOENT) {
69 self->setUnixErrorString(
"QSystemSemaphore::handle (sem_unlink)"_L1);
86 if (semaphore == SEM_FAILED) {
87 self->setUnixErrorString(
"QSystemSemaphore::handle"_L1);
91 createdSemaphore = (oflag & O_EXCL) != 0;
96void QSystemSemaphorePosix::cleanHandle(QSystemSemaphorePrivate *self)
98 if (semaphore != SEM_FAILED) {
99 if (::sem_close(semaphore) == -1) {
100 self->setUnixErrorString(
"QSystemSemaphore::cleanHandle (sem_close)"_L1);
101#if defined QSYSTEMSEMAPHORE_DEBUG
102 qDebug(
"QSystemSemaphore::cleanHandle sem_close failed.");
105 semaphore = SEM_FAILED;
108 if (createdSemaphore) {
110 if (::sem_unlink(semName) == -1 && errno != ENOENT) {
111 self->setUnixErrorString(
"QSystemSemaphore::cleanHandle (sem_unlink)"_L1);
112#if defined QSYSTEMSEMAPHORE_DEBUG
113 qDebug(
"QSystemSemaphorePosix::cleanHandle sem_unlink failed.");
116 createdSemaphore =
false;
120bool QSystemSemaphorePosix::modifySemaphore(QSystemSemaphorePrivate *self,
int count)
122 if (!
handle(self, QSystemSemaphore::Open))
128 if (::sem_post(semaphore) == -1) {
129 self->setUnixErrorString(
"QSystemSemaphore::modifySemaphore (sem_post)"_L1);
130#if defined QSYSTEMSEMAPHORE_DEBUG
131 qDebug(
"QSystemSemaphorePosix::modify sem_post failed %d %d",
count, errno);
134 for ( ; cnt <
count; ++cnt) {
147 if (errno == EINVAL || errno == EIDRM) {
148 semaphore = SEM_FAILED;
149 return modifySemaphore(self,
count);
151 self->setUnixErrorString(
"QSystemSemaphore::modifySemaphore (sem_wait)"_L1);
152#if defined QSYSTEMSEMAPHORE_DEBUG
153 qDebug(
"QSystemSemaphorePosix::modify sem_wait failed %d %d",
count, errno);
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
bool isEmpty() const noexcept
Returns true if the byte array has size 0; otherwise returns false.
static QByteArray encodeName(const QString &fileName)
Converts fileName to an 8-bit encoding that you can use in native APIs.
Combined button and popup list for selecting options.
#define EINTR_LOOP(var, cmd)
GLuint64 GLenum void * handle
GLenum GLenum GLsizei count