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