00001 /* 00002 * RealtimeThread.h 00003 * 00004 * Created on: Apr 26, 2009 00005 * Author: jgoppert 00006 */ 00007 00008 #ifndef REALTIMETHREAD_H_ 00009 #define REALTIMETHREAD_H_ 00010 00011 #include <stdio.h> 00012 #include <time.h> 00013 #include <unistd.h> 00014 #include <pthread.h> 00015 #include <stdlib.h> 00016 00017 namespace uvsim 00018 { 00019 00020 class RealtimeThread 00021 { 00022 private: 00023 pthread_t m_thread; 00024 static void *thread_func(void *d); 00025 int m_priority; 00026 long m_waitNSec; 00027 struct timespec m_time; 00028 struct sched_param m_sched; 00029 static const int m_nSecPerSec = 1000000000; 00030 volatile bool m_stopRequested; 00031 void run(); 00032 protected: 00033 virtual void loop() = 0; 00034 public: 00035 RealtimeThread(int priority, float freq); 00036 virtual ~RealtimeThread(); 00037 int start(); 00038 void stop(); 00039 int join(); 00040 }; 00041 00042 } 00043 00044 #endif /* REALTIMETHREAD_H_ */