ACE_Mem_Map Class Reference

C++ interface OS memory mapping system call. More...

#include <Mem_Map.h>

List of all members.

Public Member Functions

 ACE_Mem_Map (void)
 Default constructor.

 ACE_Mem_Map (ACE_HANDLE handle, ssize_t length=-1, int prot=PROT_RDWR, int share=ACE_MAP_PRIVATE, void *addr=0, off_t offset=0, LPSECURITY_ATTRIBUTES sa=0)
 ACE_Mem_Map (const ACE_TCHAR *filename, ssize_t length=-1, int flags=O_RDWR|O_CREAT, int mode=ACE_DEFAULT_FILE_PERMS, int prot=PROT_RDWR, int share=ACE_MAP_PRIVATE, void *addr=0, off_t offset=0, LPSECURITY_ATTRIBUTES sa=0)
 Map a file specified by file_name.

int map (ACE_HANDLE handle, ssize_t length=-1, int prot=PROT_RDWR, int share=ACE_MAP_PRIVATE, void *addr=0, off_t offset=0, LPSECURITY_ATTRIBUTES sa=0)
int map (ssize_t length=-1, int prot=PROT_RDWR, int share=ACE_MAP_PRIVATE, void *addr=0, off_t offset=0, LPSECURITY_ATTRIBUTES sa=0)
 Remap the file associated with .

int map (const ACE_TCHAR *filename, ssize_t length=-1, int flags=O_RDWR|O_CREAT, int mode=ACE_DEFAULT_FILE_PERMS, int prot=PROT_RDWR, int share=ACE_MAP_PRIVATE, void *addr=0, off_t offset=0, LPSECURITY_ATTRIBUTES sa=0)
 Map a file specified by .

 ~ACE_Mem_Map (void)
 Destructor.

int open (const ACE_TCHAR *filename, int flags=O_RDWR|O_CREAT, int mode=ACE_DEFAULT_FILE_PERMS, LPSECURITY_ATTRIBUTES sa=0)
 Open the file without mapping it.

int close (void)
 Close down the if necessary and unmap the mapping.

int close_handle (void)
 Close down the if necessary.

int close_filemapping_handle (void)
int operator() (void *&addr)
void * addr (void) const
 Return the base address.

size_t size (void) const
int unmap (ssize_t len=-1)
 Unmap the region starting at .

int unmap (void *addr, ssize_t len)
 Unmap the region starting at .

int sync (ssize_t len=-1, int flags=MS_SYNC)
int sync (void *addr, size_t len, int flags=MS_SYNC)
int protect (ssize_t len=-1, int prot=PROT_RDWR)
int protect (void *addr, size_t len, int prot=PROT_RDWR)
int remove (void)
 Close and remove the file from the file system.

int advise (int behavior, int len=-1)
 Hook into the underlying VM system.

ACE_HANDLE handle (void) const
 Return the underlying .

const ACE_TCHARfilename (void) const
 Return the name of file that is mapped (if any).

void dump (void) const
 Dump the state of an object.


Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks.


Private Member Functions

int map_it (ACE_HANDLE handle, ssize_t len=-1, int prot=PROT_RDWR, int share=MAP_SHARED, void *addr=0, off_t offset=0, LPSECURITY_ATTRIBUTES sa=0)
 ACE_Mem_Map (const ACE_Mem_Map &)
void operator= (const ACE_Mem_Map &)

Private Attributes

void * base_addr_
 Base address of the memory-mapped file.

ACE_TCHAR filename_ [MAXPATHLEN+1]
 Name of the file that is mapped.

size_t length_
 Length of the mapping.

ACE_HANDLE handle_
 HANDLE for the open file.

ACE_HANDLE file_mapping_
 HANDLE for the open mapping.

bool close_handle_


Detailed Description

C++ interface OS memory mapping system call.

This class works with both the mmap(2) UNIX system and the Win32 family of memory mapping system calls.

Definition at line 40 of file Mem_Map.h.


Constructor & Destructor Documentation

ACE_Mem_Map::ACE_Mem_Map void   ) 
 

Default constructor.

Definition at line 275 of file Mem_Map.cpp.

References ACE_TRACE, MAP_FAILED, and ACE_OS::memset().

00276   : base_addr_ (MAP_FAILED),
00277     length_ (0),
00278     handle_ (ACE_INVALID_HANDLE),
00279     file_mapping_ (ACE_INVALID_HANDLE),
00280     close_handle_ (false)
00281 {
00282   ACE_TRACE ("ACE_Mem_Map::ACE_Mem_Map");
00283   ACE_OS::memset (this->filename_, 0, sizeof this->filename_);
00284 }

ACE_Mem_Map::ACE_Mem_Map ACE_HANDLE  handle,
ssize_t  length = -1,
int  prot = PROT_RDWR,
int  share = ACE_MAP_PRIVATE,
void *  addr = 0,
off_t  offset = 0,
LPSECURITY_ATTRIBUTES  sa = 0
 

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

Definition at line 321 of file Mem_Map.cpp.

References ACE_ERROR, ACE_LIB_TEXT, ACE_TRACE, LM_ERROR, map(), MAP_FAILED, ACE_OS::memset(), and ssize_t.

00328   : base_addr_ (MAP_FAILED),
00329     length_ (0),
00330     handle_ (ACE_INVALID_HANDLE),
00331     file_mapping_ (ACE_INVALID_HANDLE),
00332     close_handle_ (false)
00333 {
00334   ACE_TRACE ("ACE_Mem_Map::ACE_Mem_Map");
00335 
00336   ACE_OS::memset (this->filename_,
00337                   0,
00338                   sizeof this->filename_);
00339   if (this->map (handle,
00340                  len,
00341                  prot,
00342                  share,
00343                  addr,
00344                  offset,
00345                  sa) < 0)
00346     ACE_ERROR ((LM_ERROR,
00347                 ACE_LIB_TEXT ("%p\n"),
00348                 ACE_LIB_TEXT ("ACE_Mem_Map::ACE_Mem_Map")));
00349 }

ACE_Mem_Map::ACE_Mem_Map const ACE_TCHAR filename,
ssize_t  length = -1,
int  flags = O_RDWR|O_CREAT,
int  mode = ACE_DEFAULT_FILE_PERMS,
int  prot = PROT_RDWR,
int  share = ACE_MAP_PRIVATE,
void *  addr = 0,
off_t  offset = 0,
LPSECURITY_ATTRIBUTES  sa = 0
 

Map a file specified by file_name.

Definition at line 288 of file Mem_Map.cpp.

References ACE_ERROR, ACE_LIB_TEXT, ACE_TCHAR, ACE_TRACE, LM_ERROR, map(), MAP_FAILED, and ssize_t.

00297   : base_addr_ (MAP_FAILED),
00298     length_ (0),
00299     handle_ (ACE_INVALID_HANDLE),
00300     file_mapping_ (ACE_INVALID_HANDLE),
00301     close_handle_ (false)
00302 {
00303   ACE_TRACE ("ACE_Mem_Map::ACE_Mem_Map");
00304   if (this->map (file_name,
00305                  len,
00306                  flags,
00307                  mode,
00308                  prot,
00309                  share,
00310                  addr,
00311                  offset,
00312                  sa) < 0)
00313     ACE_ERROR ((LM_ERROR,
00314                 ACE_LIB_TEXT ("%p\n"),
00315                 ACE_LIB_TEXT ("ACE_Mem_Map::ACE_Mem_Map")));
00316 }

ACE_Mem_Map::~ACE_Mem_Map void   ) 
 

Destructor.

Definition at line 86 of file Mem_Map.cpp.

References ACE_TRACE, and close().

00087 {
00088   ACE_TRACE ("ACE_Mem_Map::~ACE_Mem_Map");
00089 
00090   this->close ();
00091 }

ACE_Mem_Map::ACE_Mem_Map const ACE_Mem_Map  )  [private]
 


Member Function Documentation

ACE_INLINE void * ACE_Mem_Map::addr void   )  const
 

Return the base address.

Definition at line 81 of file Mem_Map.inl.

References ACE_TRACE, and base_addr_.

Referenced by ACE_MMAP_Memory_Pool::acquire(), ACE_Filecache_Object::address(), ACE_MMAP_Memory_Pool::init_acquire(), ACE_MMAP_Memory_Pool::map_file(), and ACE_MMAP_Memory_Pool::remap().

00082 {
00083   ACE_TRACE ("ACE_Mem_Map::addr");
00084 
00085   return this->base_addr_;
00086 }

ACE_INLINE int ACE_Mem_Map::advise int  behavior,
int  len = -1
 

Hook into the underlying VM system.

Definition at line 235 of file Mem_Map.inl.

References ACE_TRACE, caddr_t, and ACE_OS::madvise().

00236 {
00237   ACE_TRACE ("ACE_Mem_Map::advise");
00238   const size_t advise_len =
00239     len < 0 ? this->length_ : static_cast<size_t> (len);
00240 
00241   return ACE_OS::madvise ((caddr_t) this->base_addr_,
00242                           advise_len,
00243                           behavior);
00244 }

int ACE_Mem_Map::close void   ) 
 

Close down the if necessary and unmap the mapping.

Definition at line 77 of file Mem_Map.cpp.

References ACE_TRACE, close_handle(), and unmap().

Referenced by ACE_MMAP_Memory_Pool::release(), remove(), and ~ACE_Mem_Map().

00078 {
00079   ACE_TRACE ("ACE_Mem_Map::close");
00080 
00081   this->unmap ();
00082 
00083   return this->close_handle ();
00084 }

ACE_INLINE int ACE_Mem_Map::close_filemapping_handle void   ) 
 

Close down the internal if necessary. This is mostly necessary on Win32, which has a different handle for file-mapping kernel object.

Definition at line 99 of file Mem_Map.inl.

References ACE_OS::close(), and file_mapping_.

Referenced by map_it(), and unmap().

00100 {
00101   int result = 0;
00102 
00103   if (this->file_mapping_ != this->handle_
00104       && this->file_mapping_ != ACE_INVALID_HANDLE)
00105     {
00106       // On LynxOS, this will result in unlinking of the (hidden)
00107       // shared memory file if there are no more references to it.
00108       result = ACE_OS::close (this->file_mapping_);
00109       this->file_mapping_ = ACE_INVALID_HANDLE;
00110     }
00111 
00112   return result;
00113 }

ACE_INLINE int ACE_Mem_Map::close_handle void   ) 
 

Close down the if necessary.

Definition at line 247 of file Mem_Map.inl.

References ACE_OS::close(), and close_handle_.

Referenced by close().

00248 {
00249   int result = 0;
00250 
00251   if (this->close_handle_)
00252     {
00253       this->close_handle_ = false;
00254       result = ACE_OS::close (this->handle_);
00255       this->handle_ = ACE_INVALID_HANDLE;
00256     }
00257 
00258   return result;
00259 }

void ACE_Mem_Map::dump void   )  const
 

Dump the state of an object.

Definition at line 60 of file Mem_Map.cpp.

References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_LIB_TEXT, ACE_TRACE, and LM_DEBUG.

00061 {
00062 #if defined (ACE_HAS_DUMP)
00063   ACE_TRACE ("ACE_Mem_Map::dump");
00064 
00065   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00066   ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("base_addr_ = %x"), this->base_addr_));
00067   ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("\nfilename_ = %s"), this->filename_));
00068   ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("\nlength_ = %d"), this->length_));
00069   ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("\nhandle_ = %d"), this->handle_));
00070   ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("\nfile_mapping_ = %d"), this->file_mapping_));
00071   ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("\nclose_handle_ = %d"), this->close_handle_));
00072   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00073 #endif /* ACE_HAS_DUMP */
00074 }

ACE_INLINE const ACE_TCHAR * ACE_Mem_Map::filename void   )  const
 

Return the name of file that is mapped (if any).

Definition at line 21 of file Mem_Map.inl.

Referenced by ACE_Shared_Memory_MM::filename().

00022 {
00023   return this->filename_;
00024 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE ACE_HANDLE ACE_Mem_Map::handle void   )  const
 

Return the underlying .

Definition at line 12 of file Mem_Map.inl.

References ACE_TRACE.

Referenced by ACE_MMAP_Memory_Pool::commit_backing_store_name(), and ACE_Shared_Memory_MM::get_id().

00013 {
00014   ACE_TRACE ("ACE_Mem_Map::handle");
00015   return this->handle_;
00016 }

int ACE_Mem_Map::map const ACE_TCHAR filename,
ssize_t  length = -1,
int  flags = O_RDWR|O_CREAT,
int  mode = ACE_DEFAULT_FILE_PERMS,
int  prot = PROT_RDWR,
int  share = ACE_MAP_PRIVATE,
void *  addr = 0,
off_t  offset = 0,
LPSECURITY_ATTRIBUTES  sa = 0
 

Map a file specified by .

Definition at line 247 of file Mem_Map.cpp.

References ACE_TCHAR, ACE_TRACE, map_it(), open(), and ssize_t.

00256 {
00257   ACE_TRACE ("ACE_Mem_Map::map");
00258   this->length_ = 0;
00259 
00260   if (this->open (file_name,
00261                   flags,
00262                   mode,
00263                   sa) == -1)
00264     return -1;
00265   else
00266     return this->map_it (this->handle (),
00267                          len,
00268                          prot,
00269                          share,
00270                          addr,
00271                          offset,
00272                          sa);
00273 }

ACE_INLINE int ACE_Mem_Map::map ssize_t  length = -1,
int  prot = PROT_RDWR,
int  share = ACE_MAP_PRIVATE,
void *  addr = 0,
off_t  offset = 0,
LPSECURITY_ATTRIBUTES  sa = 0
 

Remap the file associated with .

Definition at line 42 of file Mem_Map.inl.

References ACE_TRACE, base_addr_, MAP_FAILED, MAP_FIXED, map_it(), and ssize_t.

00048 {
00049   ACE_TRACE ("ACE_Mem_Map::map");
00050   // If we're already mapped at a particular location then try to
00051   // remap the file using the same base address.
00052   if (addr == 0 && this->base_addr_ != 0 && this->base_addr_ != MAP_FAILED)
00053     {
00054       share |= MAP_FIXED;
00055       addr = this->base_addr_;
00056     }
00057 
00058   return this->map_it (this->handle (), length, prot,
00059                        share, addr, offset, sa);
00060 }

ACE_INLINE int ACE_Mem_Map::map ACE_HANDLE  handle,
ssize_t  length = -1,
int  prot = PROT_RDWR,
int  share = ACE_MAP_PRIVATE,
void *  addr = 0,
off_t  offset = 0,
LPSECURITY_ATTRIBUTES  sa = 0
 

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

Definition at line 27 of file Mem_Map.inl.

References ACE_TRACE, map_it(), and ssize_t.

Referenced by ACE_Filecache_Object::ACE_Filecache_Object(), ACE_Mem_Map(), ACE_MMAP_Memory_Pool::init_acquire(), ACE_MMAP_Memory_Pool::map_file(), ACE_Shared_Memory_MM::open(), and ACE_Filecache_Object::release().

00034 {
00035   ACE_TRACE ("ACE_Mem_Map::map");
00036   return this->map_it (handle, length, prot, share, addr, offset, sa);
00037 }

int ACE_Mem_Map::map_it ACE_HANDLE  handle,
ssize_t  len = -1,
int  prot = PROT_RDWR,
int  share = MAP_SHARED,
void *  addr = 0,
off_t  offset = 0,
LPSECURITY_ATTRIBUTES  sa = 0
[private]
 

This method does the dirty work of actually calling ::mmap to map the file into memory.

Definition at line 97 of file Mem_Map.cpp.

References ACE_BIT_ENABLED, ACE_LOFF_T, ACE_TCHAR, ACE_TRACE, base_addr_, close_filemapping_handle(), ACE_OS::filesize(), MAP_FAILED, MAP_SHARED, ACE_OS::mmap(), PROT_WRITE, ACE_OS::pwrite(), ssize_t, to_mapping_name(), and unmap().

Referenced by map().

00104 {
00105   ACE_TRACE ("ACE_Mem_Map::map_it");
00106 
00107 #if defined (ACE_LACKS_AUTO_MMAP_REPLACEMENT)
00108   // If the system does not replace any previous mappings, then
00109   // unmap() before (potentially) mapping to the same location.
00110   int const unmap_result = this->unmap ();
00111   if (unmap_result != 0)
00112     return unmap_result;
00113 #endif /* ACE_LACKS_AUTO_MMAP_REPLACEMENT */
00114 
00115   this->base_addr_ = addr;
00116   this->handle_ = handle;
00117 
00118   ACE_LOFF_T const result = ACE_OS::filesize (this->handle_);
00119 
00120   // At this point we know <result> is not negative...
00121   size_t const current_file_length = static_cast<size_t> (result);
00122 
00123   // Flag to indicate if we need to extend the back store
00124   bool extend_backing_store = false;
00125 
00126   // File length requested by user
00127   size_t requested_file_length = 0;
00128 
00129   // Check <length_request>
00130   if (length_request == -1)
00131     // Set length to file_request.
00132     this->length_ = current_file_length - offset;
00133   else
00134     {
00135       // File length implicitly requested by user
00136       requested_file_length = length_request + offset;
00137 
00138       // Check to see if we need to extend the backing store
00139       if (requested_file_length > current_file_length)
00140         {
00141           // If the length of the mapped region is less than the
00142           // length of the file then we force a complete new remapping
00143           // by setting the descriptor to ACE_INVALID_HANDLE (closing
00144           // down the descriptor if necessary).
00145           this->close_filemapping_handle ();
00146 
00147           // Remember to extend the backing store
00148           extend_backing_store = true;
00149         }
00150 
00151       // Set length to length_request
00152       this->length_ = length_request;
00153     }
00154 
00155   // Check if we need to extend the backing store.
00156   if (extend_backing_store)
00157     {
00158       // Remember than write increases the size by one.
00159       off_t null_byte_position;
00160       if (requested_file_length > 0)
00161         // This will make the file size <requested_file_length>
00162         null_byte_position =
00163           static_cast<off_t> (requested_file_length - 1);
00164       else
00165         // This will make the file size 1
00166         null_byte_position = 0;
00167 
00168       if (ACE_OS::pwrite (this->handle_,
00169                           "",
00170                           1,
00171                           null_byte_position) == -1)
00172         return -1;
00173     }
00174 
00175 #if defined (ACE_HAS_LYNXOS_BROKEN_MMAP)
00176   // Set flag that indicates whether PROT_WRITE has been enabled.
00177   write_enabled_ = ACE_BIT_ENABLED (prot, PROT_WRITE);
00178 #endif /* ACE_HAS_LYNXOS_BROKEN_MMAP */
00179 
00180 #if defined (ACE_USE_MAPPING_NAME)
00181   if (ACE_BIT_ENABLED (share, MAP_SHARED))
00182     {
00183 # if defined(__MINGW32__)
00184       const int max_mapping_name_length = 32;
00185 # else
00186       const int max_mapping_name_length = 31;
00187 # endif /* __MINGW32__ */
00188       ACE_TCHAR file_mapping_name[max_mapping_name_length + 1];
00189       to_mapping_name (file_mapping_name,
00190                        filename_,
00191                        max_mapping_name_length + 1);
00192 
00193       this->base_addr_ = ACE_OS::mmap (this->base_addr_,
00194                                        this->length_,
00195                                        prot,
00196                                        share,
00197                                        this->handle_,
00198                                        offset,
00199                                        &this->file_mapping_,
00200                                        sa,
00201                                        file_mapping_name);
00202     }
00203   else
00204 #endif /* ACE_USE_MAPPING_NAME */
00205     this->base_addr_ = ACE_OS::mmap (this->base_addr_,
00206                                      this->length_,
00207                                      prot,
00208                                      share,
00209                                      this->handle_,
00210                                      offset,
00211                                      &this->file_mapping_,
00212                                      sa);
00213 
00214   return this->base_addr_ == MAP_FAILED ? -1 : 0;
00215 }

int ACE_Mem_Map::open const ACE_TCHAR filename,
int  flags = O_RDWR|O_CREAT,
int  mode = ACE_DEFAULT_FILE_PERMS,
LPSECURITY_ATTRIBUTES  sa = 0
 

Open the file without mapping it.

Definition at line 218 of file Mem_Map.cpp.

References ACE_TCHAR, ACE_TRACE, close_handle_, MAXPATHLEN, ACE_OS::open(), ACE_OS::shm_open(), and ACE_OS::strsncpy().

Referenced by ACE_MMAP_Memory_Pool::init_acquire(), and map().

00222 {
00223   ACE_TRACE ("ACE_Mem_Map::open");
00224 
00225 #if defined(INTEGRITY)  || defined (__QNXNTO__)
00226   this->handle_ = ACE_OS::shm_open (file_name, flags, mode, sa);
00227 #elif defined (ACE_OPENVMS)
00228   ACE_OSCALL (::open (file_name, flags, mode, "shr=get,put,upd"), ACE_HANDLE, -1, this->handle_);
00229 #else
00230   this->handle_ = ACE_OS::open (file_name, flags, mode, sa);
00231 #endif /* INTEGRITY */
00232 
00233   if (this->handle_ == ACE_INVALID_HANDLE)
00234     return -1;
00235   else
00236     {
00237       ACE_OS::strsncpy (this->filename_,
00238                         file_name,
00239                         MAXPATHLEN);
00240 
00241       this->close_handle_ = true;
00242       return 0;
00243     }
00244 }

ACE_INLINE int ACE_Mem_Map::operator() void *&  addr  ) 
 

This operator passes back the starting address of the mapped file.

Definition at line 65 of file Mem_Map.inl.

References ACE_TRACE, base_addr_, and MAP_FAILED.

00066 {
00067   ACE_TRACE ("ACE_Mem_Map::operator");
00068 
00069   if (this->base_addr_ == MAP_FAILED)
00070     return -1;
00071   else
00072     {
00073       addr = this->base_addr_;
00074       return 0;
00075     }
00076 }

void ACE_Mem_Map::operator= const ACE_Mem_Map  )  [private]
 

ACE_INLINE int ACE_Mem_Map::protect void *  addr,
size_t  len,
int  prot = PROT_RDWR
 

Change the protection of the pages of the mapped region to starting at up to bytes.

Definition at line 226 of file Mem_Map.inl.

References ACE_TRACE, and ACE_OS::mprotect().

00227 {
00228   ACE_TRACE ("ACE_Mem_Map::protect");
00229   return ACE_OS::mprotect (addr, len, prot);
00230 }

ACE_INLINE int ACE_Mem_Map::protect ssize_t  len = -1,
int  prot = PROT_RDWR
 

Change the protection of the pages of the mapped region to starting at up to bytes. If == -1 then change protection of all pages in the mapped region.

Definition at line 214 of file Mem_Map.inl.

References ACE_TRACE, ACE_OS::mprotect(), and ssize_t.

Referenced by ACE_MMAP_Memory_Pool::protect().

00215 {
00216   ACE_TRACE ("ACE_Mem_Map::protect");
00217   if (len < 0)
00218     len = this->length_;
00219   return ACE_OS::mprotect (this->base_addr_, len, prot);
00220 }

int ACE_Mem_Map::remove void   ) 
 

Close and remove the file from the file system.

Definition at line 354 of file Mem_Map.cpp.

References ACE_TRACE, close(), ACE_OS::ftruncate(), ACE_OS::shm_unlink(), and ACE_OS::unlink().

Referenced by ACE_MMAP_Memory_Pool::release(), and ACE_Shared_Memory_MM::remove().

00355 {
00356   ACE_TRACE ("ACE_Mem_Map::remove");
00357 
00358   ACE_OS::ftruncate (this->handle_, 0);
00359   this->close ();
00360 
00361   if (this->filename_[0] != '\0')
00362 #if defined (__QNXNTO__)
00363   return ACE_OS::shm_unlink (this->filename_);
00364 #else
00365   return ACE_OS::unlink (this->filename_);
00366 #endif /* __QNXNTO__ */
00367 
00368   else
00369     return 0;
00370 }

ACE_INLINE size_t ACE_Mem_Map::size void   )  const
 

This function returns the number of bytes currently mapped in the file.

Definition at line 92 of file Mem_Map.inl.

References ACE_TRACE.

Referenced by ACE_MMAP_Memory_Pool::acquire(), ACE_Shared_Memory_MM::get_segment_size(), ACE_MMAP_Memory_Pool::handle_signal(), and ACE_MMAP_Memory_Pool::init_acquire().

00093 {
00094   ACE_TRACE ("ACE_Mem_Map::size");
00095   return this->length_;
00096 }

ACE_INLINE int ACE_Mem_Map::sync void *  addr,
size_t  len,
int  flags = MS_SYNC
 

Sync bytes of the memory region to the backing store starting at .

Definition at line 203 of file Mem_Map.inl.

References ACE_TRACE, and ACE_OS::msync().

00204 {
00205   ACE_TRACE ("ACE_Mem_Map::sync");
00206   return ACE_OS::msync (addr, len, flags);
00207 }

ACE_INLINE int ACE_Mem_Map::sync ssize_t  len = -1,
int  flags = MS_SYNC
 

Sync bytes of the memory region to the backing store starting at . If == -1 then sync the whole region.

Definition at line 191 of file Mem_Map.inl.

References ACE_TRACE, ACE_OS::msync(), and ssize_t.

Referenced by ACE_MMAP_Memory_Pool::sync().

00192 {
00193   ACE_TRACE ("ACE_Mem_Map::sync");
00194   return ACE_OS::msync (this->base_addr_,
00195                         len < 0 ? this->length_ : len,
00196                         flags);
00197 }

ACE_INLINE int ACE_Mem_Map::unmap void *  addr,
ssize_t  len
 

Unmap the region starting at .

Definition at line 156 of file Mem_Map.inl.

References ACE_TRACE, base_addr_, close_filemapping_handle(), ACE_OS::filesize(), ACE_OS::lseek(), ACE_OS::munmap(), ssize_t, and ACE_OS::write().

00157 {
00158   ACE_TRACE ("ACE_Mem_Map::unmap");
00159 
00160   this->close_filemapping_handle ();
00161 
00162 #if defined (ACE_HAS_LYNXOS_BROKEN_MMAP)
00163   int writeback_result = 0;
00164   if (write_enabled_)
00165     {
00166       // Write back the contents of the shared memory object to the file.
00167       off_t const filesize = ACE_OS::filesize (handle_);
00168       writeback_result =
00169         ACE_OS::lseek (handle_, 0, 0) != -1
00170         && ACE_OS::write (handle_,
00171                           base_addr_,
00172                           filesize) == filesize ? 0 : -1;
00173     }
00174 #endif /* ACE_HAS_LYNXOS_BROKEN_MMAP */
00175 
00176 #if defined (ACE_HAS_LYNXOS_BROKEN_MMAP)
00177   return ACE_OS::munmap (addr,
00178                          len < 0 ? this->length_ : len)
00179     | writeback_result;
00180 #else  /* ! ACE_HAS_LYNXOS_BROKEN_MMAP */
00181   return ACE_OS::munmap (addr,
00182                          len < 0 ? this->length_ : len);
00183 #endif /* ! ACE_HAS_LYNXOS_BROKEN_MMAP */
00184 }

ACE_INLINE int ACE_Mem_Map::unmap ssize_t  len = -1  ) 
 

Unmap the region starting at .

Definition at line 118 of file Mem_Map.inl.

References ACE_TRACE, base_addr_, close_filemapping_handle(), ACE_OS::filesize(), ACE_OS::lseek(), MAP_FAILED, ACE_OS::munmap(), ssize_t, and ACE_OS::write().

Referenced by ACE_Shared_Memory_MM::close(), close(), ACE_MMAP_Memory_Pool::map_file(), map_it(), ACE_Filecache_Object::release(), and ACE_Filecache_Object::~ACE_Filecache_Object().

00119 {
00120   ACE_TRACE ("ACE_Mem_Map::unmap");
00121 
00122   this->close_filemapping_handle ();
00123 
00124 #if defined (ACE_HAS_LYNXOS_BROKEN_MMAP)
00125   int writeback_result = 0;
00126   if (write_enabled_)
00127     {
00128       // Write back the contents of the shared memory object to the
00129       // file.
00130       off_t const filesize = ACE_OS::filesize (handle_);
00131       writeback_result =
00132         ACE_OS::lseek (handle_, 0, 0) != -1
00133         && ACE_OS::write (handle_,
00134                           base_addr_,
00135                           (int) filesize) == filesize ? 0 : -1;
00136     }
00137 #endif /* ACE_HAS_LYNXOS_BROKEN_MMAP */
00138   if (this->base_addr_ != MAP_FAILED)
00139     {
00140       int const result = ACE_OS::munmap (this->base_addr_,
00141                                          len < 0 ? this->length_ : len);
00142       this->base_addr_ = MAP_FAILED;
00143       return result;
00144     }
00145   else
00146 #if defined (ACE_HAS_LYNXOS_BROKEN_MMAP)
00147     return writeback_result;
00148 #else  /* ! ACE_HAS_LYNXOS_BROKEN_MMAP */
00149     return 0;
00150 #endif /* ! ACE_HAS_LYNXOS_BROKEN_MMAP */
00151 }


Member Data Documentation

ACE_Mem_Map::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Definition at line 175 of file Mem_Map.h.

void* ACE_Mem_Map::base_addr_ [private]
 

Base address of the memory-mapped file.

Definition at line 196 of file Mem_Map.h.

Referenced by addr(), map(), map_it(), operator()(), and unmap().

bool ACE_Mem_Map::close_handle_ [private]
 

Keeps track of whether we need to close the handle. This is set if we opened the file.

Definition at line 217 of file Mem_Map.h.

Referenced by close_handle(), and open().

ACE_HANDLE ACE_Mem_Map::file_mapping_ [private]
 

HANDLE for the open mapping.

Definition at line 208 of file Mem_Map.h.

Referenced by close_filemapping_handle().

ACE_TCHAR ACE_Mem_Map::filename_[MAXPATHLEN + 1] [private]
 

Name of the file that is mapped.

Definition at line 199 of file Mem_Map.h.

ACE_HANDLE ACE_Mem_Map::handle_ [private]
 

HANDLE for the open file.

Definition at line 205 of file Mem_Map.h.

size_t ACE_Mem_Map::length_ [private]
 

Length of the mapping.

Definition at line 202 of file Mem_Map.h.


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 11:24:39 2006 for ACE by doxygen 1.3.6