F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
DefaultTask.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title Os/Posix/DefaultTask.cpp
3 // \brief sets default Os::Task to posix implementation via linker
4 // ======================================================================
5 #include <cerrno>
6 #include "Os/Task.hpp"
7 #include "Os/Posix/Task.hpp"
8 #include "Os/Delegate.hpp"
9 
10 namespace Os {
12  Os::Task::Status task_status = Os::Task::OP_OK;
13  timespec sleep_interval;
14  sleep_interval.tv_sec = interval.getSeconds();
15  sleep_interval.tv_nsec = interval.getUSeconds() * 1000;
16 
17  timespec remaining_interval;
18  remaining_interval.tv_sec = 0;
19  remaining_interval.tv_nsec = 0;
20 
21  while (true) {
22  PlatformIntType status = nanosleep(&sleep_interval, &remaining_interval);
23  // Success, return ok
24  if (0 == status) {
25  break;
26  }
27  // Interrupted, reset sleep and iterate
28  else if (EINTR == errno) {
29  sleep_interval = remaining_interval;
30  continue;
31  }
32  // Anything else is an error
33  else {
34  task_status = Os::Task::Status::DELAY_ERROR;
35  break;
36  }
37  }
38  return task_status;
39  }
40 
42  return Os::Delegate::makeDelegate<TaskInterface, Os::Posix::Task::PosixTask>(aligned_new_memory);
43  }
44 
45 }
int PlatformIntType
DefaultTypes.hpp provides fallback defaults for the platform types.
U8 HandleStorage[FW_HANDLE_MAX_SIZE]
Storage type for OSAL handles.
Definition: Os.hpp:10
Definition: Time.hpp:9
U32 getUSeconds() const
Definition: Time.cpp:139
U32 getSeconds() const
Definition: Time.cpp:135
static TaskInterface * getDelegate(HandleStorage &aligned_placement_new_memory)
provide a pointer to a task delegate object
Definition: DefaultTask.cpp:41
@ OP_OK
message sent/received okay
Definition: Task.hpp:30
static Status delay(Fw::Time interval)
delay the current task
Definition: DefaultTask.cpp:11