14#if QT_CONFIG(posix_sem)
21# include "private/qcore_unix_p.h"
23# define QT_EINTR_LOOP_VAL(var, val, cmd) \
25# define QT_EINTR_LOOP(var, cmd) QT_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)
53 if (semName.isEmpty()) {
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#if defined(Q_OS_VXWORKS)
130 if (errno == EINVAL) {
131 semaphore = SEM_FAILED;
132 return modifySemaphore(self, cnt);
135 self->setUnixErrorString(
"QSystemSemaphore::modifySemaphore (sem_post)"_L1);
136#if defined QSYSTEMSEMAPHORE_DEBUG
137 qDebug(
"QSystemSemaphorePosix::modify sem_post failed %d %d",
count, errno);
140 for ( ; cnt <
count; ++cnt) {
153 if (errno == EINVAL || errno == EIDRM) {
154 semaphore = SEM_FAILED;
155 return modifySemaphore(self,
count);
157 self->setUnixErrorString(
"QSystemSemaphore::modifySemaphore (sem_wait)"_L1);
158#if defined QSYSTEMSEMAPHORE_DEBUG
159 qDebug(
"QSystemSemaphorePosix::modify sem_wait failed %d %d",
count, errno);
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 QT_EINTR_LOOP(var, cmd)
GLuint64 GLenum void * handle
GLenum GLenum GLsizei count