doc ru, printf() before assert in containers
This commit is contained in:
@@ -65,6 +65,7 @@ static __PIThreadCollection_Initializer__ __PIThreadCollection_initializer__;
|
||||
|
||||
typedef std::function<void(void *)> ThreadFunc;
|
||||
|
||||
|
||||
class PIP_EXPORT PIThread: public PIObject
|
||||
{
|
||||
PIOBJECT_SUBCLASS(PIThread, PIObject)
|
||||
@@ -74,24 +75,28 @@ class PIP_EXPORT PIThread: public PIObject
|
||||
public:
|
||||
NO_COPY_CLASS(PIThread)
|
||||
|
||||
//! Contructs thread with custom data "data", external function "func" and main loop delay "loop_delay".
|
||||
//! \~english Contructs thread with custom data "data", external function "func" and main loop delay "loop_delay"
|
||||
//! \~russian Создает поток с данными "data", функцией "func" и задержкой цикла "loop_delay"
|
||||
PIThread(void * data, ThreadFunc func, bool startNow = false, int loop_delay = -1);
|
||||
|
||||
//! Contructs thread with external function "func" and main loop delay "loop_delay".
|
||||
//! \~english Contructs thread with external function "func" and main loop delay "loop_delay"
|
||||
//! \~russian Создает поток с функцией "func" и задержкой цикла "loop_delay"
|
||||
PIThread(std::function<void()> func, bool startNow = false, int loop_delay = -1);
|
||||
|
||||
//! Contructs thread with main loop delay "loop_delay".
|
||||
//! \~english Contructs thread with main loop delay "loop_delay"
|
||||
//! \~russian Создает поток с задержкой цикла "loop_delay"
|
||||
PIThread(bool startNow = false, int loop_delay = -1);
|
||||
|
||||
virtual ~PIThread();
|
||||
|
||||
//! Priority of thread
|
||||
//! \~english Priority of thread
|
||||
//! \~russian Приоритет потока
|
||||
enum Priority {
|
||||
piLowerst /** Lowest */,
|
||||
piLow /** Low */,
|
||||
piNormal /** Normal, this is default priority of threads and timers */,
|
||||
piHigh /** High */,
|
||||
piHighest /** Highest */
|
||||
piLowerst /** \~english Lowest \~russian Низший */ ,
|
||||
piLow /** \~english Low \~russian Низкий */ ,
|
||||
piNormal /** \~english Normal, this is default priority of threads and timers \~russian Нормальный, это приоритет по умолчанию для потоков и таймеров */ ,
|
||||
piHigh /** \~english High \~russian Высокий */ ,
|
||||
piHighest /** \~english Highest \~russian Высший */
|
||||
};
|
||||
|
||||
EVENT_HANDLER0(bool, start) {return start(-1);}
|
||||
@@ -106,27 +111,36 @@ public:
|
||||
EVENT_HANDLER1(void, stop, bool, wait);
|
||||
EVENT_HANDLER0(void, terminate);
|
||||
|
||||
//! \brief Set common data passed to external function
|
||||
//! \~english Set common data passed to external function
|
||||
//! \~russian Устанавливает данные, передаваемые в функцию потока
|
||||
void setData(void * d) {data_ = d;}
|
||||
|
||||
//! \brief Set external function that will be executed after every \a run()
|
||||
//! \~english Set external function that will be executed after every \a run()
|
||||
//! \~russian Устанавливает функцию потока, вызываемую после каждого \a run()
|
||||
void setSlot(ThreadFunc func) {ret_func = func;}
|
||||
|
||||
//! \brief Set external function that will be executed after every \a run()
|
||||
//! \~english Set external function that will be executed after every \a run()
|
||||
//! \~russian Устанавливает функцию потока, вызываемую после каждого \a run()
|
||||
void setSlot(std::function<void()> func) {ret_func = [func](void*){func();};}
|
||||
|
||||
//! \brief Set priority of thread
|
||||
//! \~english Set thread priority
|
||||
//! \~russian Устанавливает приоритет потока
|
||||
void setPriority(PIThread::Priority prior);
|
||||
|
||||
//! \brief Returns common data passed to external function
|
||||
//! \~english Returns common data passed to external function
|
||||
//! \~russian Возвращает данные, передаваемые в функцию потока
|
||||
void * data() const {return data_;}
|
||||
|
||||
//! \brief Return priority of thread
|
||||
//! \~english Return thread priority
|
||||
//! \~russian Возвращает приоритет потока
|
||||
PIThread::Priority priority() const {return priority_;}
|
||||
|
||||
//! \brief Return \c true if thread is running
|
||||
//! \~english Return if thread is running
|
||||
//! \~russian Возвращает исполняется ли поток
|
||||
bool isRunning() const {return running_;}
|
||||
|
||||
//! \~english Return if thread is stopping
|
||||
//! \~russian Возвращает останавливается ли поток
|
||||
bool isStopping() const {return running_ && terminating;}
|
||||
|
||||
EVENT_HANDLER0(bool, waitForStart) {return waitForStart(-1);}
|
||||
@@ -134,19 +148,19 @@ public:
|
||||
EVENT_HANDLER0(bool, waitForFinish) {return waitForFinish(-1);}
|
||||
EVENT_HANDLER1(bool, waitForFinish, int, timeout_msecs);
|
||||
|
||||
//! \brief Set necessity of lock every \a run with internal mutex
|
||||
//! \~english Set necessity of lock every \a run() with internal mutex
|
||||
//! \~russian Устанавливает необходимость блокировки внутреннего мьютекса каждый \a run()
|
||||
void needLockRun(bool need) {lockRun = need;}
|
||||
|
||||
//! \brief Lock internal mutex
|
||||
EVENT_HANDLER0(void, lock) const {thread_mutex.lock();}
|
||||
|
||||
//! \brief Unlock internal mutex
|
||||
EVENT_HANDLER0(void, unlock) const {thread_mutex.unlock();}
|
||||
|
||||
//! \brief Returns internal mutex
|
||||
//! \~english Returns internal mutex
|
||||
//! \~russian Возвращает внутренний мьютекс
|
||||
PIMutex & mutex() const {return thread_mutex;}
|
||||
|
||||
//! \brief Returns thread ID
|
||||
//! \~english Returns thread ID
|
||||
//! \~russian Возвращает ID потока
|
||||
llong tid() const {return tid_;}
|
||||
|
||||
void __thread_func__();
|
||||
@@ -155,93 +169,129 @@ public:
|
||||
EVENT(started)
|
||||
EVENT(stopped)
|
||||
|
||||
//! \brief Start event handler with name \"handler\" of object \"object\"
|
||||
//! in separate thread with name \"name\"
|
||||
//! \~english
|
||||
//! Start event handler with name "handler" of object "object"
|
||||
//! in separate thread with name "name"
|
||||
//! and automatically delete it on function finish
|
||||
//!
|
||||
//! \~russian
|
||||
static void runOnce(PIObject * object, const char * handler, const PIString & name = PIString());
|
||||
|
||||
//! \brief Start function \"func\" in separate thread with name \"name\"
|
||||
//! \~english
|
||||
//! Start function "func" in separate thread with name "name"
|
||||
//! and automatically delete it on function finish
|
||||
//!
|
||||
//! \~russian
|
||||
static void runOnce(std::function<void()> func, const PIString & name = PIString());
|
||||
|
||||
//! \handlers
|
||||
//! \{
|
||||
|
||||
/** \fn bool start(int timer_delay = -1)
|
||||
* \brief Start thread
|
||||
* \details Start execution of \a run() in internal loop with
|
||||
* "timer_delay" delay in milliseconds. If "timer_delay" <= 0
|
||||
* there 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 */
|
||||
//! \fn bool start(int timer_delay = -1)
|
||||
//! \~english Start thread
|
||||
//! \~russian Запускает поток
|
||||
//! \~\details
|
||||
//! \~english
|
||||
//! Start execution of \a run() in internal loop with
|
||||
//! "timer_delay" delay in milliseconds. If "timer_delay" <= 0
|
||||
//! there 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
|
||||
|
||||
/** \fn bool startOnce()
|
||||
* \brief Start thread without internal loop
|
||||
* \details Start execution of \a run() once. 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 */
|
||||
//! \fn bool startOnce()
|
||||
//! \~english Start thread without internal loop
|
||||
//! \~russian Запускает поток без внутреннего цикла
|
||||
//! \~\details
|
||||
//! \~english
|
||||
//! Start execution of \a run() once. 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
|
||||
|
||||
/** \fn bool startOnce(ThreadFunc func)
|
||||
* \brief Start thread without internal loop
|
||||
* \details Overloaded function. Set external function "func" before start
|
||||
*
|
||||
* \return \c false if thread already started or can`t start thread */
|
||||
//! \fn bool startOnce(ThreadFunc func)
|
||||
//! \~english Start thread without internal loop
|
||||
//! \~russian Запускает поток без внутреннего цикла
|
||||
//! \~\details
|
||||
//! \~english
|
||||
//! Overloaded function. Set external function "func" before start
|
||||
//! \return \c false if thread already started or can`t start thread
|
||||
//! \~russian
|
||||
|
||||
/** \fn void stop(bool wait = false)
|
||||
* \brief Stop thread
|
||||
* \details Stop execution of thread and wait for it finish
|
||||
* if "wait" is \c true. This function can block for infinite
|
||||
* time if "wait" is \c true and any of thread function is
|
||||
* busy forever */
|
||||
//! \fn void stop(bool wait = false)
|
||||
//! \~english Stop thread
|
||||
//! \~russian Останавливает поток
|
||||
//! \~\details
|
||||
//! \~english
|
||||
//! Stop execution of thread and wait for it finish
|
||||
//! if "wait" is \c true. This function can block for infinite
|
||||
//! time if "wait" is \c true and any of thread function is
|
||||
//! busy forever
|
||||
//! \~russian
|
||||
|
||||
/** \fn void terminate()
|
||||
* \brief Strongly stop thread
|
||||
* \details Stop execution of thread immediately */
|
||||
//! \fn void terminate()
|
||||
//! \~english Strongly stop thread
|
||||
//! \~russian Жестко останавливает поток
|
||||
//! \~\details
|
||||
//! \~english
|
||||
//! Stop execution of thread immediately
|
||||
//! \~russian
|
||||
|
||||
/** \fn bool waitForStart(int timeout_msecs = -1)
|
||||
* \brief Wait for thread start
|
||||
* \details This function block until thread start for "timeout_msecs"
|
||||
* or forever if "timeout_msecs" < 0
|
||||
*
|
||||
* \return \c false if timeout is exceeded */
|
||||
//! \fn bool waitForStart(int timeout_msecs = -1)
|
||||
//! \~english Wait for thread start
|
||||
//! \~russian Ожидает старта потока
|
||||
//! \~\details
|
||||
//! \~english
|
||||
//! This function block until thread start for "timeout_msecs"
|
||||
//! or forever if "timeout_msecs" < 0
|
||||
//! \return \c false if timeout is exceeded
|
||||
//! \~russian
|
||||
|
||||
/** \fn bool waitForFinish(int timeout_msecs = -1)
|
||||
* \brief Wait for thread finish
|
||||
* \details This function block until thread finish for "timeout_msecs"
|
||||
* or forever if "timeout_msecs" < 0
|
||||
*
|
||||
* \return \c false if timeout is exceeded */
|
||||
//! \fn bool waitForFinish(int timeout_msecs = -1)
|
||||
//! \~english Wait for thread finish
|
||||
//! \~russian Ожидает завершения потока
|
||||
//! \~\details
|
||||
//! \~english
|
||||
//! This function block until thread finish for "timeout_msecs"
|
||||
//! or forever if "timeout_msecs" < 0
|
||||
//! \return \c false if timeout is exceeded
|
||||
//! \~russian
|
||||
|
||||
//! \fn void lock()
|
||||
//! \brief Lock internal mutex
|
||||
|
||||
//! \~english Lock internal mutex
|
||||
//! \~russian Блокирует внутренний мьютекс
|
||||
|
||||
//! \fn void unlock()
|
||||
//! \brief Unlock internal mutex
|
||||
|
||||
//! \~english Unlock internal mutex
|
||||
//! \~russian Разблокирует внутренний мьютекс
|
||||
|
||||
//! \}
|
||||
//! \events
|
||||
//! \{
|
||||
|
||||
//! \fn void started()
|
||||
//! \brief Raise on thread start
|
||||
|
||||
//! \~english Raise on thread start
|
||||
//! \~russian Вызывается при старте потока
|
||||
|
||||
//! \fn void stopped()
|
||||
//! \brief Raise on thread stop
|
||||
|
||||
//! \~english Raise on thread stop
|
||||
//! \~russian Вызывается при завершении потока
|
||||
|
||||
//! \}
|
||||
|
||||
protected:
|
||||
static int priority2System(PIThread::Priority p);
|
||||
|
||||
//! Function executed once at the start of thread.
|
||||
//! \~english Function executed once at the start of thread
|
||||
//! \~russian Метод выполняется один раз при старте потока
|
||||
virtual void begin() {;}
|
||||
|
||||
//! Function executed at every "timer_delay" msecs until thread was stopped.
|
||||
//! \~english Function executed at every "timer_delay" msecs until thread was stopped
|
||||
//! \~russian Метод выполняется каждые "timer_delay" миллисекунд
|
||||
virtual void run() {;}
|
||||
|
||||
//! Function executed once at the end of thread.
|
||||
//! \~english Function executed once at the end of thread
|
||||
//! \~russian Метод выполняется один раз при остановке потока
|
||||
virtual void end() {;}
|
||||
|
||||
std::atomic_bool terminating, running_, lockRun;
|
||||
|
||||
Reference in New Issue
Block a user