29.07.2011 - fundamental new
This commit is contained in:
16
pitimer.h
16
pitimer.h
@@ -4,6 +4,7 @@
|
||||
#include <ctime>
|
||||
#include <csignal>
|
||||
#include "pithread.h"
|
||||
#include "pistring.h"
|
||||
|
||||
typedef void (*TimerEvent)(void * );
|
||||
|
||||
@@ -20,20 +21,23 @@ struct PIDate {
|
||||
};
|
||||
|
||||
class PITimer
|
||||
#ifdef __WIN32__
|
||||
#ifdef WINDOWS
|
||||
: public PIThread
|
||||
#endif
|
||||
{
|
||||
public:
|
||||
PITimer(TimerEvent slot = 0, void * data = 0);
|
||||
~PITimer() {stop();}
|
||||
#ifdef __WIN32__
|
||||
#ifdef WINDOWS
|
||||
void reset() {t_st = GetCurrentTime();}
|
||||
#else
|
||||
void reset() {clock_gettime(0, &t_st);}
|
||||
void start(double msecs);
|
||||
void stop() {if (ti == 0) timer_delete(timer); ti = -1; running = false;}
|
||||
bool isRunning() const {return running;}
|
||||
void needLockRun(bool need) {lockRun = need;}
|
||||
void lock() {mutex_.lock();}
|
||||
void unlock() {mutex_.unlock();}
|
||||
#endif
|
||||
double elapsed_n(); // nanoseconds
|
||||
double elapsed_u(); // microseconds
|
||||
@@ -41,7 +45,7 @@ public:
|
||||
double elapsed_s(); // seconds
|
||||
|
||||
private:
|
||||
#ifdef __WIN32__
|
||||
#ifdef WINDOWS
|
||||
void run() {if (ret_func != 0) ret_func(data);}
|
||||
|
||||
long int t_st, t_cur;
|
||||
@@ -49,6 +53,8 @@ private:
|
||||
static void timer_event(sigval e);
|
||||
|
||||
bool running;
|
||||
volatile bool lockRun;
|
||||
PIMutex mutex_;
|
||||
int ti;
|
||||
itimerspec spec;
|
||||
timespec t_st, t_cur;
|
||||
@@ -63,7 +69,7 @@ private:
|
||||
|
||||
PITime currentTime();
|
||||
PIDate currentDate();
|
||||
string time2string(const PITime & time, const string & format = "h:m:s");
|
||||
string date2string(const PIDate & date, const string & format = "d.m.y");
|
||||
PIString time2string(const PITime & time, const PIString & format = "h:mm:ss");
|
||||
PIString date2string(const PIDate & date, const PIString & format = "d.mm.yyyy");
|
||||
|
||||
#endif // PITIMER_H
|
||||
|
||||
Reference in New Issue
Block a user