summaryrefslogtreecommitdiffstats
path: root/Master/Real-Time Systems/RTS_A8/src/Task.cpp
diff options
context:
space:
mode:
authorSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
committerSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
commit33613a85afc4b1481367fbe92a17ee59c240250b (patch)
tree670b842326116b376b505ec2263878912fca97e2 /Master/Real-Time Systems/RTS_A8/src/Task.cpp
downloadStudium-master.tar.gz
Studium-master.tar.bz2
add new repoHEADmaster
Diffstat (limited to 'Master/Real-Time Systems/RTS_A8/src/Task.cpp')
-rw-r--r--Master/Real-Time Systems/RTS_A8/src/Task.cpp51
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);
+}