distortos  v0.6.0
object-oriented C++ RTOS for microcontrollers
locking.hpp
Go to the documentation of this file.
1 
12 #ifndef INCLUDE_DISTORTOS_INTERNAL_NEWLIB_LOCKING_HPP_
13 #define INCLUDE_DISTORTOS_INTERNAL_NEWLIB_LOCKING_HPP_
14 
15 #include "distortos/Mutex.hpp"
16 
17 #include <sys/lock.h>
18 
19 #if defined(_RETARGETABLE_LOCKING)
20 
21 /*---------------------------------------------------------------------------------------------------------------------+
22 | global types
23 +---------------------------------------------------------------------------------------------------------------------*/
24 
26 struct __lock : public distortos::Mutex
27 {
28  using Mutex::Mutex;
29 };
30 
31 extern "C"
32 {
33 
34 /*---------------------------------------------------------------------------------------------------------------------+
35 | global objects
36 +---------------------------------------------------------------------------------------------------------------------*/
37 
38 extern __lock __lock___malloc_recursive_mutex;
39 
40 }; // extern "C"
41 
42 #endif // defined(_RETARGETABLE_LOCKING)
43 
44 namespace distortos
45 {
46 
47 namespace internal
48 {
49 
50 /*---------------------------------------------------------------------------------------------------------------------+
51 | global functions
52 +---------------------------------------------------------------------------------------------------------------------*/
53 
58 constexpr Mutex& getMallocMutex()
59 {
60 #if defined(_RETARGETABLE_LOCKING)
61 
62  return __lock___malloc_recursive_mutex;
63 
64 #else // !defined(_RETARGETABLE_LOCKING)
65 
67  return mallocMutexInstance;
68 
69 #endif // !defined(_RETARGETABLE_LOCKING)
70 }
71 
72 } // namespace internal
73 
74 } // namespace distortos
75 
76 #endif // INCLUDE_DISTORTOS_INTERNAL_NEWLIB_LOCKING_HPP_
Mutex class header.
Top-level namespace of distortos project.
Mutex is the basic synchronization primitive.
Definition: Mutex.hpp:30
constexpr Mutex(const Type type=Type::normal, const Protocol protocol=Protocol::none, const uint8_t priorityCeiling={})
Mutex&#39;s constructor.
Definition: Mutex.hpp:69
constexpr Mutex & getMallocMutex()
Definition: locking.hpp:58
Mutex mallocMutexInstance
main instance of Mutex used for malloc() and free() locking
Definition: locking.cpp:195