04.11.2011 - adjust for Windows & QNX, multiprotocol, repeater, signals, process, codec, console input
This commit is contained in:
19
pitimer.h
19
pitimer.h
@@ -6,7 +6,7 @@
|
||||
#include "pithread.h"
|
||||
#include "pistring.h"
|
||||
|
||||
typedef void (*TimerEvent)(void * );
|
||||
typedef void (*TimerEvent)(void * , int );
|
||||
|
||||
struct PITime {
|
||||
int seconds;
|
||||
@@ -30,7 +30,7 @@ public:
|
||||
~PITimer() {stop();}
|
||||
|
||||
void setData(void * data_) {data = data_;}
|
||||
void setSlot(TimerEvent slot_) {ret_func = slot_;}
|
||||
void setSlot(TimerEvent slot) {ret_func = slot;}
|
||||
#ifdef WINDOWS
|
||||
void reset() {t_st = GetCurrentTime();}
|
||||
#else
|
||||
@@ -42,6 +42,12 @@ public:
|
||||
void lock() {mutex_.lock();}
|
||||
void unlock() {mutex_.unlock();}
|
||||
#endif
|
||||
void addDelimiter(int delim, TimerEvent slot = 0) {ret_funcs << TimerSlot(slot, delim);}
|
||||
void removeDelimiter(int delim) {for (int i = 0; i < ret_funcs.size_s(); ++i) if (ret_funcs[i].delim == delim) {ret_funcs.remove(i); i--;}}
|
||||
void removeDelimiter(TimerEvent slot) {for (int i = 0; i < ret_funcs.size_s(); ++i) if (ret_funcs[i].slot == slot) {ret_funcs.remove(i); i--;}}
|
||||
void removeDelimiter(int delim, TimerEvent slot) {for (int i = 0; i < ret_funcs.size_s(); ++i) if (ret_funcs[i].slot == slot && ret_funcs[i].delim == delim) {ret_funcs.remove(i); i--;}}
|
||||
void clearDelimiters() {ret_funcs.clear();}
|
||||
|
||||
double elapsed_n(); // nanoseconds
|
||||
double elapsed_u(); // microseconds
|
||||
double elapsed_m(); // miliseconds
|
||||
@@ -49,7 +55,7 @@ public:
|
||||
|
||||
private:
|
||||
#ifdef WINDOWS
|
||||
void run() {if (ret_func != 0) ret_func(data);}
|
||||
void run();
|
||||
|
||||
long int t_st, t_cur;
|
||||
#else
|
||||
@@ -64,9 +70,16 @@ private:
|
||||
timer_t timer;
|
||||
sigevent se;
|
||||
#endif
|
||||
struct TimerSlot {
|
||||
TimerSlot(TimerEvent slot_ = 0, int delim_ = 1) {slot = slot_; delim = delim_; tick = 0;}
|
||||
TimerEvent slot;
|
||||
int delim;
|
||||
int tick;
|
||||
};
|
||||
|
||||
void * data;
|
||||
TimerEvent ret_func;
|
||||
PIVector<TimerSlot> ret_funcs;
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user