pithread, pitimer stop, stopAndWait
This commit is contained in:
@@ -588,7 +588,7 @@ void PIScreen::waitForFinish() {
|
||||
|
||||
|
||||
void PIScreen::stop(bool clear) {
|
||||
PIThread::stop(true);
|
||||
PIThread::stopAndWait();
|
||||
if (clear) console.clearScreen();
|
||||
#ifndef WINDOWS
|
||||
fflush(0);
|
||||
|
||||
@@ -192,7 +192,7 @@ PIPeer::~PIPeer() {
|
||||
if (p._data) {
|
||||
p._data->dt_in.stop();
|
||||
p._data->dt_out.stop();
|
||||
p._data->t.stop(true);
|
||||
p._data->t.stopAndWait();
|
||||
}
|
||||
destroyEths();
|
||||
piForeach (PIEthernet * i, eths_mcast) {
|
||||
|
||||
@@ -620,10 +620,9 @@ void PIThread::interrupt() {
|
||||
}
|
||||
|
||||
|
||||
void PIThread::stop(bool wait) {
|
||||
void PIThread::stop() {
|
||||
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "stop ..." << running_ << wait;
|
||||
terminating = true;
|
||||
if (wait) waitForFinish();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -107,12 +107,11 @@ public:
|
||||
bool start(std::function<void()> func, int timer_delay) {ret_func = [func](void*){func();}; return start(timer_delay);}
|
||||
EVENT_HANDLER0(bool, startOnce);
|
||||
EVENT_HANDLER1(bool, startOnce, ThreadFunc, func) {ret_func = func; return startOnce();}
|
||||
EVENT_HANDLER0(void, stop) {stop(false);}
|
||||
EVENT_HANDLER1(void, stop, bool, wait);
|
||||
EVENT_HANDLER0(void, stop);
|
||||
EVENT_HANDLER0(void, terminate);
|
||||
|
||||
//! \~english Stop thread and wait for finish.
|
||||
//! \~russian Останавливает потоков и ожидает завершения.
|
||||
//! \~russian Останавливает поток и ожидает завершения.
|
||||
void stopAndWait(int timeout_ms = -1);
|
||||
|
||||
void interrupt();
|
||||
@@ -201,7 +200,7 @@ public:
|
||||
//! \~english Start thread without internal loop
|
||||
//! \~russian Запускает поток без внутреннего цикла
|
||||
|
||||
//! \fn void stop(bool wait = false)
|
||||
//! \fn void stop()
|
||||
//! \brief
|
||||
//! \~english Stop thread
|
||||
//! \~russian Останавливает поток
|
||||
@@ -209,7 +208,7 @@ public:
|
||||
//! \fn void terminate()
|
||||
//! \brief
|
||||
//! \~english Strongly stop thread
|
||||
//! \~russian Жестко останавливает поток
|
||||
//! \~russian Жёстко прерывает поток
|
||||
|
||||
//! \fn bool waitForStart(int timeout_msecs = -1)
|
||||
//! \brief
|
||||
|
||||
@@ -114,7 +114,7 @@ PIThreadPoolLoop::PIThreadPoolLoop(int thread_cnt) {
|
||||
|
||||
PIThreadPoolLoop::~PIThreadPoolLoop() {
|
||||
for (auto * t: threads) {
|
||||
t->stop(false);
|
||||
t->stop();
|
||||
if (!t->waitForFinish(100))
|
||||
t->terminate();
|
||||
delete t;
|
||||
@@ -135,7 +135,7 @@ void PIThreadPoolLoop::start(int index_start, int index_count) {
|
||||
while (1) {
|
||||
int cc = counter.fetch_add(1);
|
||||
if (cc >= end) {
|
||||
t->stop(false);
|
||||
t->stop();
|
||||
return;
|
||||
}
|
||||
func(cc);
|
||||
|
||||
@@ -274,15 +274,12 @@ bool _PITimerImp_Thread::startTimer(double interval_ms) {
|
||||
|
||||
|
||||
bool _PITimerImp_Thread::stopTimer(bool wait) {
|
||||
#ifndef FREERTOS
|
||||
thread_.stop(wait);
|
||||
#else
|
||||
thread_.stop();
|
||||
if (wait)
|
||||
if (!thread_.waitForFinish(10))
|
||||
if (thread_.isRunning())
|
||||
thread_.terminate();
|
||||
#endif
|
||||
if (wait) return thread_.waitForFinish();
|
||||
// if (wait)
|
||||
// if (!thread_.waitForFinish(10))
|
||||
// if (thread_.isRunning())
|
||||
// thread_.terminate();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -739,3 +736,9 @@ bool PITimer::waitForFinish(int timeout_msecs) {
|
||||
piMinSleep();
|
||||
return tm.elapsed_m() < timeout_msecs;
|
||||
}
|
||||
|
||||
void PITimer::stopAndWait(int timeout_ms) {
|
||||
init();
|
||||
imp->stop(false);
|
||||
waitForFinish(timeout_ms);
|
||||
}
|
||||
|
||||
@@ -165,6 +165,10 @@ public:
|
||||
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_;}
|
||||
|
||||
@@ -24,7 +24,7 @@ Daemon::Remote::Remote(const PIString & n): PIThread() {
|
||||
Daemon::Remote::~Remote() {
|
||||
shellClose();
|
||||
ft.stop();
|
||||
stop(true);
|
||||
stopAndWait();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user