SV_Shared_Memory.inl

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // $Id: SV_Shared_Memory.inl 80826 2008-03-04 14:51:23Z wotte $
00004 
00005 #include "ace/OS_NS_sys_shm.h"
00006 #include "ace/Global_Macros.h"
00007 #include "ace/OS_NS_errno.h"
00008 
00009 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00010 
00011 ACE_INLINE size_t
00012 ACE_SV_Shared_Memory::round_up (size_t len)
00013 {
00014   ACE_TRACE ("ACE_SV_Shared_Memory::round_up");
00015   return (len + ACE_SV_Shared_Memory::ALIGN_WORDB - 1) & ~(ACE_SV_Shared_Memory::ALIGN_WORDB - 1);
00016 }
00017 
00018 // Creates a shared memory segment of SIZE bytes. Does *not* attach
00019 // this memory segment...
00020 
00021 ACE_INLINE int
00022 ACE_SV_Shared_Memory::open (key_t external_id, size_t sz, int create, int perms)
00023 {
00024   ACE_TRACE ("ACE_SV_Shared_Memory::open");
00025 #if defined (ACE_WIN32)
00026   ACE_UNUSED_ARG(perms);
00027   ACE_UNUSED_ARG(create);
00028   ACE_UNUSED_ARG(sz);
00029   ACE_UNUSED_ARG(external_id);
00030   ACE_NOTSUP_RETURN (-1);
00031 #else
00032   this->segment_ptr_ = 0;
00033   this->size_ = sz;
00034 
00035   this->internal_id_ = ACE_OS::shmget (external_id, sz, create | perms);
00036 
00037   return this->internal_id_ == -1 ? -1 : 0;
00038 #endif /* ACE_WIN32 */
00039 }
00040 
00041 // Attachs to the shared memory segment.
00042 
00043 ACE_INLINE int
00044 ACE_SV_Shared_Memory::attach (void *virtual_addr, int flags)
00045 {
00046   ACE_TRACE ("ACE_SV_Shared_Memory::attach");
00047 #if defined (ACE_WIN32)
00048   ACE_UNUSED_ARG(flags);
00049   ACE_UNUSED_ARG(virtual_addr);
00050   ACE_NOTSUP_RETURN (-1);
00051 #else
00052   this->segment_ptr_ = ACE_OS::shmat (this->internal_id_, virtual_addr, flags);
00053   return this->segment_ptr_ == (void *) -1 ? -1 : 0;
00054 #endif /* ACE_WIN32 */
00055 }
00056 
00057 // Interface to the underlying shared memory control function.
00058 
00059 ACE_INLINE int
00060 ACE_SV_Shared_Memory::control (int cmd, void *buf)
00061 {
00062   ACE_TRACE ("ACE_SV_Shared_Memory::control");
00063 #if defined (ACE_WIN32)
00064   ACE_UNUSED_ARG(cmd);
00065   ACE_UNUSED_ARG(buf);
00066   ACE_NOTSUP_RETURN (-1);
00067 #else
00068   return ACE_OS::shmctl (this->internal_id_, cmd, (struct shmid_ds *) buf);
00069 #endif /* ACE_WIN32 */
00070 }
00071 
00072 // The overall size of the segment.
00073 
00074 ACE_INLINE size_t
00075 ACE_SV_Shared_Memory::get_segment_size (void) const
00076 {
00077   ACE_TRACE ("ACE_SV_Shared_Memory::get_segment_size");
00078   return this->size_;
00079 }
00080 
00081 // Removes the shared memory segment.
00082 
00083 ACE_INLINE int
00084 ACE_SV_Shared_Memory::remove (void)
00085 {
00086   ACE_TRACE ("ACE_SV_Shared_Memory::remove");
00087 #if defined (ACE_WIN32)
00088   ACE_NOTSUP_RETURN (-1);
00089 #else
00090   return ACE_OS::shmctl (this->internal_id_, IPC_RMID, 0);
00091 #endif /* ACE_WIN32 */
00092 }
00093 
00094 // Detach the current binding between this->segment_ptr and the shared
00095 // memory segment.
00096 
00097 ACE_INLINE int
00098 ACE_SV_Shared_Memory::detach (void)
00099 {
00100   ACE_TRACE ("ACE_SV_Shared_Memory::detach");
00101   return ACE_OS::shmdt (this->segment_ptr_);
00102 }
00103 
00104 ACE_INLINE void *
00105 ACE_SV_Shared_Memory::get_segment_ptr (void) const
00106 {
00107   ACE_TRACE ("ACE_SV_Shared_Memory::get_segment_ptr");
00108   return this->segment_ptr_;
00109 }
00110 
00111 ACE_INLINE ACE_HANDLE
00112 ACE_SV_Shared_Memory::get_id (void) const
00113 {
00114   ACE_TRACE ("ACE_SV_Shared_Memory::get_id");
00115   return this->internal_id_;
00116 }
00117 
00118 ACE_END_VERSIONED_NAMESPACE_DECL

Generated on Tue Feb 2 17:18:43 2010 for ACE by  doxygen 1.4.7