05.11.2011 - stable version, 0.1.0, self-test program, work at GCC 2.95 - 4.5, VC 2010, MinGW, Linux, Windows, QNX
This commit is contained in:
25
pithread.h
25
pithread.h
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <signal.h>
|
||||
#include "pimutex.h"
|
||||
#include "piobject.h"
|
||||
|
||||
#ifdef WINDOWS
|
||||
inline void msleep(int msecs) {Sleep(msecs);}
|
||||
@@ -10,7 +11,7 @@ inline void msleep(int msecs) {Sleep(msecs);}
|
||||
inline void msleep(int msecs) {usleep(msecs * 1000);}
|
||||
#endif
|
||||
|
||||
class PIThread {
|
||||
class PIThread: public PIObject {
|
||||
public:
|
||||
PIThread(bool startNow = false, int timer_delay = -1);
|
||||
~PIThread();
|
||||
@@ -29,18 +30,24 @@ public:
|
||||
piLowerst = 2 };
|
||||
#endif
|
||||
|
||||
bool start(int timer_delay = -1);
|
||||
bool startOnce();
|
||||
void stop(bool wait = false) {terminating = true; if (wait) waitForFinish();}
|
||||
void terminate(bool hard = false);
|
||||
//bool start(int timer_delay = -1);
|
||||
EVENT_HANDLER0(PIThread, bool, start) {return start(-1);}
|
||||
EVENT_HANDLER1(PIThread, bool, start, int, timer_delay);
|
||||
EVENT_HANDLER0(PIThread, bool, startOnce);
|
||||
EVENT_HANDLER0(PIThread, void, stop) {stop(false);}
|
||||
EVENT_HANDLER1(PIThread, void, stop, bool, wait) {terminating = true; if (wait) waitForFinish();}
|
||||
EVENT_HANDLER0(PIThread, void, terminate) {terminate(false);}
|
||||
EVENT_HANDLER1(PIThread, void, terminate, bool, hard);
|
||||
void setPriority(PIThread::Priority prior);
|
||||
PIThread::Priority priority() const {return priority_;}
|
||||
bool isRunning() const {return running;}
|
||||
bool waitForFinish(int timeout_msecs = -1);
|
||||
bool waitForStart(int timeout_msecs = -1);
|
||||
EVENT_HANDLER0(PIThread, bool, waitForFinish) {return waitForFinish(-1);}
|
||||
EVENT_HANDLER1(PIThread, bool, waitForFinish, int, timeout_msecs);
|
||||
EVENT_HANDLER0(PIThread, bool, waitForStart) {return waitForStart(-1);}
|
||||
EVENT_HANDLER1(PIThread, bool, waitForStart, int, timeout_msecs);
|
||||
void needLockRun(bool need) {lockRun = need;}
|
||||
void lock() {mutex_.lock();}
|
||||
void unlock() {mutex_.unlock();}
|
||||
EVENT_HANDLER0(PIThread, void, lock) {mutex_.lock();}
|
||||
EVENT_HANDLER0(PIThread, void, unlock) {mutex_.unlock();}
|
||||
PIMutex & mutex() {return mutex_;}
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user