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;
|
||||
}
|
||||
opened_ = false;
|
||||
ping_timer.stop(false);
|
||||
ping_timer.stop();
|
||||
piMSleep(100);
|
||||
});
|
||||
CONNECTL(&ping_timer, tickEvent, [this] (void *, int){
|
||||
@@ -80,7 +80,7 @@ bool PICloudServer::openDevice() {
|
||||
ping_timer.start(5000);
|
||||
return true;
|
||||
} else {
|
||||
ping_timer.stop(false);
|
||||
ping_timer.stop();
|
||||
eth.close();
|
||||
return false;
|
||||
}
|
||||
@@ -90,7 +90,7 @@ bool PICloudServer::openDevice() {
|
||||
bool PICloudServer::closeDevice() {
|
||||
//piCoutObj << "closeDevice" << this;
|
||||
eth.stopAndWait();
|
||||
ping_timer.stop(false);
|
||||
ping_timer.stop();
|
||||
eth.close();
|
||||
for (auto c : clients_) {
|
||||
delete c;
|
||||
|
||||
@@ -128,14 +128,14 @@ void _PITimerBase::setInterval(double i) {
|
||||
interval_ = i;
|
||||
if (isRunning()) {
|
||||
//piCout << "change interval runtime";
|
||||
stop(true);
|
||||
stop();
|
||||
start();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool _PITimerBase::start(double interval_ms) {
|
||||
if (isRunning()) stop(true);
|
||||
if (isRunning()) stop();
|
||||
deferred_ = false;
|
||||
setInterval(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) {
|
||||
if (isRunning()) stop(true);
|
||||
if (isRunning()) stop();
|
||||
deferred_ = true;
|
||||
deferred_mode = true;
|
||||
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) {
|
||||
if (isRunning()) stop(true);
|
||||
if (isRunning()) stop();
|
||||
deferred_ = true;
|
||||
deferred_mode = false;
|
||||
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();
|
||||
if (!isRunning()) return true;
|
||||
//piCout << "_PITimerBase::stopTimer ...";
|
||||
running_ = !stopTimer(wait);
|
||||
running_ = !stopTimer();
|
||||
return !running_;
|
||||
}
|
||||
|
||||
@@ -178,14 +178,14 @@ bool _PITimerBase::stop(bool wait) {
|
||||
class _PITimerImp_Thread: public _PITimerBase {
|
||||
public:
|
||||
_PITimerImp_Thread();
|
||||
virtual ~_PITimerImp_Thread();
|
||||
virtual ~_PITimerImp_Thread() {stop();}
|
||||
protected:
|
||||
void prepareStart(double interval_ms);
|
||||
bool threadFunc(); // returns true if repeat is needed
|
||||
int wait_dt, wait_dd, wait_tick;
|
||||
private:
|
||||
virtual bool startTimer(double interval_ms);
|
||||
virtual bool stopTimer(bool wait);
|
||||
bool startTimer(double interval_ms) override;
|
||||
bool stopTimer() override;
|
||||
static void threadFuncS(void * d) {((_PITimerImp_Thread*)d)->threadFunc();}
|
||||
void adjustTimes();
|
||||
bool smallWait(int ms);
|
||||
@@ -216,7 +216,7 @@ private:
|
||||
class _PITimerImp_Pool: public _PITimerImp_Thread {
|
||||
public:
|
||||
_PITimerImp_Pool();
|
||||
virtual ~_PITimerImp_Pool() {stop(true);}
|
||||
virtual ~_PITimerImp_Pool() {stop();}
|
||||
private:
|
||||
class Pool: public PIThread {
|
||||
public:
|
||||
@@ -229,8 +229,8 @@ private:
|
||||
explicit Pool();
|
||||
virtual ~Pool();
|
||||
};
|
||||
virtual bool startTimer(double interval_ms);
|
||||
virtual bool stopTimer(bool wait);
|
||||
bool startTimer(double interval_ms) override;
|
||||
bool stopTimer() override;
|
||||
};
|
||||
|
||||
|
||||
@@ -246,11 +246,6 @@ _PITimerImp_Thread::_PITimerImp_Thread() {
|
||||
}
|
||||
|
||||
|
||||
_PITimerImp_Thread::~_PITimerImp_Thread() {
|
||||
stop(true);
|
||||
}
|
||||
|
||||
|
||||
void _PITimerImp_Thread::prepareStart(double interval_ms) {
|
||||
if (interval_ms <= 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();
|
||||
event.notifyAll();
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
@@ -633,7 +628,7 @@ void PITimer::init() const {
|
||||
void PITimer::destroy() {
|
||||
if (!imp) return;
|
||||
//piCout << this << "destroy" << imp;
|
||||
imp->stop(false); ///BUG: WTF FreeRTOS segfault on this!
|
||||
imp->stop();
|
||||
delete imp;
|
||||
imp = 0;
|
||||
}
|
||||
@@ -723,37 +718,14 @@ void PITimer::startDeferred(double interval_ms, PIDateTime start_datetime) {
|
||||
|
||||
bool PITimer::restart() {
|
||||
init();
|
||||
imp->stop(true);
|
||||
imp->stop();
|
||||
return imp->start();
|
||||
}
|
||||
|
||||
|
||||
bool PITimer::stop() {
|
||||
return stop(true);
|
||||
}
|
||||
|
||||
|
||||
bool PITimer::stop(bool wait) {
|
||||
init();
|
||||
//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(double interval_ms, PIDateTime start_datetime);
|
||||
|
||||
bool stop(bool wait);
|
||||
bool stop();
|
||||
|
||||
typedef void(*TickFunc)(PITimer*);
|
||||
TickFunc tfunc;
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
protected:
|
||||
|
||||
virtual bool startTimer(double interval_ms) = 0;
|
||||
virtual bool stopTimer(bool wait) = 0;
|
||||
virtual bool stopTimer() = 0;
|
||||
|
||||
double interval_, deferred_delay;
|
||||
bool deferred_, deferred_mode; // mode: true - date, false - delay
|
||||
@@ -161,14 +161,7 @@ public:
|
||||
void startDeferred(double interval_ms, PIDateTime start_datetime);
|
||||
|
||||
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
|
||||
//! \~russian Установить данные, передаваемые в метод таймера
|
||||
void setData(void * data_) {data_t = data_;}
|
||||
|
||||
Reference in New Issue
Block a user