44 #ifndef QT_NO_QWS_MULTIPROCESS 52 #include <sys/types.h> 60 #include <linux/version.h> 64 #include <private/qcore_unix_p.h> 68 #ifdef QT_NO_SEMAPHORE 69 #error QWSLock currently requires semaphores 73 #include <QtCore/QAtomicInt> 80 static unsigned short initialValues[3] = { 1, 1, 0 };
82 #ifndef QT_NO_QWS_SIGNALHANDLER 88 semId = semget(IPC_PRIVATE, 3, IPC_CREAT | 0666);
90 perror(
"QWSLock::QWSLock");
91 qFatal(
"Unable to create semaphore");
95 semval.
array = initialValues;
96 if (semctl(
semId, 0, SETALL, semval) == -1) {
97 perror(
"QWSLock::QWSLock");
98 qFatal(
"Unable to initialize semaphores");
102 sems[0] = sems[1] = sems[2] = SEM_FAILED;
107 semId = (getpid() << 16) + (localUniqueId.fetchAndAddRelaxed(1) %
ushort(-1));
112 QByteArray keys[3] = { pfx +
"BackingStore", pfx +
"Communication", pfx +
"RegionEvent" };
113 for (
int i = 0; i < 3; ++i) {
115 sem_unlink(keys[i].constData());
117 sems[i] = sem_open(keys[i].constData(), (owned ?
O_CREAT : 0), 0666, initialValues[i]);
118 }
while (sems[i] == SEM_FAILED &&
errno == EINTR);
119 if (sems[i] == SEM_FAILED) {
120 perror(
"QWSLock::QWSLock");
121 qFatal(
"Unable to %s semaphore", (owned ?
"create" :
"open"));
131 #ifndef QT_NO_QWS_SIGNALHANDLER 139 semctl(
semId, 0, IPC_RMID, semval);
147 QByteArray keys[3] = { pfx +
"BackingStore", pfx +
"Communication", pfx +
"RegionEvent" };
148 for (
int i = 0; i < 3; ++i) {
149 if (sems[i] != SEM_FAILED) {
151 sems[i] = SEM_FAILED;
154 sem_unlink(keys[i].constData());
165 sembuf sops = { semNum, 1, 0 };
171 sops.sem_flg |= SEM_UNDO;
175 ret = sem_post(sems[semNum]);
190 sembuf sops = { semNum, -1, 0 };
196 sops.sem_flg |= SEM_UNDO;
214 ret = semctl(
semId, semNum, GETVAL, 0);
216 if (sem_getvalue(sems[semNum], &ret) == -1)
220 qDebug(
"QWSLock::getValue(): %s", strerror(
errno));
234 if (
down(type, timeout)) {
268 bool ok =
down(type, timeout);
276 #endif // QT_NO_QWS_MULTIPROCESS
#define QT_END_NAMESPACE
This macro expands to.
bool wait(LockType type, int timeout=-1)
#define EINTR_LOOP(var, cmd)
The QByteArray class provides an array of bytes.
void removeWSLock(QWSLock *wslock)
bool down(unsigned short semNum, int timeout)
#define Q_BASIC_ATOMIC_INITIALIZER(a)
void unlock(LockType type)
static QWSSignalHandler * instance()
Q_CORE_EXPORT void qDebug(const char *,...)
bool hasLock(LockType type)
#define QT_BEGIN_NAMESPACE
This macro expands to.
int getValue(unsigned short semNum) const
bool up(unsigned short semNum)
Q_CORE_EXPORT void qFatal(const char *,...)
void addWSLock(QWSLock *wslock)
bool lock(LockType type, int timeout=-1)
static QByteArray number(int, int base=10)
Returns a byte array containing the string equivalent of the number n to base base (10 by default)...