version 4.6.0
PIThreadNotifier::waitFor() new method PIThread::waitForFinish() now use condvar to exit as soon as possible
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
|
||||
#include "piincludes_p.h"
|
||||
#include "piintrospection_threads.h"
|
||||
#include "piliterals_time.h"
|
||||
#include "pitime.h"
|
||||
#include "pitranslator.h"
|
||||
#ifndef MICRO_PIP
|
||||
@@ -827,26 +828,14 @@ bool PIThread::waitForFinish(PISystemTime timeout) {
|
||||
// timeout_msecs;
|
||||
if (!running_) return true;
|
||||
if (timeout.isNull()) {
|
||||
while (running_) {
|
||||
piMinSleep();
|
||||
#ifdef WINDOWS
|
||||
if (!isExists(PRIVATE->thread)) {
|
||||
unlock();
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
for (;;) {
|
||||
if (_waitForFinish(100_ms)) break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
tmf_.reset();
|
||||
while (running_ && tmf_.elapsed() < timeout) {
|
||||
piMinSleep();
|
||||
#ifdef WINDOWS
|
||||
if (!isExists(PRIVATE->thread)) {
|
||||
unlock();
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
while (tmf_.elapsed() < timeout) {
|
||||
if (_waitForFinish(100_ms)) return true;
|
||||
}
|
||||
return tmf_.elapsed() < timeout;
|
||||
}
|
||||
@@ -919,10 +908,11 @@ void PIThread::_endThread() {
|
||||
PIScopeExitCall ec([this] {
|
||||
terminating = running_ = false;
|
||||
tid_ = -1;
|
||||
state_mutex.lock();
|
||||
state_var.notifyAll();
|
||||
state_mutex.unlock();
|
||||
});
|
||||
// while (PRIVATE->starting)
|
||||
// piMinSleep();
|
||||
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "stop" << "...";
|
||||
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "stop" << "...";
|
||||
stopped();
|
||||
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "stop" << "ok";
|
||||
if (lockRun) thread_mutex.lock();
|
||||
@@ -1084,3 +1074,19 @@ void PIThread::setThreadName() {
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
bool PIThread::_waitForFinish(PISystemTime max_tm) {
|
||||
if (!running_) return true;
|
||||
state_mutex.lock();
|
||||
state_var.waitFor(state_mutex, max_tm);
|
||||
state_mutex.unlock();
|
||||
if (!running_) return true;
|
||||
#ifdef WINDOWS
|
||||
if (!isExists(PRIVATE->thread)) {
|
||||
unlock();
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user