F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
Cpu.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title Os/Cpu.hpp
3 // \brief common function definitions for Os::Cpu
4 // ======================================================================
5 #include "Os/Os.hpp"
6 
7 #ifndef OS_CPU_HPP_
8 #define OS_CPU_HPP_
9 
10 namespace Os {
11 
13 class CpuHandle {};
14 
16 class CpuInterface {
17  public:
20 
22  CpuInterface() = default;
24  virtual ~CpuInterface() = default;
25 
27  CpuInterface(const CpuInterface& other) = delete;
28 
30  virtual CpuInterface& operator=(const CpuInterface& other) = delete;
31 
37  virtual Status _getCount(FwSizeType & cpu_count) = 0;
38 
49  virtual Status _getTicks(Ticks& ticks, FwSizeType cpu_index) = 0;
50 
53  virtual CpuHandle* getHandle() = 0;
54 
56  static CpuInterface* getDelegate(CpuHandleStorage& aligned_new_memory);
57 };
58 
60 class Cpu final : public CpuInterface {
61  public:
63  Cpu();
64 
66  ~Cpu() final;
67 
69  Cpu(const CpuInterface& other) = delete;
70 
72  Cpu(const CpuInterface* other) = delete;
73 
75  CpuInterface& operator=(const CpuInterface& other) override = delete;
76 
77  //-----------------------------------------------------------------------------
78  // Interface methods
79  //-----------------------------------------------------------------------------
80 
82  static void init();
83 
85  static Cpu& getSingleton();
86 
87  //-----------------------------------------------------------------------------
88  // Delegating methods
89  //-----------------------------------------------------------------------------
90 
98  Status _getCount(FwSizeType& cpu_count) override;
99 
111  Status _getTicks(Ticks& ticks, FwSizeType cpu_index) override;
112 
115  CpuHandle* getHandle() override;
116 
117  //-----------------------------------------------------------------------------
118  // Static interface (singleton) methods
119  //-----------------------------------------------------------------------------
120 
128  static Status getCount(FwSizeType& cpu_count);
129 
141  static Status getTicks(Ticks& ticks, FwSizeType cpu_index);
142 
143  private:
144 
145  // This section is used to store the implementation-defined file handle. To Os::File and fprime, this type is
146  // opaque and thus normal allocation cannot be done. Instead, we allow the implementor to store then handle in
147  // the byte-array here and set `handle` to that address for storage.
148  alignas(FW_HANDLE_ALIGNMENT) CpuHandleStorage m_handle_storage;
149  CpuInterface& m_delegate;
150 };
151 }
152 #endif //OS_CONDITION_HPP_
#define FW_HANDLE_ALIGNMENT
Alignment of handle storage.
Definition: FpConfig.h:440
PlatformSizeType FwSizeType
Definition: FpConfig.h:35
U8 CpuHandleStorage[FW_CPU_HANDLE_MAX_SIZE]
Definition: Os.hpp:18
Cpu variable handle parent.
Definition: Cpu.hpp:13
cpu implementation
Definition: Cpu.hpp:60
CpuInterface & operator=(const CpuInterface &other) override=delete
assignment operator is forbidden
static void init()
initialize the singleton
Definition: Cpu.cpp:16
Cpu(const CpuInterface &other)=delete
copy constructor is forbidden
CpuHandle * getHandle() override
return the underlying cpu handle (implementation specific).
Definition: Cpu.cpp:35
Status _getCount(FwSizeType &cpu_count) override
Request the count of the CPUs detected by the system.
Definition: Cpu.cpp:25
Cpu(const CpuInterface *other)=delete
copy constructor is forbidden
Status _getTicks(Ticks &ticks, FwSizeType cpu_index) override
Get the CPU tick information for a given CPU.
Definition: Cpu.cpp:30
~Cpu() final
default virtual destructor
Definition: Cpu.cpp:12
static Status getTicks(Ticks &ticks, FwSizeType cpu_index)
Get the CPU tick information for a given CPU.
Definition: Cpu.cpp:44
static Cpu & getSingleton()
return singleton
Definition: Cpu.cpp:20
Cpu()
default constructor
Definition: Cpu.cpp:10
static Status getCount(FwSizeType &cpu_count)
Request the count of the CPUs detected by the system.
Definition: Cpu.cpp:40
interface for cpu implementation
Definition: Cpu.hpp:16
virtual Status _getCount(FwSizeType &cpu_count)=0
Request the count of the CPUs detected by the system.
virtual CpuInterface & operator=(const CpuInterface &other)=delete
assignment operator is forbidden
virtual Status _getTicks(Ticks &ticks, FwSizeType cpu_index)=0
Get the CPU tick information for a given CPU.
CpuInterface(const CpuInterface &other)=delete
copy constructor is forbidden
CpuInterface()=default
Default constructor.
static CpuInterface * getDelegate(CpuHandleStorage &aligned_new_memory)
provide a pointer to a Mutex delegate object
Definition: DefaultCpu.cpp:10
virtual ~CpuInterface()=default
Default destructor.
virtual CpuHandle * getHandle()=0
return the underlying cpu handle (implementation specific).
Status
Generic OK/ERROR status.
Definition: Os.hpp:25
Generic used/total struct.
Definition: Os.hpp:31