F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
Task.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title Os/Posix/Task.hpp
3 // \brief definitions of Posix implementation of Os::Task
4 // ======================================================================
5 #ifndef Os_Posix_Task_hpp_
6 #define Os_Posix_Task_hpp_
7 
8 #include <pthread.h>
9 #include <Os/Task.hpp>
10 #include <atomic>
11 
12 #include <Fw/Deprecate.hpp>
13 #include <Fw/FPrimeBasicTypes.hpp>
15 #include <Os/Mutex.hpp>
17 #include <Os/TaskString.hpp>
18 
19 namespace Os {
20 namespace Posix {
21 namespace Task {
22 
25 struct PosixTaskHandle : public TaskHandle {
26  static constexpr FwSizeType PTHREAD_NAME_LENGTH = 16;
27  static constexpr int SUCCESS = 0;
28 
30  pthread_t m_task_descriptor;
32  bool m_is_valid = false;
33 #if defined(POSIX_THREADS_ENABLE_NAMES) && POSIX_THREADS_ENABLE_NAMES
35 #endif
36 };
37 
39 class PosixTask : public TaskInterface {
40  public:
45  };
46 
51  "TASK_PRIORITY_NON_REALTIME must not alias TASK_PRIORITY_DEFAULT");
52 
54  PosixTask() = default;
55 
57  ~PosixTask() = default;
58 
60  PosixTask(const PosixTask& other) = delete;
61 
63  PosixTask& operator=(const PosixTask& other) = delete;
64 
66  void onStart() override;
67 
73  //
78  Status start(const Arguments& arguments) override;
79 
86  Status join() override;
87 
95  void suspend(SuspensionType suspensionType) override;
96 
101  void resume() override;
102 
110  Status _delay(const Fw::TimeInterval& interval) override;
111 
114  TaskHandle* getHandle() override;
115 
116  private:
125  Status create(const Os::Task::Arguments& arguments, const PosixTask::PermissionExpectation permissions);
126 
127  PosixTaskHandle m_handle;
128  static std::atomic<bool> s_permissions_reported;
129 };
130 } // end namespace Task
131 } // end namespace Posix
132 } // end namespace Os
133 #endif
Status _delay(const Fw::TimeInterval &interval) override
delay the current task
Definition: Task.cpp:273
Task handle representation.
Definition: Task.hpp:33
PlatformSizeType FwSizeType
~PosixTask()=default
default virtual destructor
static constexpr FwTaskPriorityType TASK_PRIORITY_NON_REALTIME
Sentinel priority: run the task under SCHED_OTHER (non-realtime) rather than SCHED_RR.
Definition: Task.hpp:48
void suspend(SuspensionType suspensionType) override
suspend the task given the suspension type
Definition: Task.cpp:265
static constexpr int SUCCESS
Definition: Task.hpp:27
static constexpr FwTaskPriorityType TASK_PRIORITY_DEFAULT
Definition: Task.hpp:47
PosixTask & operator=(const PosixTask &other)=delete
assignment operator is forbidden
bool m_is_valid
Is the above descriptor valid.
Definition: Task.hpp:32
PermissionExpectation
Enumeration of permission expectations.
Definition: Task.hpp:42
pthread_t m_task_descriptor
Posix task descriptor.
Definition: Task.hpp:30
TaskHandle * getHandle() override
return the underlying task handle (implementation specific)
Definition: Task.cpp:259
static constexpr FwSizeType PTHREAD_NAME_LENGTH
Length of pthread name.
Definition: Task.hpp:26
PosixTask()=default
default constructor
PlatformTaskPriorityType FwTaskPriorityType
The type of task priorities used.
Expect that you do not hold necessary permissions.
Definition: Task.hpp:44
Expect that you hold necessary permissions.
Definition: Task.hpp:43
Status join() override
block until the task has ended
Definition: Task.cpp:248
Status start(const Arguments &arguments) override
start the task
Definition: Task.cpp:218
void resume() override
resume a suspended task
Definition: Task.cpp:269
void onStart() override
perform required task start actions
Definition: Task.cpp:216
Posix task implementation as driven by pthreads implementation.
Definition: Task.hpp:39