diff options
author | Morten Johan Sørvig <morten.sorvig@qt.io> | 2018-07-04 00:20:37 +0200 |
---|---|---|
committer | Morten Johan Sørvig <morten.sorvig@qt.io> | 2018-08-09 07:24:15 +0000 |
commit | a09c8b0ee6ddd13251ee1335ede73fd66e007a35 (patch) | |
tree | 9c7cb2af31892edc16b696c86bde948152b8cb2f /src/corelib/kernel/qcfsocketnotifier.cpp | |
parent | 489ae6db3c1d4c78b60f67d1c64e6bdb820560eb (diff) |
Make QEventDispatcherCoreFoundaton work on secondary threads
We were using CFRunLoopGetMain() everywhere. Get the
correct run loop using CFRunLoopGetCurrent() during
initialization, and store it.
Event dispatcher initialization must now be delayed
until after the constructor has run, since event dispatchers
may be created on the main thread and then moved to
the target thread. Initialize on first call to processEvents()
where the current thread will be the correct thread.
Use the stored m_runLoop instead of CFRunLoopGetMain().
This is required for wakeUp() and interrupt() which
may be called from another thread.
Change-Id: I6fffcfd4394899c4a12f241c42781979aaf99d5e
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/corelib/kernel/qcfsocketnotifier.cpp')
-rw-r--r-- | src/corelib/kernel/qcfsocketnotifier.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/corelib/kernel/qcfsocketnotifier.cpp b/src/corelib/kernel/qcfsocketnotifier.cpp index 1fee2aa5fc..920ec9cd86 100644 --- a/src/corelib/kernel/qcfsocketnotifier.cpp +++ b/src/corelib/kernel/qcfsocketnotifier.cpp @@ -86,7 +86,7 @@ CFRunLoopSourceRef qt_mac_add_socket_to_runloop(const CFSocketRef socket) if (!loopSource) return 0; - CFRunLoopAddSource(CFRunLoopGetMain(), loopSource, kCFRunLoopCommonModes); + CFRunLoopAddSource(CFRunLoopGetCurrent(), loopSource, kCFRunLoopCommonModes); return loopSource; } @@ -96,7 +96,7 @@ CFRunLoopSourceRef qt_mac_add_socket_to_runloop(const CFSocketRef socket) void qt_mac_remove_socket_from_runloop(const CFSocketRef socket, CFRunLoopSourceRef runloop) { Q_ASSERT(runloop); - CFRunLoopRemoveSource(CFRunLoopGetMain(), runloop, kCFRunLoopCommonModes); + CFRunLoopRemoveSource(CFRunLoopGetCurrent(), runloop, kCFRunLoopCommonModes); CFSocketDisableCallBacks(socket, kCFSocketReadCallBack); CFSocketDisableCallBacks(socket, kCFSocketWriteCallBack); } @@ -188,7 +188,7 @@ void QCFSocketNotifier::registerSocketNotifier(QSocketNotifier *notifier) enableNotifiersObserver = CFRunLoopObserverCreate(kCFAllocatorDefault, kCFRunLoopBeforeSources, true, 0, enableSocketNotifiers, &context); Q_ASSERT(enableNotifiersObserver); - CFRunLoopAddObserver(CFRunLoopGetMain(), enableNotifiersObserver, kCFRunLoopCommonModes); + CFRunLoopAddObserver(CFRunLoopGetCurrent(), enableNotifiersObserver, kCFRunLoopCommonModes); } } |