1 // $Id: Mutex.cpp 80826 2008-03-04 14:51:23Z wotte $
5 #if !defined (__ACE_INLINE__)
6 #include "ace/Mutex.inl"
7 #endif /* __ACE_INLINE__ */
9 #include "ace/Log_Msg.h"
10 #include "ace/OS_NS_string.h"
11 #include "ace/os_include/sys/os_mman.h"
16 "$Id: Mutex.cpp 80826 2008-03-04 14:51:23Z wotte $")
18 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
20 ACE_ALLOC_HOOK_DEFINE(ACE_Mutex
)
23 ACE_Mutex::dump (void) const
25 // ACE_TRACE ("ACE_Mutex::dump");
27 ACE_DEBUG ((LM_DEBUG
, ACE_BEGIN_DUMP
, this));
28 #if defined (ACE_HAS_PTHREADS) || defined(ACE_HAS_STHREADS)
29 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("lockname_ = %s\n"), this->lockname_
));
30 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("process_lock_ = %x\n"), this->process_lock_
));
31 #endif /* ACE_HAS_PTHREADS || ACE_HAS_STHREADS */
32 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("\n")));
33 ACE_DEBUG ((LM_DEBUG
, ACE_END_DUMP
));
36 ACE_Mutex::ACE_Mutex (int type
, const ACE_TCHAR
*name
,
37 ACE_mutexattr_t
*arg
, mode_t mode
)
39 #if defined (ACE_HAS_PTHREADS) || defined(ACE_HAS_STHREADS)
42 #endif /* ACE_HAS_PTHREADS || ACE_HAS_STHREADS */
45 // ACE_TRACE ("ACE_Mutex::ACE_Mutex");
47 // These platforms need process-wide mutex to be in shared memory.
48 #if defined(ACE_HAS_PTHREADS) || defined (ACE_HAS_STHREADS)
49 if (type
== USYNC_PROCESS
)
51 // Let's see if the shared memory entity already exists.
52 ACE_HANDLE fd
= ACE_OS::shm_open (name
, O_RDWR
| O_CREAT
| O_EXCL
, mode
);
53 if (fd
== ACE_INVALID_HANDLE
)
56 fd
= ACE_OS::shm_open (name
, O_RDWR
| O_CREAT
, mode
);
62 // We own this shared memory object! Let's set its size.
63 if (ACE_OS::ftruncate (fd
,
64 sizeof (ACE_mutex_t
)) == -1)
69 this->lockname_
= ACE_OS::strdup (name
);
70 if (this->lockname_
== 0)
78 (ACE_mutex_t
*) ACE_OS::mmap (0,
85 if (this->process_lock_
== MAP_FAILED
)
89 && ACE_OS::mutex_init (this->process_lock_
,
96 ACE_TEXT ("ACE_Mutex::ACE_Mutex")));
102 // local mutex init if USYNC_PROCESS flag is not enabled.
104 ACE_UNUSED_ARG (mode
);
105 #endif /* ACE_HAS_PTHREADS || ACE_HAS_STHREADS */
107 if (ACE_OS::mutex_init (&this->lock_
,
111 ACE_ERROR ((LM_ERROR
,
113 ACE_TEXT ("ACE_Mutex::ACE_Mutex")));
114 #if defined(ACE_HAS_PTHREADS) || defined (ACE_HAS_STHREADS)
116 #endif /* ACE_HAS_PTHREADS || ACE_HAS_STHREADS */
119 ACE_Mutex::~ACE_Mutex (void)
121 // ACE_TRACE ("ACE_Mutex::~ACE_Mutex");
125 ACE_END_VERSIONED_NAMESPACE_DECL