00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __RTCLOCK_H__
00022 #define __RTCLOCK_H__
00023
00024
00025 #include <pthread.h>
00026
00027
00028
00029
00030
00031
00032
00033 class RTClock {
00034 public:
00035 RTClock();
00036 ~RTClock();
00037
00038 int init();
00039
00040 int set_freq(unsigned long freq);
00041
00042 int start();
00043
00044 void run();
00045
00046 int sleep(uint64_t sec);
00047
00048 bool quit;
00049
00050 uint64_t msec;
00051
00052 private:
00053
00054 int tick();
00055
00056 int rtcfd;
00057 unsigned long rtctime;
00058
00059 pthread_t _thread;
00060 pthread_attr_t _attr;
00061
00062 pthread_mutex_t _mutex;
00063 pthread_cond_t _cond;
00064
00065 void lock() { pthread_mutex_lock(&_mutex); };
00066 void unlock() { pthread_mutex_unlock(&_mutex); };
00067
00068
00069 void wait() { pthread_cond_wait(&_cond,&_mutex); };
00070 void signal() { pthread_cond_signal(&_cond); };
00071
00072 bool sleeping;
00073
00074 protected:
00075
00076 static void* kickoff(void *arg) {
00077 ((RTClock *) arg)->run();
00078 return NULL;
00079 };
00080
00081 };
00082
00083
00084
00085 #endif