mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 09:15:34 +08:00
refs #287 Thread safety, fix "memory access violation"
* some improved comments and information * QMetaObject::invokeMethod in tool.cpp as thread safe invocation * common base class for threaded readers * removed event class, using QMetaObject::invoke instead for forcing calls in main event loop * stop methods for readers, as used for graceful shutdown (preparing for thread safe destruction of objects) * graceful shutdown for network context * calls in tool now via inkoke for thread safety (only thread safe methods called directly)
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include "blackcore/context.h"
|
||||
#include "blackmisc/statusmessagelist.h"
|
||||
#include <QObject>
|
||||
#include <QReadWriteLock>
|
||||
|
||||
#define BLACKCORE_CONTEXTAPPLICATION_INTERFACENAME "net.vatsim.PilotClient.BlackCore.ContextApplication"
|
||||
#define BLACKCORE_CONTEXTAPPLICATION_OBJECTPATH "/Application"
|
||||
@@ -16,7 +17,7 @@
|
||||
namespace BlackCore
|
||||
{
|
||||
/*!
|
||||
* \brief Application context interface
|
||||
* Application context interface
|
||||
*/
|
||||
class IContextApplication : public CContext
|
||||
{
|
||||
@@ -76,20 +77,21 @@ namespace BlackCore
|
||||
virtual ~IContextApplication() {}
|
||||
|
||||
//! Output redirection (redirect my output)
|
||||
RedirectionLevel getOutputRedirectionLevel() const { return this->m_outputRedirectionLevel; }
|
||||
//! \threadsafe
|
||||
RedirectionLevel getOutputRedirectionLevel() const;
|
||||
|
||||
//! Output redirection (redirect my output)
|
||||
void setOutputRedirectionLevel(RedirectionLevel redirectionLevel) { this->m_outputRedirectionLevel = redirectionLevel; }
|
||||
//! \threadsafe
|
||||
void setOutputRedirectionLevel(RedirectionLevel redirectionLevel);
|
||||
|
||||
//! Redirected output generated by others
|
||||
RedirectionLevel getStreamingForRedirectedOutputLevel() const { return this->m_redirectedOutputRedirectionLevel; }
|
||||
//! \threadsafe
|
||||
RedirectionLevel getStreamingForRedirectedOutputLevel() const;
|
||||
|
||||
//! Redirected output generated by others
|
||||
//! \threadsafe
|
||||
void setStreamingForRedirectedOutputLevel(RedirectionLevel redirectionLevel) ;
|
||||
|
||||
//! Process event, cross thread messages
|
||||
bool event(QEvent *event) override;
|
||||
|
||||
//! Reset output redirection
|
||||
static void resetOutputRedirection();
|
||||
|
||||
@@ -144,13 +146,16 @@ namespace BlackCore
|
||||
static QtMessageHandler s_oldHandler;
|
||||
|
||||
//! Message handler, handles one individual context
|
||||
//! \threadsafe
|
||||
void messageHandler(QtMsgType type, const QMessageLogContext &messageContext, const QString &messsage);
|
||||
|
||||
//! Handle output dispatch, handles all contexts
|
||||
//! \remarks Can be called in thread, has to be thread safe
|
||||
static void messageHandlerDispatch(QtMsgType type, const QMessageLogContext &messageContext, const QString &message);
|
||||
|
||||
RedirectionLevel m_outputRedirectionLevel; //!< enable / disable my output
|
||||
RedirectionLevel m_redirectedOutputRedirectionLevel; //!< enable / disable others output
|
||||
RedirectionLevel m_redirectedOutputRedirectionLevel; //!< enable / disable others' output
|
||||
mutable QReadWriteLock m_lock; //!< thread safety
|
||||
|
||||
private slots:
|
||||
//! Re-stream the redirected output
|
||||
|
||||
Reference in New Issue
Block a user