diff options
author | schmidt <douglascraigschmidt@users.noreply.github.com> | 1999-07-07 05:42:03 +0000 |
---|---|---|
committer | schmidt <douglascraigschmidt@users.noreply.github.com> | 1999-07-07 05:42:03 +0000 |
commit | 81a825bad180e2b8f3c3bf27a4f8d1cc071d2a39 (patch) | |
tree | f3961ecb0a771c015bbca524252cf96b3725d9eb /ace | |
parent | 1e199c0d09e61730bddca859fd7c9262328746fa (diff) | |
download | ATCD-81a825bad180e2b8f3c3bf27a4f8d1cc071d2a39.tar.gz |
ChangeLogTag:Wed Jul 7 00:37:22 1999 Douglas C. Schmidt <schmidt@tango.cs.wustl.edu>
Diffstat (limited to 'ace')
-rw-r--r-- | ace/Based_Pointer_T.cpp (renamed from ace/Based_Pointer_Repository_T.cpp) | 14 | ||||
-rw-r--r-- | ace/Based_Pointer_T.h (renamed from ace/Based_Pointer_Repository_T.h) | 35 | ||||
-rw-r--r-- | ace/Makefile | 2 | ||||
-rw-r--r-- | ace/Makefile.bor | 1 | ||||
-rw-r--r-- | ace/Malloc.h | 23 | ||||
-rw-r--r-- | ace/Memory_Pool.cpp | 49 | ||||
-rw-r--r-- | ace/Memory_Pool.h | 9 | ||||
-rw-r--r-- | ace/Memory_Pool.i | 4 |
8 files changed, 88 insertions, 49 deletions
diff --git a/ace/Based_Pointer_Repository_T.cpp b/ace/Based_Pointer_T.cpp index ebf9cac28ba..f8c6717889e 100644 --- a/ace/Based_Pointer_Repository_T.cpp +++ b/ace/Based_Pointer_T.cpp @@ -1,21 +1,21 @@ // $Id$ -#if !defined (ACE_BASED_POINTER_REPOSITORY_T_CPP) -#define ACE_BASED_POINTER_REPOSITORY_T_CPP +#if !defined (ACE_BASED_POINTER_T_CPP) +#define ACE_BASED_POINTER_T_CPP #include "ace/Based_Pointer_Repository.h" -#include "ace/Based_Pointer_Repository_T.h" +#include "ace/Based_Pointer_T.h" template <class CONCRETE> ACE_Based_Pointer<CONCRETE>::ACE_BasedPointer (void) : target_ (0), base_offset_ (0) { - // Find the base address associated with our <this> pointer. + // Find the base address associated with our <this> pointer. Note + // that it's ok for <find> to return 0, which simply indicates that + // the address is not in memory-mapped virtual address space. void *base_addr = ACE_BASED_POINTER_REPOSITORY::instance ()->find (this); - - ACE_ASSERT (base_addr != 0); this->base_offset_ = (char *) this - (char *) base_addr; } @@ -49,5 +49,5 @@ ACE_Based_Pointer<CONCRETE>::operator [] (int index) return *((CONCRETE *)(base_addr + (long) this->target_) + index); } -#endif/* ACE_BASED_POINTER_REPOSITORY_T_CPP */ +#endif/* ACE_BASED_POINTER_T_CPP */ diff --git a/ace/Based_Pointer_Repository_T.h b/ace/Based_Pointer_T.h index ef8a5dd4ae1..1f0c1838582 100644 --- a/ace/Based_Pointer_Repository_T.h +++ b/ace/Based_Pointer_T.h @@ -7,7 +7,7 @@ // ace // // = FILENAME -// Based_Pointer_Repository_T.h +// Based_Pointer_T.h // // = AUTHOR // Dietrich Quehl <Dietrich.Quehl@med.siemens.de> and @@ -15,8 +15,8 @@ // // ============================================================================ -#if !defined (ACE_BASED_POINTER_REPOSITORY_T_H) -#define ACE_BASED_POINTER_REPOSITORY_T_H +#if !defined (ACE_BASED_POINTER_T_H) +#define ACE_BASED_POINTER_T_H #if defined (_MSC_VER) // Suppress warning e.g. "return type for @@ -34,16 +34,29 @@ class ACE_Based_Pointer // from its base address. // // = DESCRIPTION - // This class makes it possible to transparently use "pointers" - // in shared memory without having to ensure that the base + // This class makes it possible to transparently use "pointers" in + // shared memory as easily as programming with pointers to local + // memory. In particular, we don't need to ensure that the base // addresses of all the pointers are mapped into separate // processes at the same absolute memory base address. public: // = Initialization method. ACE_Based_Pointer (void); - // This constructor initializes the <base_offset_> by computing the - // difference between <this> and the base address of the region that - // <this> is contained within. + // This constructor initializes the <base_offset_> by asking the + // <ACE_BASED_POINTER_REPOSITORY> Singleton for the base address of + // the memory region within which it is instantiated. Two results + // are possible: + // + // 1. An <ACE_*_Memory_Pool> has stored a base address/size pair and the + // new based-pointer instance is located between the base address and + // the base address + size - 1. In this case, the repository + // returns the base address. + // + // 2. No suitable address/size pair was found. The repository + // assumes an address in the regular (not mapped) virtual address + // space of the process and returns 0. In this case, the + // based-pointer uses its address as an offset to it's base + // address 0. CONCRETE *operator->(void); // The C++ "delegation operator". @@ -65,11 +78,11 @@ private: }; #if defined (ACE_TEMPLATES_REQUIRE_SOURCE) -#include "ace/Based_Pointer_Repository_T.cpp" +#include "ace/Based_Pointer_T.cpp" #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) -#pragma implementation ("Based_Pointer_Repository_T.cpp") +#pragma implementation ("Based_Pointer_T.cpp") #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ -#endif /* ACE_BASED_POINTER_REPOSITORY_T_H */ +#endif /* ACE_BASED_POINTER_T_H */ diff --git a/ace/Makefile b/ace/Makefile index c3fe48d1779..9cfb79633d5 100644 --- a/ace/Makefile +++ b/ace/Makefile @@ -180,7 +180,7 @@ TEMPLATE_FILES = \ Active_Map_Manager_T \ Asynch_Acceptor \ Auto_Ptr \ - Based_Pointer_Repository_T \ + Based_Pointer_T \ Connector \ Containers_T \ Cache_Map_Manager_T \ diff --git a/ace/Makefile.bor b/ace/Makefile.bor index e5ab56a2e86..1f40409661a 100644 --- a/ace/Makefile.bor +++ b/ace/Makefile.bor @@ -18,6 +18,7 @@ OBJFILES = \ $(OBJDIR)\Asynch_IO.obj \ $(OBJDIR)\Asynch_IO_Impl.obj \ $(OBJDIR)\Auto_Ptr.obj \ + $(OBJDIR)\Based_Pointer_Repository.obj \ $(OBJDIR)\Basic_Types.obj \ $(OBJDIR)\CDR_Stream.obj \ $(OBJDIR)\CORBA_Handler.obj \ diff --git a/ace/Malloc.h b/ace/Malloc.h index 57e240da004..96a64054949 100644 --- a/ace/Malloc.h +++ b/ace/Malloc.h @@ -34,6 +34,10 @@ #define ACE_PROCESS_MUTEX ACE_SV_Semaphore_Simple #endif /* ACE_HAS_THREADS */ +#if defined (ACE_HAS_BASED_POINTER_MALLOC) +#include "ace/Based_Pointer_T.h" +#endif /* ACE_HAS_BASED_POINTER_MALLOC */ + typedef ACE_Atomic_Op<ACE_PROCESS_MUTEX, int> ACE_INT; struct ACE_Export ACE_Malloc_Stats @@ -57,6 +61,7 @@ struct ACE_Export ACE_Malloc_Stats #define AMS(X) #endif /* ACE_HAS_MALLOC_STATS */ +#if !defined (ACE_MALLOC_ALIGN) // ACE_MALLOC_ALIGN allows you to insure that allocated regions are at // least <ACE_MALLOC_ALIGN> bytes long. It is especially useful when // you want areas to be at least a page long, or 32K long, or @@ -71,17 +76,27 @@ struct ACE_Export ACE_Malloc_Stats // use a signed integer number of bytes you want. For example: // #define ACE_MALLOC_ALIGN ((int)4096) -#if !defined (ACE_MALLOC_ALIGN) #define ACE_MALLOC_ALIGN ((int)(sizeof (long))) #endif /* ACE_MALLOC_ALIGN */ union ACE_Export ACE_Malloc_Header { - // TITLE - // This is a block header. + // = TITLE + // We use a union to force alignment to the most restrictive type. - struct ACE_Malloc_Control_Block + class ACE_Malloc_Control_Block { + // = TITLE + // This is the control block header. It's used by <ACE_Malloc> + // to keep track of each chunk of data when it's in the free + // list or in use. + public: +#if defined (ACE_HAS_BASED_POINTER_MALLOC) + ACE_Based_Pointer<ACE_Malloc_Header> *next_block_; +#else + ACE_Malloc_Header *next_block_; +#endif /* ACE_HAS_BASED_POINTER_MALLOC */ + ACE_Malloc_Header *next_block_; // Points to next block if on free list. diff --git a/ace/Memory_Pool.cpp b/ace/Memory_Pool.cpp index b8a3567fa6d..6be0ce5bff0 100644 --- a/ace/Memory_Pool.cpp +++ b/ace/Memory_Pool.cpp @@ -33,16 +33,17 @@ ACE_Local_Memory_Pool::acquire (size_t nbytes, ACE_TRACE ("ACE_Local_Memory_Pool::acquire"); rounded_bytes = this->round_up (nbytes); - ACE_Auto_Basic_Array_Ptr<char> cp (new char[rounded_bytes]); + char *temp = 0; + ACE_NEW_RETURN (temp, + char[rounded_bytes], + -1); - if (cp.get () == 0) - ACE_ERROR_RETURN ((LM_ERROR, ASYS_TEXT ("(%P|%t) new failed \n")), 0); - else - { - int result = this->allocated_chunks_.insert (cp.get ()); - if (result != 0) - ACE_ERROR_RETURN ((LM_ERROR, ASYS_TEXT ("(%P|%t) insertion into set failed\n")), 0); - } + ACE_Auto_Basic_Array_Ptr<char> cp (temp); + + if (this->allocated_chunks_.insert (cp.get ()) != 0) + ACE_ERROR_RETURN ((LM_ERROR, + ASYS_TEXT ("(%P|%t) insertion into set failed\n")), + 0); return cp.release (); } @@ -56,9 +57,7 @@ ACE_Local_Memory_Pool::release (void) for (ACE_Unbounded_Set<char *>::iterator i = this->allocated_chunks_.begin (); i != this->allocated_chunks_.end (); ++i) - { - delete[] *i; - } + delete [] *i; return 0; } @@ -357,9 +356,9 @@ ACE_MMAP_Memory_Pool_Options::ACE_MMAP_Memory_Pool_Options (void *base_addr, ACE_TRACE ("ACE_MMAP_Memory_Pool_Options::ACE_MMAP_Memory_Pool_Options"); // HP-UX 11, 64-bit bug workaround. #if defined (__hpux) && defined (__LP64__) -long temp = ACE_DEFAULT_BASE_ADDRL; -base_addr_ = (void *)temp; -#endif + long temp = ACE_DEFAULT_BASE_ADDRL; + base_addr_ = (void *) temp; +#endif /* defined (__hpux) && defined (__LP64__) */ } // Handle SIGSEGV and SIGBUS signals to remap memory properly. When a @@ -485,18 +484,20 @@ ACE_ALLOC_HOOK_DEFINE(ACE_Shared_Memory_Pool) ACE_Shared_Memory_Pool_Options::ACE_Shared_Memory_Pool_Options (char *base_addr, size_t max_segments, size_t file_perms, - off_t minimum_bytes) + off_t minimum_bytes, + size_t segment_size) : base_addr_ (base_addr), max_segments_ (max_segments), minimum_bytes_ (minimum_bytes), - file_perms_ (file_perms) + file_perms_ (file_perms), + segment_size_ (segment_size) { ACE_TRACE ("ACE_Shared_Memory_Pool_Options::ACE_Shared_Memory_Pool_Options"); -// HP-UX 11, 64-bit bug workaround -#if defined (__hpux) && defined(__LP64__) -long temp = ACE_DEFAULT_BASE_ADDRL; -base_addr_ = (char *)temp; -#endif + // HP-UX 11, 64-bit bug workaround +#if defined (__hpux) && defined (__LP64__) + long temp = ACE_DEFAULT_BASE_ADDRL; + base_addr_ = (char *) temp; +#endif /* defined (__hpux) && defined (__LP64__) */ } void @@ -666,7 +667,8 @@ ACE_Shared_Memory_Pool::ACE_Shared_Memory_Pool (LPCTSTR backing_store_name, : base_addr_ (0), file_perms_ (ACE_DEFAULT_FILE_PERMS), max_segments_ (ACE_DEFAULT_MAX_SEGMENTS), - minimum_bytes_ (0) + minimum_bytes_ (0), + segment_size_ (ACE_DEFAULT_SEGMENT_SIZE) { ACE_TRACE ("ACE_Shared_Memory_Pool::ACE_Shared_Memory_Pool"); @@ -677,6 +679,7 @@ ACE_Shared_Memory_Pool::ACE_Shared_Memory_Pool (LPCTSTR backing_store_name, this->max_segments_ = options->max_segments_; this->file_perms_ = options->file_perms_; this->minimum_bytes_ = options->minimum_bytes_; + this->segment_size_ = options->segment_size_; } if (backing_store_name) diff --git a/ace/Memory_Pool.h b/ace/Memory_Pool.h index 0d14b34c2f1..be0f868afd0 100644 --- a/ace/Memory_Pool.h +++ b/ace/Memory_Pool.h @@ -114,7 +114,8 @@ public: ACE_Shared_Memory_Pool_Options (char *base_addr = ACE_DEFAULT_BASE_ADDR, size_t max_segments = ACE_DEFAULT_MAX_SEGMENTS, size_t file_perms = ACE_DEFAULT_FILE_PERMS, - off_t minimum_bytes = 0); + off_t minimum_bytes = 0, + size_t segment_size = ACE_DEFAULT_SEGMENT_SIZE); char *base_addr_; // Base address of the memory-mapped backing store. @@ -127,6 +128,9 @@ public: size_t file_perms_; // File permissions to use when creating/opening a segment. + + size_t segment_size_; + // Shared memory segment size. }; class ACE_Export ACE_Shared_Memory_Pool : public ACE_Event_Handler @@ -220,6 +224,9 @@ protected: off_t minimum_bytes_; // What the minimim bytes of the initial segment should be. + size_t segment_size_; + // Shared memory segment size. + key_t base_shm_key_; // Base shared memory key for the segment. diff --git a/ace/Memory_Pool.i b/ace/Memory_Pool.i index a3a8667c6a4..d18ccb7afdd 100644 --- a/ace/Memory_Pool.i +++ b/ace/Memory_Pool.i @@ -89,8 +89,8 @@ ACE_INLINE size_t ACE_Shared_Memory_Pool::round_up (size_t nbytes) { ACE_TRACE ("ACE_Shared_Memory_Pool::round_up"); - if (nbytes < ACE_DEFAULT_SEGMENT_SIZE) - nbytes = ACE_DEFAULT_SEGMENT_SIZE; + if (nbytes < this->segment_size_) + nbytes = this->segment_size_; return ACE::round_to_pagesize (nbytes); } |