mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-14 08:45:36 +08:00
* only call this->abandonAndWait() when not in main thread (also slack discussion MS/KB) * make sure web data service start to read even if setup reader signal was missed * add timestamp to setupreader to detect "recently read" in case signal is missed
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
|
||||
#include "threadedreader.h"
|
||||
#include "blackmisc/threadutils.h"
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Network;
|
||||
@@ -48,6 +49,14 @@ namespace BlackMisc
|
||||
this->m_updateTimestamp = updateTimestamp;
|
||||
}
|
||||
|
||||
bool CThreadedReader::updatedWithinLastMs(qint64 timeLastMs)
|
||||
{
|
||||
QDateTime dt(getUpdateTimestamp());
|
||||
if (dt.isNull() || !dt.isValid()) { return false; }
|
||||
qint64 delta = QDateTime::currentMSecsSinceEpoch() - dt.toMSecsSinceEpoch();
|
||||
return delta <= timeLastMs;
|
||||
}
|
||||
|
||||
void CThreadedReader::requestReload()
|
||||
{
|
||||
// default implementation, subclasses shall override as required
|
||||
@@ -56,11 +65,16 @@ namespace BlackMisc
|
||||
|
||||
void CThreadedReader::gracefulShutdown()
|
||||
{
|
||||
this->abandonAndWait();
|
||||
// if not in main thread stop, otherwise it makes no sense to abandon
|
||||
if (!CThreadUtils::isCurrentThreadObjectThread(this))
|
||||
{
|
||||
this->abandonAndWait();
|
||||
}
|
||||
}
|
||||
|
||||
CThreadedReader::~CThreadedReader()
|
||||
{
|
||||
gracefulShutdown();
|
||||
}
|
||||
|
||||
void CThreadedReader::setInterval(int updatePeriodMs)
|
||||
|
||||
@@ -30,21 +30,25 @@ namespace BlackMisc
|
||||
class BLACKMISC_EXPORT CThreadedReader : public CContinuousWorker
|
||||
{
|
||||
public:
|
||||
//! Destructor
|
||||
virtual ~CThreadedReader();
|
||||
|
||||
//! Thread safe, set update timestamp
|
||||
//! \threadsafe
|
||||
QDateTime getUpdateTimestamp() const;
|
||||
|
||||
//! Thread safe, set update timestamp
|
||||
//! \threadsafe
|
||||
void setUpdateTimestamp(const QDateTime &updateTimestamp);
|
||||
void setUpdateTimestamp(const QDateTime &updateTimestamp = QDateTime::currentDateTimeUtc());
|
||||
|
||||
//! Was setup read within last xx milliseconds
|
||||
//! \threadsafe
|
||||
bool updatedWithinLastMs(qint64 timeLastMs);
|
||||
|
||||
//! Request new reading
|
||||
//! \note override as required, default is to call initialize()
|
||||
virtual void requestReload();
|
||||
|
||||
//! Destructor
|
||||
virtual ~CThreadedReader();
|
||||
|
||||
//! Set the update time
|
||||
//! \param updatePeriodMs <=0 stops the timer
|
||||
//! \threadsafe
|
||||
|
||||
Reference in New Issue
Block a user