The MAUVE Toolchain
Task.hpp
1 /*
2  * Copyright 2017 ONERA
3  *
4  * This file is part of the MAUVE Runtime project.
5  *
6  * MAUVE Runtime is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License version 3 as
8  * published by the Free Software Foundation.
9  *
10  * MAUVE Runtime is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with MAUVE. If not, see <https://www.gnu.org/licenses/lgpl-3.0>.
17  */
18 #ifndef MAUVE_RUNTIME_TASK_HPP
19 #define MAUVE_RUNTIME_TASK_HPP
20 
21 #include <mqueue.h>
22 #include <pthread.h>
23 #include <signal.h>
24 #include <iostream>
25 #include <string>
26 #include <atomic>
27 
28 #include "common.hpp"
29 
30 #define TASK_MQ_MAX_MSG 10
31 #define TASK_SIG SIGUSR1
32 
33 namespace mauve {
34  namespace runtime {
35 
36  class AbstractComponent;
37  class ComponentLogger;
38 
39  // ========================= Task =========================
40 
41  enum TaskStatus { CREATED, ACTIVATED, RUNNING };
42 
46  class Task final {
47 
48  public:
53  Task(AbstractComponent * component);
55  ~Task();
56 
62 
63  inline TaskStatus get_status() const { return status; }
64 
69  pthread_t thread_id() const;
74  time_ns_t get_time() const;
75 
80  bool activate();
87  bool start(time_ns_t start_time, pthread_barrier_t * barrier = nullptr);
92  bool stop();
93 
98  std::string to_string() const;
99 
100  protected:
103 
104  private:
105  static void *thread_start(void *data);
106 
107  void release();
108  void run();
109 
110  AbstractComponent * component;
111  std::atomic<TaskStatus> status;
112 
113  std::atomic<bool> finish;
114 
115  pthread_t pthread_id; // Useless
116  pthread_t pt_id; // Thread ID
117 
118  time_ns_t time;
119 
120  // barrier for configuration
121  pthread_barrier_t barrier;
122  // barrier for start
123  std::atomic<pthread_barrier_t *> start_barrier;
124 
125  // Signal
126  pid_t t_id;
127  struct sigevent sev;
128  timer_t timerid;
129  struct itimerspec its;
130 
131  }; /* class Task */
132 
133  }
134 } /* namespace mauve */
135 
136 #endif
Class of a MAUVE logger for a component.
Definition: logger.hpp:188
std::string to_string() const
Get a string representation of this task.
bool stop()
Stop the task.
bool start(time_ns_t start_time, pthread_barrier_t *barrier=nullptr)
Start the task.
~Task()
Task Destructor.
Task(AbstractComponent *component)
Create a task associated to a component.
AbstractComponent * get_component()
Get the component associated to this task.
The MAUVE namespace.
Definition: tracing.hpp:24
time_ns_t get_time() const
Get the clock of the task.
bool activate()
Activate the task.
pthread_t thread_id() const
Get the thread ID of this task.
ComponentLogger * logger
A pointer to a logger.
Definition: Task.hpp:102
Abstract Component class.
Definition: AbstractComponent.hpp:43
A system Task that executes a component.
Definition: Task.hpp:46