From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- Master/Real-Time Systems/RTS_A8/src/Task.cpp | 51 ++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Master/Real-Time Systems/RTS_A8/src/Task.cpp (limited to 'Master/Real-Time Systems/RTS_A8/src/Task.cpp') 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 +#include +#include +#include + +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); +} -- cgit v1.2.3