summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gui/embedded/qlock.cpp19
-rw-r--r--src/gui/embedded/qwslock.cpp17
-rw-r--r--src/gui/embedded/qwssignalhandler.cpp50
-rw-r--r--src/gui/embedded/qwssignalhandler_p.h22
4 files changed, 54 insertions, 54 deletions
diff --git a/src/gui/embedded/qlock.cpp b/src/gui/embedded/qlock.cpp
index ae18b05..ac15431 100644
--- a/src/gui/embedded/qlock.cpp
+++ b/src/gui/embedded/qlock.cpp
@@ -169,10 +169,6 @@ QLock::QLock(const QString &filename, char id, bool create)
data->id = semget(semkey, 1, IPC_CREAT | 0600);
arg.val = MAX_LOCKS;
semctl(data->id, 0, SETVAL, arg);
-
-#ifndef QT_NO_QWS_SIGNALHANDLER
- QWSSignalHandler::instance()->addSemaphore(data->id);
-#endif
}
#endif
if (!isValid()) {
@@ -180,6 +176,10 @@ QLock::QLock(const QString &filename, char id, bool create)
(create ? "create" : "get"), qPrintable(filename), id,
errno, strerror(errno));
}
+
+#ifndef QT_NO_QWS_SIGNALHANDLER
+ QWSSignalHandler::instance()->addLock(this);
+#endif
}
/*!
@@ -187,6 +187,10 @@ QLock::QLock(const QString &filename, char id, bool create)
*/
QLock::~QLock()
{
+#ifndef QT_NO_QWS_SIGNALHANDLER
+ QWSSignalHandler::instance()->removeLock(this);
+#endif
+
while (locked())
unlock();
#ifdef Q_NO_SEMAPHORE
@@ -200,13 +204,10 @@ QLock::~QLock()
qt_semun semval;
semval.val = 0;
semctl(data->id, 0, IPC_RMID, semval);
-
-#ifndef QT_NO_QWS_SIGNALHANDLER
- QWSSignalHandler::instance()->removeSemaphore(data->id);
-#endif
#endif
}
delete data;
+ data = 0;
}
/*!
@@ -215,7 +216,7 @@ QLock::~QLock()
*/
bool QLock::isValid() const
{
- return (data->id != -1);
+ return data && data->id != -1;
}
/*!
diff --git a/src/gui/embedded/qwslock.cpp b/src/gui/embedded/qwslock.cpp
index 67f8bd8..c14f50b 100644
--- a/src/gui/embedded/qwslock.cpp
+++ b/src/gui/embedded/qwslock.cpp
@@ -70,6 +70,10 @@ QWSLock::QWSLock(int id) : semId(id)
{
static unsigned short initialValues[3] = { 1, 1, 0 };
+#ifndef QT_NO_QWS_SIGNALHANDLER
+ QWSSignalHandler::instance()->addWSLock(this);
+#endif
+
if (semId == -1) {
semId = semget(IPC_PRIVATE, 3, IPC_CREAT | 0666);
if (semId == -1) {
@@ -86,22 +90,19 @@ QWSLock::QWSLock(int id) : semId(id)
}
lockCount[0] = lockCount[1] = 0;
-
-#ifndef QT_NO_QWS_SIGNALHANDLER
- QWSSignalHandler::instance()->addSemaphore(semId);
-#endif
}
QWSLock::~QWSLock()
{
- if (semId != -1) {
#ifndef QT_NO_QWS_SIGNALHANDLER
- QWSSignalHandler::instance()->removeSemaphore(semId);
-#else
+ QWSSignalHandler::instance()->removeWSLock(this);
+#endif
+
+ if (semId != -1) {
qt_semun semval;
semval.val = 0;
semctl(semId, 0, IPC_RMID, semval);
-#endif
+ semId = -1;
}
}
diff --git a/src/gui/embedded/qwssignalhandler.cpp b/src/gui/embedded/qwssignalhandler.cpp
index 2a20141..b13a57d 100644
--- a/src/gui/embedded/qwssignalhandler.cpp
+++ b/src/gui/embedded/qwssignalhandler.cpp
@@ -43,13 +43,10 @@
#ifndef QT_NO_QWS_SIGNALHANDLER
-#include <sys/types.h>
-#ifndef QT_NO_QWS_MULTIPROCESS
-# include <sys/ipc.h>
-# include <sys/sem.h>
+#include "qlock_p.h"
+#include "qwslock_p.h"
-# include <private/qcore_unix_p.h>
-#endif
+#include <sys/types.h>
#include <signal.h>
QT_BEGIN_NAMESPACE
@@ -87,39 +84,30 @@ QWSSignalHandler::QWSSignalHandler()
QWSSignalHandler::~QWSSignalHandler()
{
-#ifndef QT_NO_QWS_MULTIPROCESS
- while (!semaphores.isEmpty())
- removeSemaphore(semaphores.last());
-#endif
+ clear();
}
-#ifndef QT_NO_QWS_MULTIPROCESS
-void QWSSignalHandler::removeSemaphore(int semno)
+void QWSSignalHandler::clear()
{
- const int index = semaphores.lastIndexOf(semno);
- if (index != -1) {
- qt_semun semval;
- semval.val = 0;
- semctl(semaphores.at(index), 0, IPC_RMID, semval);
- semaphores.remove(index);
- }
+#if !defined(QT_NO_QWS_MULTIPROCESS)
+ // it is safe to call d-tors directly here since, on normal exit,
+ // lists should be empty; otherwise, we don't care about semi-alive objects
+ // and the only important thing here is to unregister the system semaphores.
+ while (!locks.isEmpty())
+ locks.takeLast()->~QLock();
+ while (!wslocks.isEmpty())
+ wslocks.takeLast()->~QWSLock();
+#endif
+ objects.clear();
}
-#endif // QT_NO_QWS_MULTIPROCESS
void QWSSignalHandler::handleSignal(int signum)
{
QWSSignalHandler *h = instance();
-
- signal(signum, h->oldHandlers[signum]);
-
-#ifndef QT_NO_QWS_MULTIPROCESS
- qt_semun semval;
- semval.val = 0;
- for (int i = 0; i < h->semaphores.size(); ++i)
- semctl(h->semaphores.at(i), 0, IPC_RMID, semval);
-#endif
-
- h->objects.clear();
+ if (h) {
+ signal(signum, h->oldHandlers[signum]);
+ h->clear();
+ }
raise(signum);
}
diff --git a/src/gui/embedded/qwssignalhandler_p.h b/src/gui/embedded/qwssignalhandler_p.h
index dda9c76..217eda1 100644
--- a/src/gui/embedded/qwssignalhandler_p.h
+++ b/src/gui/embedded/qwssignalhandler_p.h
@@ -57,14 +57,17 @@
#ifndef QT_NO_QWS_SIGNALHANDLER
-#include <QtCore/qmap.h>
-#include <QtCore/qvector.h>
+#include <QtCore/qhash.h>
+#include <QtCore/qlist.h>
#include <QtCore/qobjectcleanuphandler.h>
QT_BEGIN_NAMESPACE
typedef void (*qt_sighandler_t)(int);
+class QLock;
+class QWSLock;
+
class QWSSignalHandlerPrivate;
class Q_GUI_EXPORT QWSSignalHandler
@@ -75,17 +78,24 @@ public:
~QWSSignalHandler();
#ifndef QT_NO_QWS_MULTIPROCESS
- inline void addSemaphore(int semno) { semaphores.append(semno); }
- void removeSemaphore(int semno);
+ inline void addLock(QLock *lock) { locks.append(lock); }
+ inline void removeLock(QLock *lock) { locks.removeOne(lock); }
+ inline void addWSLock(QWSLock *wslock) { wslocks.append(wslock); }
+ inline void removeWSLock(QWSLock *wslock) { wslocks.removeOne(wslock); }
#endif
inline void addObject(QObject *object) { (void)objects.add(object); }
private:
QWSSignalHandler();
+
+ void clear();
+
static void handleSignal(int signal);
- QMap<int, qt_sighandler_t> oldHandlers;
+
+ QHash<int, qt_sighandler_t> oldHandlers;
#ifndef QT_NO_QWS_MULTIPROCESS
- QVector<int> semaphores;
+ QList<QLock *> locks;
+ QList<QWSLock *> wslocks;
#endif
QObjectCleanupHandler objects;