diff options
| author | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
|---|---|---|
| committer | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
| commit | 33613a85afc4b1481367fbe92a17ee59c240250b (patch) | |
| tree | 670b842326116b376b505ec2263878912fca97e2 /Master/Real-Time Systems/RTS_A8/src/Task.cpp | |
| download | Studium-master.tar.gz Studium-master.tar.bz2 | |
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); +} |
