SV_Shared_Memory.inl

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // SV_Shared_Memory.inl,v 4.2 2005/10/28 16:14:55 ossama Exp
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 
00067         ACE_NOTSUP_RETURN (-1);
00068 #else
00069   return ACE_OS::shmctl (this->internal_id_, cmd, (struct shmid_ds *) buf);
00070 #endif /* ACE_WIN32 */
00071 }
00072 
00073 // The overall size of the segment.
00074 
00075 ACE_INLINE size_t
00076 ACE_SV_Shared_Memory::get_segment_size (void) const
00077 {
00078   ACE_TRACE ("ACE_SV_Shared_Memory::get_segment_size");
00079   return this->size_;
00080 }
00081 
00082 // Removes the shared memory segment.
00083 
00084 ACE_INLINE int
00085 ACE_SV_Shared_Memory::remove (void)
00086 {
00087   ACE_TRACE ("ACE_SV_Shared_Memory::remove");
00088 #if defined (ACE_WIN32)
00089   ACE_NOTSUP_RETURN (-1);
00090 #else
00091   return ACE_OS::shmctl (this->internal_id_, IPC_RMID, 0);
00092 #endif /* ACE_WIN32 */
00093 }
00094 
00095 // Detach the current binding between this->segment_ptr and the shared
00096 // memory segment.
00097 
00098 ACE_INLINE int
00099 ACE_SV_Shared_Memory::detach (void)
00100 {
00101   ACE_TRACE ("ACE_SV_Shared_Memory::detach");
00102   return ACE_OS::shmdt (this->segment_ptr_);
00103 }
00104 
00105 ACE_INLINE void *
00106 ACE_SV_Shared_Memory::get_segment_ptr (void) const
00107 {
00108   ACE_TRACE ("ACE_SV_Shared_Memory::get_segment_ptr");
00109   return this->segment_ptr_;
00110 }
00111 
00112 ACE_INLINE ACE_HANDLE
00113 ACE_SV_Shared_Memory::get_id (void) const
00114 {
00115   ACE_TRACE ("ACE_SV_Shared_Memory::get_id");
00116   return this->internal_id_;
00117 }
00118 
00119 ACE_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 09:42:06 2006 for ACE by doxygen 1.3.6