fix cleanup of QWinIoCompletionPort
The QWinIoCompletionPort thread was never properly cleaned up. Maintain a reference count for QWinIoCompletionPort and create/destroy it on demand. Change-Id: I607b574484554dd3ad107dfb43b0a248bcf8b7a4 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
This commit is contained in:
parent
76dfe82add
commit
40c9a3ef11
@ -161,12 +161,20 @@ private:
|
|||||||
QMutex mutex;
|
QMutex mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_GLOBAL_STATIC(QWinIoCompletionPort, iocp)
|
QWinIoCompletionPort *QWinOverlappedIoNotifier::iocp = 0;
|
||||||
|
HANDLE QWinOverlappedIoNotifier::iocpInstanceLock = CreateMutex(NULL, FALSE, NULL);
|
||||||
|
unsigned int QWinOverlappedIoNotifier::iocpInstanceRefCount = 0;
|
||||||
|
|
||||||
QWinOverlappedIoNotifier::QWinOverlappedIoNotifier(QObject *parent)
|
QWinOverlappedIoNotifier::QWinOverlappedIoNotifier(QObject *parent)
|
||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
hHandle(INVALID_HANDLE_VALUE)
|
hHandle(INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
|
WaitForSingleObject(iocpInstanceLock, INFINITE);
|
||||||
|
if (!iocp)
|
||||||
|
iocp = new QWinIoCompletionPort;
|
||||||
|
iocpInstanceRefCount++;
|
||||||
|
ReleaseMutex(iocpInstanceLock);
|
||||||
|
|
||||||
hSemaphore = CreateSemaphore(NULL, 0, 255, NULL);
|
hSemaphore = CreateSemaphore(NULL, 0, 255, NULL);
|
||||||
hResultsMutex = CreateMutex(NULL, FALSE, NULL);
|
hResultsMutex = CreateMutex(NULL, FALSE, NULL);
|
||||||
connect(this, &QWinOverlappedIoNotifier::_q_notify,
|
connect(this, &QWinOverlappedIoNotifier::_q_notify,
|
||||||
@ -178,6 +186,13 @@ QWinOverlappedIoNotifier::~QWinOverlappedIoNotifier()
|
|||||||
setEnabled(false);
|
setEnabled(false);
|
||||||
CloseHandle(hResultsMutex);
|
CloseHandle(hResultsMutex);
|
||||||
CloseHandle(hSemaphore);
|
CloseHandle(hSemaphore);
|
||||||
|
|
||||||
|
WaitForSingleObject(iocpInstanceLock, INFINITE);
|
||||||
|
if (!--iocpInstanceRefCount) {
|
||||||
|
delete iocp;
|
||||||
|
iocp = 0;
|
||||||
|
}
|
||||||
|
ReleaseMutex(iocpInstanceLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QWinOverlappedIoNotifier::setHandle(HANDLE h)
|
void QWinOverlappedIoNotifier::setHandle(HANDLE h)
|
||||||
@ -188,9 +203,9 @@ void QWinOverlappedIoNotifier::setHandle(HANDLE h)
|
|||||||
void QWinOverlappedIoNotifier::setEnabled(bool enabled)
|
void QWinOverlappedIoNotifier::setEnabled(bool enabled)
|
||||||
{
|
{
|
||||||
if (enabled)
|
if (enabled)
|
||||||
iocp()->registerNotifier(this);
|
iocp->registerNotifier(this);
|
||||||
else
|
else
|
||||||
iocp()->unregisterNotifier(this);
|
iocp->unregisterNotifier(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -61,6 +61,8 @@ QT_BEGIN_HEADER
|
|||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
class QWinIoCompletionPort;
|
||||||
|
|
||||||
class Q_CORE_EXPORT QWinOverlappedIoNotifier : public QObject
|
class Q_CORE_EXPORT QWinOverlappedIoNotifier : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -85,6 +87,9 @@ private:
|
|||||||
void notify(DWORD numberOfBytes, DWORD errorCode, OVERLAPPED *overlapped);
|
void notify(DWORD numberOfBytes, DWORD errorCode, OVERLAPPED *overlapped);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static QWinIoCompletionPort *iocp;
|
||||||
|
static HANDLE iocpInstanceLock;
|
||||||
|
static unsigned int iocpInstanceRefCount;
|
||||||
HANDLE hHandle;
|
HANDLE hHandle;
|
||||||
HANDLE hSemaphore;
|
HANDLE hSemaphore;
|
||||||
HANDLE hResultsMutex;
|
HANDLE hResultsMutex;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user