SafetyProfilePool.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef OPENDDS_DCPS_SAFETY_PROFILE_POOL_H
00009 #define OPENDDS_DCPS_SAFETY_PROFILE_POOL_H
00010
00011 #include "ace/Malloc_Base.h"
00012 #include "dds/Versioned_Namespace.h"
00013
00014 #ifdef OPENDDS_SAFETY_PROFILE
00015 #include "ace/Atomic_Op.h"
00016 #include "ace/Singleton.h"
00017 #include "dcps_export.h"
00018 #include "MemoryPool.h"
00019
00020 #include <cstring>
00021
00022 class SafetyProfilePoolTest;
00023
00024 OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
00025
00026 namespace OpenDDS {
00027 namespace DCPS {
00028
00029
00030
00031
00032
00033
00034 class OpenDDS_Dcps_Export SafetyProfilePool : public ACE_Allocator
00035 {
00036 friend class SafetyProfilePoolTest;
00037 public:
00038 SafetyProfilePool();
00039 ~SafetyProfilePool();
00040
00041 void configure_pool(size_t size, size_t granularity);
00042 void install();
00043
00044 void* malloc(std::size_t size)
00045 {
00046 ACE_GUARD_RETURN(ACE_Thread_Mutex, lock, lock_, 0);
00047 return main_pool_->pool_alloc(size);
00048 }
00049
00050 void free(void* ptr)
00051 {
00052 ACE_GUARD(ACE_Thread_Mutex, lock, lock_);
00053 main_pool_->pool_free(ptr);
00054 }
00055
00056 void* calloc(std::size_t bytes, char init = '\0')
00057 {
00058 void* const mem = malloc(bytes);
00059 std::memset(mem, init, bytes);
00060 return mem;
00061 }
00062
00063 void* calloc(std::size_t elems, std::size_t size, char init = '\0')
00064 {
00065 return calloc(elems * size, init);
00066 }
00067
00068 int remove() { return -1; }
00069 int bind(const char*, void*, int = 0) { return -1; }
00070 int trybind(const char*, void*&) { return -1; }
00071 int find(const char*, void*&) { return -1; }
00072 int find(const char*) { return -1; }
00073 int unbind(const char*, void*&) { return -1; }
00074 int unbind(const char*) { return -1; }
00075 int sync(ssize_t = -1, int = MS_SYNC) { return -1; }
00076 int sync(void*, size_t, int = MS_SYNC) { return -1; }
00077 int protect(ssize_t = -1, int = PROT_RDWR) { return -1; }
00078 int protect(void*, size_t, int = PROT_RDWR) { return -1; }
00079 void dump() const {}
00080
00081
00082 static SafetyProfilePool* instance();
00083
00084 private:
00085 SafetyProfilePool(const SafetyProfilePool&);
00086 SafetyProfilePool& operator=(const SafetyProfilePool&);
00087
00088 MemoryPool* main_pool_;
00089 ACE_Thread_Mutex lock_;
00090 static SafetyProfilePool* instance_;
00091 friend class InstanceMaker;
00092 };
00093
00094 }}
00095
00096 OPENDDS_END_VERSIONED_NAMESPACE_DECL
00097
00098 #else // ! OPENDDS_SAFETY_PROFILE
00099
00100 OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
00101
00102 namespace OpenDDS {
00103 namespace DCPS {
00104 typedef ACE_Allocator SafetyProfilePool;
00105 }
00106 }
00107
00108 OPENDDS_END_VERSIONED_NAMESPACE_DECL
00109
00110 #endif // OPENDDS_SAFETY_PROFILE
00111
00112 #endif // OPENDDS_DCPS_SAFETY_PROFILE_POOL_H