version 3.21.0
add PISystemTime overload for thread/timer/io classes
This commit is contained in:
@@ -116,7 +116,7 @@ __THREAD_FUNC_RET__ thread_function_once(void * t) {
|
||||
//! while (isRunning()) { // while not stop()
|
||||
//! virtual run()
|
||||
//! ThreadFunc() // Slot or lambda
|
||||
//! piMSleep(timer_delay) // if timer_delay > 0
|
||||
//! piMSleep(loop_delay) // if loop_delay > 0
|
||||
//! }
|
||||
//! event stopped()
|
||||
//! virtual end()
|
||||
@@ -216,7 +216,7 @@ __THREAD_FUNC_RET__ thread_function_once(void * t) {
|
||||
//! \~russian \section PIThread_sec1 Использование без наследования
|
||||
//! \~english
|
||||
//! You can use %PIThread without subclassing by using "ThreadFunc" pointer
|
||||
//! that can be set from constructor or by overloaded function \a start(ThreadFunc func, int timer_delay).
|
||||
//! that can be set from constructor or by overloaded function \a start(ThreadFunc func, int loop_delay).
|
||||
//! If "func" if not null this function will be executed after \a run().
|
||||
//!
|
||||
//! ThreadFunc is any static function with format "void func(void * data)", or
|
||||
@@ -354,18 +354,18 @@ __THREAD_FUNC_RET__ thread_function_once(void * t) {
|
||||
//!
|
||||
|
||||
|
||||
//! \fn bool PIThread::start(int timer_delay = -1)
|
||||
//! \fn bool PIThread::start(int loop_delay = -1)
|
||||
//! \~\details
|
||||
//! \~english
|
||||
//! Start execution of \a run() in internal loop with
|
||||
//! "timer_delay" delay in milliseconds. If "timer_delay" <= 0
|
||||
//! "loop_delay" delay in milliseconds. If "loop_delay" <= 0
|
||||
//! this is no delay in loop. Thread also exec external function
|
||||
//! set by \a setSlot() if it`s not null.
|
||||
//! \return \c false if thread already started or can`t start thread
|
||||
//!
|
||||
//! \~russian
|
||||
//! Начинает выполнение \a run() во внутреннем цикле
|
||||
//! с задержкой "timer_delay" миллисекунд. Если "timer_delay" <= 0
|
||||
//! с задержкой "loop_delay" миллисекунд. Если "loop_delay" <= 0
|
||||
//! то задержки не будет. Также поток вызывает внешний метод,
|
||||
//! заданный через \a setSlot(), если он существует.
|
||||
//! \return \c false если поток уже запущен или не может запуститься
|
||||
@@ -525,51 +525,43 @@ __PIThreadCollection_Initializer__::~__PIThreadCollection_Initializer__() {
|
||||
|
||||
PRIVATE_DEFINITION_START(PIThread)
|
||||
#if defined(WINDOWS)
|
||||
void * thread;
|
||||
void * thread = nullptr;
|
||||
#elif defined(FREERTOS)
|
||||
TaskHandle_t thread;
|
||||
#else
|
||||
pthread_t thread;
|
||||
pthread_t thread = 0;
|
||||
sched_param sparam;
|
||||
#endif
|
||||
PRIVATE_DEFINITION_END(PIThread)
|
||||
|
||||
|
||||
PIThread::PIThread(void * data, ThreadFunc func, bool startNow, int timer_delay): PIObject() {
|
||||
PIThread::PIThread(void * data, ThreadFunc func, bool startNow, int loop_delay): PIObject() {
|
||||
PIINTROSPECTION_THREAD_NEW(this);
|
||||
tid_ = -1;
|
||||
PRIVATE->thread = 0;
|
||||
data_ = data;
|
||||
ret_func = func;
|
||||
data_ = data;
|
||||
ret_func = func;
|
||||
terminating = running_ = lockRun = false;
|
||||
priority_ = piNormal;
|
||||
delay_ = timer_delay;
|
||||
if (startNow) start(timer_delay);
|
||||
delay_ = loop_delay;
|
||||
if (startNow) start(loop_delay);
|
||||
}
|
||||
|
||||
|
||||
PIThread::PIThread(std::function<void()> func, bool startNow, int timer_delay) {
|
||||
PIThread::PIThread(std::function<void()> func, bool startNow, int loop_delay) {
|
||||
PIINTROSPECTION_THREAD_NEW(this);
|
||||
tid_ = -1;
|
||||
PRIVATE->thread = 0;
|
||||
data_ = 0;
|
||||
ret_func = [func](void *) { func(); };
|
||||
ret_func = [func](void *) { func(); };
|
||||
terminating = running_ = lockRun = false;
|
||||
priority_ = piNormal;
|
||||
delay_ = timer_delay;
|
||||
if (startNow) start(timer_delay);
|
||||
delay_ = loop_delay;
|
||||
if (startNow) start(loop_delay);
|
||||
}
|
||||
|
||||
|
||||
PIThread::PIThread(bool startNow, int timer_delay): PIObject() {
|
||||
PIThread::PIThread(bool startNow, int loop_delay): PIObject() {
|
||||
PIINTROSPECTION_THREAD_NEW(this);
|
||||
tid_ = -1;
|
||||
PRIVATE->thread = 0;
|
||||
ret_func = 0;
|
||||
terminating = running_ = lockRun = false;
|
||||
priority_ = piNormal;
|
||||
delay_ = timer_delay;
|
||||
if (startNow) start(timer_delay);
|
||||
delay_ = loop_delay;
|
||||
if (startNow) start(loop_delay);
|
||||
}
|
||||
|
||||
|
||||
@@ -599,6 +591,24 @@ PIThread::~PIThread() {
|
||||
}
|
||||
|
||||
|
||||
bool PIThread::start(ThreadFunc func, int loop_delay) {
|
||||
ret_func = func;
|
||||
return start(loop_delay);
|
||||
}
|
||||
|
||||
|
||||
bool PIThread::start(std::function<void()> func, int loop_delay) {
|
||||
ret_func = [func](void *) { func(); };
|
||||
return start(loop_delay);
|
||||
}
|
||||
|
||||
|
||||
bool PIThread::startOnce(ThreadFunc func) {
|
||||
ret_func = func;
|
||||
return startOnce();
|
||||
}
|
||||
|
||||
|
||||
void PIThread::stopAndWait(int timeout_ms) {
|
||||
stop();
|
||||
waitForFinish(timeout_ms);
|
||||
@@ -611,9 +621,9 @@ void PIThread::stop() {
|
||||
}
|
||||
|
||||
|
||||
bool PIThread::start(int timer_delay) {
|
||||
bool PIThread::start(int loop_delay) {
|
||||
if (running_) return false;
|
||||
delay_ = timer_delay;
|
||||
delay_ = loop_delay;
|
||||
return _startThread((void *)thread_function);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user