PITimer remove wait in stop, waitForFinish
This commit is contained in:
@@ -40,7 +40,7 @@ PICloudServer::PICloudServer(const PIString & path, PIIODevice::DeviceMode mode)
|
|||||||
delete c;
|
delete c;
|
||||||
}
|
}
|
||||||
opened_ = false;
|
opened_ = false;
|
||||||
ping_timer.stop(false);
|
ping_timer.stop();
|
||||||
piMSleep(100);
|
piMSleep(100);
|
||||||
});
|
});
|
||||||
CONNECTL(&ping_timer, tickEvent, [this] (void *, int){
|
CONNECTL(&ping_timer, tickEvent, [this] (void *, int){
|
||||||
@@ -80,7 +80,7 @@ bool PICloudServer::openDevice() {
|
|||||||
ping_timer.start(5000);
|
ping_timer.start(5000);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
ping_timer.stop(false);
|
ping_timer.stop();
|
||||||
eth.close();
|
eth.close();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -90,7 +90,7 @@ bool PICloudServer::openDevice() {
|
|||||||
bool PICloudServer::closeDevice() {
|
bool PICloudServer::closeDevice() {
|
||||||
//piCoutObj << "closeDevice" << this;
|
//piCoutObj << "closeDevice" << this;
|
||||||
eth.stopAndWait();
|
eth.stopAndWait();
|
||||||
ping_timer.stop(false);
|
ping_timer.stop();
|
||||||
eth.close();
|
eth.close();
|
||||||
for (auto c : clients_) {
|
for (auto c : clients_) {
|
||||||
delete c;
|
delete c;
|
||||||
|
|||||||
@@ -128,14 +128,14 @@ void _PITimerBase::setInterval(double i) {
|
|||||||
interval_ = i;
|
interval_ = i;
|
||||||
if (isRunning()) {
|
if (isRunning()) {
|
||||||
//piCout << "change interval runtime";
|
//piCout << "change interval runtime";
|
||||||
stop(true);
|
stop();
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool _PITimerBase::start(double interval_ms) {
|
bool _PITimerBase::start(double interval_ms) {
|
||||||
if (isRunning()) stop(true);
|
if (isRunning()) stop();
|
||||||
deferred_ = false;
|
deferred_ = false;
|
||||||
setInterval(interval_ms);
|
setInterval(interval_ms);
|
||||||
//piCout << "_PITimerBase::startTimer"<<interval_ms<<"...";
|
//piCout << "_PITimerBase::startTimer"<<interval_ms<<"...";
|
||||||
@@ -145,7 +145,7 @@ bool _PITimerBase::start(double interval_ms) {
|
|||||||
|
|
||||||
|
|
||||||
void _PITimerBase::startDeferred(double interval_ms, PIDateTime start_datetime) {
|
void _PITimerBase::startDeferred(double interval_ms, PIDateTime start_datetime) {
|
||||||
if (isRunning()) stop(true);
|
if (isRunning()) stop();
|
||||||
deferred_ = true;
|
deferred_ = true;
|
||||||
deferred_mode = true;
|
deferred_mode = true;
|
||||||
deferred_datetime = start_datetime;
|
deferred_datetime = start_datetime;
|
||||||
@@ -155,7 +155,7 @@ void _PITimerBase::startDeferred(double interval_ms, PIDateTime start_datetime)
|
|||||||
|
|
||||||
|
|
||||||
void _PITimerBase::startDeferred(double interval_ms, double delay_ms) {
|
void _PITimerBase::startDeferred(double interval_ms, double delay_ms) {
|
||||||
if (isRunning()) stop(true);
|
if (isRunning()) stop();
|
||||||
deferred_ = true;
|
deferred_ = true;
|
||||||
deferred_mode = false;
|
deferred_mode = false;
|
||||||
deferred_delay = delay_ms;
|
deferred_delay = delay_ms;
|
||||||
@@ -164,11 +164,11 @@ void _PITimerBase::startDeferred(double interval_ms, double delay_ms) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool _PITimerBase::stop(bool wait) {
|
bool _PITimerBase::stop() {
|
||||||
//piCout << GetCurrentThreadId() << "_PITimerBase::stop" << wait << isRunning();
|
//piCout << GetCurrentThreadId() << "_PITimerBase::stop" << wait << isRunning();
|
||||||
if (!isRunning()) return true;
|
if (!isRunning()) return true;
|
||||||
//piCout << "_PITimerBase::stopTimer ...";
|
//piCout << "_PITimerBase::stopTimer ...";
|
||||||
running_ = !stopTimer(wait);
|
running_ = !stopTimer();
|
||||||
return !running_;
|
return !running_;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,14 +178,14 @@ bool _PITimerBase::stop(bool wait) {
|
|||||||
class _PITimerImp_Thread: public _PITimerBase {
|
class _PITimerImp_Thread: public _PITimerBase {
|
||||||
public:
|
public:
|
||||||
_PITimerImp_Thread();
|
_PITimerImp_Thread();
|
||||||
virtual ~_PITimerImp_Thread();
|
virtual ~_PITimerImp_Thread() {stop();}
|
||||||
protected:
|
protected:
|
||||||
void prepareStart(double interval_ms);
|
void prepareStart(double interval_ms);
|
||||||
bool threadFunc(); // returns true if repeat is needed
|
bool threadFunc(); // returns true if repeat is needed
|
||||||
int wait_dt, wait_dd, wait_tick;
|
int wait_dt, wait_dd, wait_tick;
|
||||||
private:
|
private:
|
||||||
virtual bool startTimer(double interval_ms);
|
bool startTimer(double interval_ms) override;
|
||||||
virtual bool stopTimer(bool wait);
|
bool stopTimer() override;
|
||||||
static void threadFuncS(void * d) {((_PITimerImp_Thread*)d)->threadFunc();}
|
static void threadFuncS(void * d) {((_PITimerImp_Thread*)d)->threadFunc();}
|
||||||
void adjustTimes();
|
void adjustTimes();
|
||||||
bool smallWait(int ms);
|
bool smallWait(int ms);
|
||||||
@@ -216,7 +216,7 @@ private:
|
|||||||
class _PITimerImp_Pool: public _PITimerImp_Thread {
|
class _PITimerImp_Pool: public _PITimerImp_Thread {
|
||||||
public:
|
public:
|
||||||
_PITimerImp_Pool();
|
_PITimerImp_Pool();
|
||||||
virtual ~_PITimerImp_Pool() {stop(true);}
|
virtual ~_PITimerImp_Pool() {stop();}
|
||||||
private:
|
private:
|
||||||
class Pool: public PIThread {
|
class Pool: public PIThread {
|
||||||
public:
|
public:
|
||||||
@@ -229,8 +229,8 @@ private:
|
|||||||
explicit Pool();
|
explicit Pool();
|
||||||
virtual ~Pool();
|
virtual ~Pool();
|
||||||
};
|
};
|
||||||
virtual bool startTimer(double interval_ms);
|
bool startTimer(double interval_ms) override;
|
||||||
virtual bool stopTimer(bool wait);
|
bool stopTimer() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -246,11 +246,6 @@ _PITimerImp_Thread::_PITimerImp_Thread() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
_PITimerImp_Thread::~_PITimerImp_Thread() {
|
|
||||||
stop(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void _PITimerImp_Thread::prepareStart(double interval_ms) {
|
void _PITimerImp_Thread::prepareStart(double interval_ms) {
|
||||||
if (interval_ms <= 0.) {
|
if (interval_ms <= 0.) {
|
||||||
piCout << "Achtung! Start PITimer with interval <= 0!";
|
piCout << "Achtung! Start PITimer with interval <= 0!";
|
||||||
@@ -276,7 +271,7 @@ bool _PITimerImp_Thread::startTimer(double interval_ms) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool _PITimerImp_Thread::stopTimer(bool wait) {
|
bool _PITimerImp_Thread::stopTimer() {
|
||||||
thread_.stop();
|
thread_.stop();
|
||||||
event.notifyAll();
|
event.notifyAll();
|
||||||
thread_.waitForFinish();
|
thread_.waitForFinish();
|
||||||
@@ -521,7 +516,7 @@ bool _PITimerImp_Pool::startTimer(double interval_ms) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool _PITimerImp_Pool::stopTimer(bool wait) {
|
bool _PITimerImp_Pool::stopTimer() {
|
||||||
Pool::instance()->remove(this);
|
Pool::instance()->remove(this);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -633,7 +628,7 @@ void PITimer::init() const {
|
|||||||
void PITimer::destroy() {
|
void PITimer::destroy() {
|
||||||
if (!imp) return;
|
if (!imp) return;
|
||||||
//piCout << this << "destroy" << imp;
|
//piCout << this << "destroy" << imp;
|
||||||
imp->stop(false); ///BUG: WTF FreeRTOS segfault on this!
|
imp->stop();
|
||||||
delete imp;
|
delete imp;
|
||||||
imp = 0;
|
imp = 0;
|
||||||
}
|
}
|
||||||
@@ -723,37 +718,14 @@ void PITimer::startDeferred(double interval_ms, PIDateTime start_datetime) {
|
|||||||
|
|
||||||
bool PITimer::restart() {
|
bool PITimer::restart() {
|
||||||
init();
|
init();
|
||||||
imp->stop(true);
|
imp->stop();
|
||||||
return imp->start();
|
return imp->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool PITimer::stop() {
|
bool PITimer::stop() {
|
||||||
return stop(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool PITimer::stop(bool wait) {
|
|
||||||
init();
|
init();
|
||||||
//piCout << this << "stop" << imp << wait;
|
//piCout << this << "stop" << imp << wait;
|
||||||
return imp->stop(wait);
|
return imp->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool PITimer::waitForFinish(int timeout_msecs) {
|
|
||||||
if (timeout_msecs < 0) {
|
|
||||||
while (isRunning())
|
|
||||||
piMinSleep();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
PITimeMeasurer tm;
|
|
||||||
while (isRunning() && tm.elapsed_m() < timeout_msecs)
|
|
||||||
piMinSleep();
|
|
||||||
return tm.elapsed_m() < timeout_msecs;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PITimer::stopAndWait(int timeout_ms) {
|
|
||||||
init();
|
|
||||||
imp->stop(false);
|
|
||||||
waitForFinish(timeout_ms);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public:
|
|||||||
void startDeferred(PIDateTime start_datetime) {startDeferred(interval_, start_datetime);}
|
void startDeferred(PIDateTime start_datetime) {startDeferred(interval_, start_datetime);}
|
||||||
void startDeferred(double interval_ms, PIDateTime start_datetime);
|
void startDeferred(double interval_ms, PIDateTime start_datetime);
|
||||||
|
|
||||||
bool stop(bool wait);
|
bool stop();
|
||||||
|
|
||||||
typedef void(*TickFunc)(PITimer*);
|
typedef void(*TickFunc)(PITimer*);
|
||||||
TickFunc tfunc;
|
TickFunc tfunc;
|
||||||
@@ -62,7 +62,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual bool startTimer(double interval_ms) = 0;
|
virtual bool startTimer(double interval_ms) = 0;
|
||||||
virtual bool stopTimer(bool wait) = 0;
|
virtual bool stopTimer() = 0;
|
||||||
|
|
||||||
double interval_, deferred_delay;
|
double interval_, deferred_delay;
|
||||||
bool deferred_, deferred_mode; // mode: true - date, false - delay
|
bool deferred_, deferred_mode; // mode: true - date, false - delay
|
||||||
@@ -161,13 +161,6 @@ public:
|
|||||||
void startDeferred(double interval_ms, PIDateTime start_datetime);
|
void startDeferred(double interval_ms, PIDateTime start_datetime);
|
||||||
|
|
||||||
EVENT_HANDLER0(bool, stop);
|
EVENT_HANDLER0(bool, stop);
|
||||||
EVENT_HANDLER1(bool, stop, bool, wait);
|
|
||||||
bool waitForFinish() {return waitForFinish(-1);}
|
|
||||||
bool waitForFinish(int timeout_msecs);
|
|
||||||
|
|
||||||
//! \~english Stop timer and wait for finish.
|
|
||||||
//! \~russian Останавливает таймер и ожидает завершения.
|
|
||||||
void stopAndWait(int timeout_ms = -1);
|
|
||||||
|
|
||||||
//! \~english Set custom data
|
//! \~english Set custom data
|
||||||
//! \~russian Установить данные, передаваемые в метод таймера
|
//! \~russian Установить данные, передаваемые в метод таймера
|
||||||
|
|||||||
Reference in New Issue
Block a user