diff options
Diffstat (limited to 'Master/Real-Time Systems/RTS_A8/src/Task.cpp')
| -rw-r--r-- | Master/Real-Time Systems/RTS_A8/src/Task.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/Master/Real-Time Systems/RTS_A8/src/Task.cpp b/Master/Real-Time Systems/RTS_A8/src/Task.cpp new file mode 100644 index 0000000..e0bce66 --- /dev/null +++ b/Master/Real-Time Systems/RTS_A8/src/Task.cpp @@ -0,0 +1,51 @@ +/* + * Task.cpp + * + * Created on: 30.11.2010 + * Author: istsveise + */ + +#include "Task.h" +#include <pthread.h> +#include <iostream> +#include <sys/time.h> +#include <signal.h> + +using namespace std; + +void* timer_main(void* task) { + Task* t = (Task*) task; + while(true) { + usleep(t->T*1000); + sem_post(&t->threadSem); + } + return NULL; +} + +void* execute_main(void* task) { + cout << "Start execution..." << endl; + Task* t = (Task*) task; + t->execute(); + + return NULL; +} + +Task::Task(int t=1000) +:T(t) +{ + sem_init(&this->threadSem,0,0); + + pthread_t timerthread; + pthread_t executethread; + + pthread_create(&timerthread,NULL,&timer_main,(void*) this); + pthread_create(&executethread,NULL,&execute_main,(void*) this); +} + +Task::~Task() { +} + +void Task::waitForNextCycle() +{ + sem_wait(&this->threadSem); +} |
