ifw-core 7.0.0
 
Loading...
Searching...
No Matches
system.hpp
Go to the documentation of this file.
1
6
7#ifndef IFW_CORE_UTILS_SYSTEM_HPP_
8#define IFW_CORE_UTILS_SYSTEM_HPP_
9
10#include <string>
11#include <sys/sem.h>
12#include <pthread.h>
13#include <mutex>
14
15#include <rad/logger.hpp>
16
18
19
21
22 double _Time();
23
25 void Assert(const bool condition,
26 const std::string& message,
27 std::array<std::string, 3>& location);
28
30 void AssertPtr(const void* ptr,
31 const std::string& object,
32 std::array<std::string, 3>& location);
33
35 std::string Platform();
36
38 int64_t Random(const int64_t min_val,
39 const int64_t max_val);
40
42 //int32_t ExecuteCommand(const std::string& command,
43 // std::string& std_out,
44 // std::string& std_err);
45
47 std::string ExecCommand(const std::string& command);
48
70 class Mutex {
71 public:
73 static void Clear();
74
75 explicit Mutex(const std::string& id);
76
77 ~Mutex();
78
79 const std::string& Id() const;
80
81 void Lock();
82
83 void Unlock();
84
85 protected:
86
87 private:
88 static bool s_initialized;
89 static bool s_debug_mode;
90 static std::recursive_mutex s_gen_mutex;
91 static void _lock_gen_mutex();
92 static void _unlock_gen_mutex();
93
94 static std::map<std::string, std::shared_ptr<std::recursive_mutex> > s_mutexes;
95
96 std::recursive_mutex* m_cur_sem_ptr;
97 std::string m_id;
98 double m_timeout;
99 };
100
102#define BEGIN_CRIT_SEC(id) { \
103 ifw::core::utils::system::Mutex tmp_mutex(id); \
104
105
106#define END_CRIT_SEC(id) }
107
108}
109
110#endif // IFW_CORE_UTILS_SYSTEM_HPP_
const std::string & Id() const
Definition system.cpp:192
void Unlock()
Definition system.cpp:182
static void Clear()
Releases (deletes) all semaphores allocated. Use with caution!!
Definition system.cpp:166
void Lock()
Definition system.cpp:172
Mutex(const std::string &id)
Definition system.cpp:121
~Mutex()
Definition system.cpp:153
Definition system.hpp:20
std::string Platform()
Get the name of the platform (OS).
Definition system.cpp:46
void AssertPtr(const void *ptr, const std::string &object, std::array< std::string, 3 > &location)
Check if pointer is NULL. If yes, throw std::runtime_error.
Definition system.cpp:27
std::string ExecCommand(const std::string &command)
Execute a shell command (synchroneously).
Definition system.cpp:90
int64_t Random(const int64_t min_val, const int64_t max_val)
Generate an int64_t random number in the inteval specified.
Definition system.cpp:66
double _Time()
Definition system.cpp:38
void Assert(const bool condition, const std::string &message, std::array< std::string, 3 > &location)
Check if pointer is NULL. If yes, throw std::runtime_error.