OpenDDS  Snapshot(2023/04/28-20:55)
SafetyProfilePool.h
Go to the documentation of this file.
1 /*
2  *
3  *
4  * Distributed under the OpenDDS License.
5  * See: http://www.opendds.org/license.html
6  */
7 
8 #ifndef OPENDDS_DCPS_SAFETY_PROFILE_POOL_H
9 #define OPENDDS_DCPS_SAFETY_PROFILE_POOL_H
10 
11 #include "ace/Malloc_Base.h"
12 #include /**/ "dds/Versioned_Namespace.h"
13 
14 #ifdef OPENDDS_SAFETY_PROFILE
15 #include "ace/Atomic_Op.h"
16 #include "ace/Singleton.h"
17 #include "dcps_export.h"
18 #include "MemoryPool.h"
19 
20 #include <cstring>
21 
22 class SafetyProfilePoolTest;
23 
25 
26 namespace OpenDDS {
27 namespace DCPS {
28 
29 /// Memory pool for use when the Safety Profile is enabled.
30 ///
31 /// Safety Profile disallows std::free() and the delete operators
32 /// See PoolAllocator.h for a class that allows STL containers to use an
33 /// instance of SafetyProfilePool managed by our Service_Participant singleton.
35 {
36  friend class SafetyProfilePoolTest;
37 public:
40 
41  void configure_pool(size_t size, size_t granularity);
42  void install();
43 
44  void* malloc(std::size_t size)
45  {
47  return main_pool_->pool_alloc(size);
48  }
49 
50  void free(void* ptr)
51  {
53  main_pool_->pool_free(ptr);
54  }
55 
56  void* calloc(std::size_t bytes, char init = '\0')
57  {
58  void* const mem = malloc(bytes);
59  std::memset(mem, init, bytes);
60  return mem;
61  }
62 
63  void* calloc(std::size_t elems, std::size_t size, char init = '\0')
64  {
65  return calloc(elems * size, init);
66  }
67 
68  int remove() { return -1; }
69  int bind(const char*, void*, int = 0) { return -1; }
70  int trybind(const char*, void*&) { return -1; }
71  int find(const char*, void*&) { return -1; }
72  int find(const char*) { return -1; }
73  int unbind(const char*, void*&) { return -1; }
74  int unbind(const char*) { return -1; }
75  int sync(ssize_t = -1, int = MS_SYNC) { return -1; }
76  int sync(void*, size_t, int = MS_SYNC) { return -1; }
77  int protect(ssize_t = -1, int = PROT_RDWR) { return -1; }
78  int protect(void*, size_t, int = PROT_RDWR) { return -1; }
79  void dump() const {}
80 
81  /// Return a singleton instance of this class.
82  static SafetyProfilePool* instance();
83 
84 private:
86  SafetyProfilePool& operator=(const SafetyProfilePool&);
87 
88  MemoryPool* main_pool_;
90  static SafetyProfilePool* instance_;
91  friend class InstanceMaker;
92 };
93 
94 }}
95 
97 
98 #else // ! OPENDDS_SAFETY_PROFILE
99 
101 
102 namespace OpenDDS {
103 namespace DCPS {
105 }
106 }
107 
109 
110 #endif // OPENDDS_SAFETY_PROFILE
111 
112 #endif // OPENDDS_DCPS_SAFETY_PROFILE_POOL_H
#define ACE_GUARD(MUTEX, OBJ, LOCK)
void free(void *)
void * calloc(size_t elements, size_t sizeof_elements)
int bind(Container &c, const FirstType &first, const SecondType &second)
Definition: Util.h:20
#define OpenDDS_Dcps_Export
Definition: dcps_export.h:24
int ssize_t
ACE_Guard< ACE_Thread_Mutex > lock_
void * malloc(size_t)
#define ACE_GUARD_RETURN(MUTEX, OBJ, LOCK, RETURN)
ACE_Allocator SafetyProfilePool
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28
int unbind(Container &c, const typename Container::key_type &k, typename Container::mapped_type &v)
Definition: Util.h:40
int find(Container &c, const Key &key, typename Container::mapped_type *&value)
Definition: Util.h:71