mn_singleton.hpp
Go to the documentation of this file.
1 
19 #ifndef MINLIB_ESP32_SINGLETON_H_
20 #define MINLIB_ESP32_SINGLETON_H_
21 
22 #include "mn_config.hpp"
23 
24 #include "mn_autolock.hpp"
25 #include "mn_copyable.hpp"
26 #include "mn_pointer.hpp"
27 
28 namespace mn {
29 
30  template < typename T, class TLOCK = LockType_t>
32  public:
33  using value_type = T;
35  using lock_t = TLOCK;
36  using pointer = T*;
38 
39  basic_singleton(this_type&& other) = delete;
40  basic_singleton(const this_type&) = delete;
41 
42  static reference instance() {
44 
45  if( m_ptr == 0 ) {
46  m_ptr = new T();
47  }
48  return *m_ptr;
49  }
50  void operator=(const this_type&) = delete;
51  protected:
53  private:
54  static pointer m_ptr;
55  static lock_t m_tLock;
56  };
57  template < typename T, class TLOCK >
59 
60  template < typename T, class TLOCK >
62 
63 }
64 
65 #endif
Definition: mn_lock.hpp:122
Definition: mn_singleton.hpp:31
basic_singleton(const this_type &)=delete
basic_singleton()
Definition: mn_singleton.hpp:52
T value_type
Definition: mn_singleton.hpp:33
void operator=(const this_type &)=delete
static lock_t m_tLock
Definition: mn_singleton.hpp:55
basic_singleton(this_type &&other)=delete
static pointer m_ptr
Definition: mn_singleton.hpp:54
TLOCK lock_t
Definition: mn_singleton.hpp:35
T * pointer
Definition: mn_singleton.hpp:36
static reference instance()
Definition: mn_singleton.hpp:42
value_type & reference
Definition: mn_singleton.hpp:34
struct mn::memory::detail::ptr_difference T
Definition: mn_atomic_singleton.hpp:38
Definition: mn_allocator_typetraits.hpp:25
int lock(TLOCK &m1, unsigned int timeout)
Definition: mn_autolock.hpp:70