29.07.2011 - fundamental new
This commit is contained in:
16
pithread.h
16
pithread.h
@@ -2,13 +2,13 @@
|
||||
#define PITHREAD_H
|
||||
|
||||
#include <pthread.h>
|
||||
#include "piincludes.h"
|
||||
#include <signal.h>
|
||||
#include "pimutex.h"
|
||||
|
||||
#ifdef WINDOWS
|
||||
inline void msleep(int msecs) {Sleep(msecs);}
|
||||
inline void msleep(int msecs) {Sleep(msecs);}
|
||||
#else
|
||||
inline void msleep(int msecs) {usleep(msecs * 1000);}
|
||||
inline void msleep(int msecs) {usleep(msecs * 1000);}
|
||||
#endif
|
||||
|
||||
class PIThread {
|
||||
@@ -31,13 +31,16 @@ public:
|
||||
#endif
|
||||
|
||||
bool start(int timer_delay = -1);
|
||||
void stop() {terminating = true;}
|
||||
bool startOnce();
|
||||
void stop(bool wait = false) {terminating = true; if (wait) waitForFinish();}
|
||||
void terminate() {kill(thread, SIGKILL); end(); running = false;}
|
||||
void setPriority(PIThread::Priority prior);
|
||||
PIThread::Priority priority() const {return priority_;}
|
||||
bool isRunning() const {return running;}
|
||||
void waitForFinish() {while (running) msleep(1);}
|
||||
bool waitForFinish(int timeout_msecs = -1);
|
||||
bool waitForStart(int timeout_msecs = -1);
|
||||
void needLockRun(bool need) {lockRun = need;}
|
||||
void lock() {mutex_.lock();;}
|
||||
void lock() {mutex_.lock();}
|
||||
void unlock() {mutex_.unlock();}
|
||||
PIMutex & mutex() {return mutex_;}
|
||||
|
||||
@@ -48,6 +51,7 @@ private:
|
||||
|
||||
protected:
|
||||
static void * thread_function(void * t);
|
||||
static void * thread_function_once(void * t);
|
||||
|
||||
volatile bool terminating, running, lockRun;
|
||||
int timer, policy;
|
||||
|
||||
Reference in New Issue
Block a user