Skip to content

Commit

Permalink
Call shmdt when we only need to release the shared memory
Browse files Browse the repository at this point in the history
    * ACE/ace/Malloc_T.cpp:
    * ACE/ace/Malloc_T.inl:
    * ACE/ace/Mem_Map.cpp:
    * ACE/ace/Shared_Memory.h:
    * ACE/ace/Shared_Memory_MM.h:
    * ACE/ace/Shared_Memory_Pool.cpp:
    * ACE/ace/Shared_Memory_Pool.h:
  • Loading branch information
jwillemsen committed Jun 15, 2023
1 parent 4834147 commit 6c593fc
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 98 deletions.
3 changes: 1 addition & 2 deletions ACE/ace/Malloc_T.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,6 @@ ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::~ACE_Malloc_T ()
}

// Clean up the resources allocated by ACE_Malloc_T.

template <ACE_MEM_POOL_1, class ACE_LOCK, class ACE_CB> int
ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::remove ()
{
Expand All @@ -601,7 +600,7 @@ ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::remove ()
// Also notice that we are leaving the decision of removing
// the pool to users so they can map to the same mmap file
// again.
this->cb_ptr_ = 0;
this->cb_ptr_ = nullptr;

return result;
}
Expand Down
10 changes: 5 additions & 5 deletions ACE/ace/Malloc_T.inl
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ template <ACE_MEM_POOL_1, class ACE_LOCK, class ACE_CB> ACE_INLINE int
ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::release (int close)
{
ACE_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1);
if (this->cb_ptr_ != 0)
if (this->cb_ptr_ != nullptr)
{
int const retv = --this->cb_ptr_->ref_counter_;

if (close)
this->memory_pool_.release (0);
{
this->memory_pool_.release (0);
}

if (retv == 0)
{
Expand Down Expand Up @@ -109,9 +111,7 @@ ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::protect (ssize_t len,
}

template <ACE_MEM_POOL_1, class ACE_LOCK, class ACE_CB> ACE_INLINE int
ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::protect (void *addr,
size_t len,
int flags)
ACE_Malloc_T<ACE_MEM_POOL_2, ACE_LOCK, ACE_CB>::protect (void *addr, size_t len, int flags)
{
ACE_TRACE ("ACE_Malloc_T<MEMORY_POOL, ACE_LOCK, ACE_CB>::protect");
return this->memory_pool_.protect (addr, len, flags);
Expand Down
2 changes: 0 additions & 2 deletions ACE/ace/Mem_Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ ACE_Mem_Map::ACE_Mem_Map ()
}

// Map a file specified by FILE_NAME.

ACE_Mem_Map::ACE_Mem_Map (const ACE_TCHAR *file_name,
size_t len,
int flags,
Expand Down Expand Up @@ -279,7 +278,6 @@ ACE_Mem_Map::ACE_Mem_Map (const ACE_TCHAR *file_name,

// Map a file from an open file descriptor HANDLE. This function will
// lookup the length of the file if it is not given.

ACE_Mem_Map::ACE_Mem_Map (ACE_HANDLE handle,
size_t len,
int prot,
Expand Down
2 changes: 1 addition & 1 deletion ACE/ace/Shared_Memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ ACE_BEGIN_VERSIONED_NAMESPACE_DECL
* This is a very simple-minded wrapper, i.e., it really is only
* useful for allocating large contiguous chunks of shared
* memory. For a much more sophisticated version, please check
* out the <ACE_Malloc> class.
* out the ACE_Malloc class.
*/
class ACE_Export ACE_Shared_Memory
{
Expand Down
2 changes: 1 addition & 1 deletion ACE/ace/Shared_Memory_MM.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class ACE_Export ACE_Shared_Memory_MM : public ACE_Shared_Memory
virtual void *malloc (size_t size = 0);

/// Free a chuck of memory allocated by
/// <ACE_Shared_Memory_MM::malloc>.
/// ACE_Shared_Memory_MM::malloc.
virtual int free (void *p);

/// Return the size of the shared memory segment.
Expand Down
Loading

0 comments on commit 6c593fc

Please sign in to comment.