44 #ifdef QT_NO_QWS_MULTIPROCESS 82 #else // QT_NO_QWS_MULTIPROCESS 84 #if defined(Q_OS_DARWIN) 85 # define QT_NO_SEMAPHORE 91 #include <sys/types.h> 93 #if defined(QT_NO_SEMAPHORE) 94 # include <sys/stat.h> 95 # include <sys/file.h> 96 #elif !defined(QT_POSIX_IPC) 99 # include <semaphore.h> 104 #include <private/qcore_unix_p.h> 108 #define MAX_LOCKS 200 // maximum simultaneous read locks 113 #if defined(QT_NO_SEMAPHORE) || defined(QT_POSIX_IPC) 116 #if !defined(QT_POSIX_IPC) 162 #if defined(QT_NO_SEMAPHORE) 164 for (
int x = 0; x < 2; ++x) {
166 if (
data->id != -1 || !create) {
171 #elif !defined(QT_POSIX_IPC) 173 data->id = semget(semkey, 0, 0);
179 semctl(
data->id, 0, IPC_RMID, arg);
180 data->id = semget(semkey, 1, IPC_CREAT | 0600);
182 semctl(
data->id, 0, SETVAL, arg);
188 char ids[3] = {
'c',
'r',
'w' };
189 sem_t **sems[3] = { &
data->id, &
data->rsem, &
data->wsem };
190 unsigned short initialValues[3] = {
MAX_LOCKS, 1, 1 };
191 for (
int i = 0; i < 3; ++i) {
194 *sems[i] = sem_open(file.
constData(), 0, 0666, 0);
195 }
while (*sems[i] == SEM_FAILED &&
errno == EINTR);
197 if (*sems[i] != SEM_FAILED) {
203 }
while (*sems[i] == SEM_FAILED &&
errno == EINTR);
208 qWarning(
"QLock::QLock: Cannot %s semaphore %s '%c' (%d, %s)",
209 (create ?
"create" :
"get"),
qPrintable(filename),
id,
213 #ifndef QT_NO_QWS_SIGNALHANDLER 223 #ifndef QT_NO_QWS_SIGNALHANDLER 230 #if defined(QT_NO_SEMAPHORE) 233 #elif defined(QT_POSIX_IPC) 234 if (
data->id != SEM_FAILED)
236 if (
data->rsem != SEM_FAILED)
237 sem_close(
data->rsem);
238 if (
data->wsem != SEM_FAILED)
239 sem_close(
data->wsem);
243 #if defined(QT_NO_SEMAPHORE) 244 unlink(
data->file.constData());
245 #elif !defined(QT_POSIX_IPC) 248 semctl(
data->id, 0, IPC_RMID, semval);
250 char ids[3] = {
'c',
'r',
'w' };
251 for (
int i = 0; i < 3; ++i) {
267 #if !defined(QT_POSIX_IPC) 270 return data &&
data->id != SEM_FAILED &&
data->rsem != SEM_FAILED &&
data->wsem != SEM_FAILED;
294 #if defined(QT_NO_SEMAPHORE) 295 int op =
type == Write ? LOCK_EX : LOCK_SH;
298 #elif !defined(QT_POSIX_IPC) 302 sops.sem_flg = SEM_UNDO;
311 sem_post(
data->rsem);
317 if (rv != -1 ||
errno == EAGAIN) {
321 sem_getvalue(
data->id, &semval);
323 sem_post(
data->rsem);
326 rv = sem_post(
data->wsem);
334 }
else if (
type == Read && t == Write) {
335 qDebug(
"QLock::lock(): Attempt to lock for write while locked for read");
350 if (
data->count > 0) {
354 #if defined(QT_NO_SEMAPHORE) 356 #elif !defined(QT_POSIX_IPC) 360 sops.sem_flg = SEM_UNDO;
365 sem_post(
data->wsem);
366 rv = sem_post(
data->rsem);
372 sem_getvalue(
data->id, &semval);
374 sem_post(
data->rsem);
375 rv = sem_post(
data->wsem);
383 qDebug(
"QLock::unlock(): Unlock without corresponding lock");
393 return isValid() &&
data->count > 0;
398 #endif // QT_NO_QWS_MULTIPROCESS
#define QT_END_NAMESPACE
This macro expands to.
#define EINTR_LOOP(var, cmd)
The QByteArray class provides an array of bytes.
static Expression::Ptr create(Expression *const expr, const YYLTYPE &sourceLocator, const ParserContext *const parseInfo)
The QString class provides a Unicode character string.
void unlock()
Unlocks the semaphore.
static QWSSignalHandler * instance()
Q_CORE_EXPORT void qDebug(const char *,...)
bool locked() const
Returns true if the lock is currently held by the current process; otherwise returns false...
#define QT_BEGIN_NAMESPACE
This macro expands to.
Q_CORE_EXPORT void qWarning(const char *,...)
void lock(Type type)
Locks the semaphore with a lock of type t.
static const char * data(const QByteArray &arr)
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
const char * constData() const
Returns a pointer to the data stored in the byte array.
bool isValid() const
Returns true if the lock constructor was successful; returns false if the lock could not be created o...
void removeLock(QLock *lock)
QLock(const QString &filename, char id, bool create=false)
Creates a lock.
#define qPrintable(string)
void addLock(QLock *lock)