summaryrefslogtreecommitdiff
path: root/ACE/ace/Mutex.inl
diff options
context:
space:
mode:
Diffstat (limited to 'ACE/ace/Mutex.inl')
-rw-r--r--ACE/ace/Mutex.inl148
1 files changed, 92 insertions, 56 deletions
diff --git a/ACE/ace/Mutex.inl b/ACE/ace/Mutex.inl
index 632172dd006..42870709716 100644
--- a/ACE/ace/Mutex.inl
+++ b/ACE/ace/Mutex.inl
@@ -2,16 +2,23 @@
#include "ace/OS_NS_sys_mman.h"
+#if defined (ACE_HAS_ALLOC_HOOKS)
+# include "ace/Malloc_Base.h"
+#endif /* ACE_HAS_ALLOC_HOOKS */
+
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
ACE_INLINE int
ACE_Mutex::acquire_read (void)
{
// ACE_TRACE ("ACE_Mutex::acquire_read");
-#if defined (ACE_HAS_PTHREADS) || defined(ACE_HAS_STHREADS)
- if (this->process_lock_)
- return ACE_OS::mutex_lock (this->process_lock_);
-#endif /* ACE_HAS_PTHREADS || ACE_HAS_STHREADS */
+#ifdef ACE_MUTEX_PROCESS_LOCK_IS_MUTEX
+ if (this->process_lock_)
+ return ACE_OS::mutex_lock (this->process_lock_);
+#elif defined ACE_MUTEX_PROCESS_LOCK_IS_SEMA
+ if (this->process_lock_)
+ return ACE_OS::sema_wait (this->process_lock_);
+#endif /* ACE_MUTEX_PROCESS_LOCK_IS_MUTEX */
return ACE_OS::mutex_lock (&this->lock_);
}
@@ -19,10 +26,13 @@ ACE_INLINE int
ACE_Mutex::acquire_write (void)
{
// ACE_TRACE ("ACE_Mutex::acquire_write");
-#if defined (ACE_HAS_PTHREADS) || defined(ACE_HAS_STHREADS)
- if (this->process_lock_)
- return ACE_OS::mutex_lock (this->process_lock_);
-#endif /* ACE_HAS_PTHREADS || ACE_HAS_STHREADS */
+#ifdef ACE_MUTEX_PROCESS_LOCK_IS_MUTEX
+ if (this->process_lock_)
+ return ACE_OS::mutex_lock (this->process_lock_);
+#elif defined ACE_MUTEX_PROCESS_LOCK_IS_SEMA
+ if (this->process_lock_)
+ return ACE_OS::sema_wait (this->process_lock_);
+#endif /* ACE_MUTEX_PROCESS_LOCK_IS_MUTEX */
return ACE_OS::mutex_lock (&this->lock_);
}
@@ -30,10 +40,13 @@ ACE_INLINE int
ACE_Mutex::tryacquire_read (void)
{
// ACE_TRACE ("ACE_Mutex::tryacquire_read");
-#if defined (ACE_HAS_PTHREADS) || defined(ACE_HAS_STHREADS)
- if (this->process_lock_)
- return ACE_OS::mutex_trylock (this->process_lock_);
-#endif /* ACE_HAS_PTHREADS || ACE_HAS_STHREADS */
+#ifdef ACE_MUTEX_PROCESS_LOCK_IS_MUTEX
+ if (this->process_lock_)
+ return ACE_OS::mutex_trylock (this->process_lock_);
+#elif defined ACE_MUTEX_PROCESS_LOCK_IS_SEMA
+ if (this->process_lock_)
+ return ACE_OS::sema_trywait (this->process_lock_);
+#endif /* ACE_MUTEX_PROCESS_LOCK_IS_MUTEX */
return ACE_OS::mutex_trylock (&this->lock_);
}
@@ -41,10 +54,10 @@ ACE_INLINE const ACE_mutex_t &
ACE_Mutex::lock (void) const
{
// ACE_TRACE ("ACE_Mutex::lock");
-#if defined (ACE_HAS_PTHREADS) || defined(ACE_HAS_STHREADS)
+#ifdef ACE_MUTEX_PROCESS_LOCK_IS_MUTEX
if (this->process_lock_)
return *this->process_lock_;
-#endif /* ACE_HAS_PTHREADS || ACE_HAS_STHREADS */
+#endif /* ACE_MUTEX_PROCESS_LOCK_IS_MUTEX */
return this->lock_;
}
@@ -52,10 +65,10 @@ ACE_INLINE ACE_mutex_t &
ACE_Mutex::lock (void)
{
// ACE_TRACE ("ACE_Mutex::lock");
-#if defined (ACE_HAS_PTHREADS) || defined(ACE_HAS_STHREADS)
+#ifdef ACE_MUTEX_PROCESS_LOCK_IS_MUTEX
if (this->process_lock_)
return *this->process_lock_;
-#endif /* ACE_HAS_PTHREADS || ACE_HAS_STHREADS */
+#endif /* ACE_MUTEX_PROCESS_LOCK_IS_MUTEX */
return this->lock_;
}
@@ -63,10 +76,13 @@ ACE_INLINE int
ACE_Mutex::tryacquire_write (void)
{
// ACE_TRACE ("ACE_Mutex::tryacquire_write");
-#if defined (ACE_HAS_PTHREADS) || defined(ACE_HAS_STHREADS)
- if (this->process_lock_)
- return ACE_OS::mutex_trylock (this->process_lock_);
-#endif /* ACE_HAS_PTHREADS || ACE_HAS_STHREADS */
+#ifdef ACE_MUTEX_PROCESS_LOCK_IS_MUTEX
+ if (this->process_lock_)
+ return ACE_OS::mutex_trylock (this->process_lock_);
+#elif defined ACE_MUTEX_PROCESS_LOCK_IS_SEMA
+ if (this->process_lock_)
+ return ACE_OS::sema_trywait (this->process_lock_);
+#endif /* ACE_MUTEX_PROCESS_LOCK_IS_MUTEX */
return ACE_OS::mutex_trylock (&this->lock_);
}
@@ -81,10 +97,13 @@ ACE_INLINE int
ACE_Mutex::acquire (void)
{
// ACE_TRACE ("ACE_Mutex::acquire");
-#if defined (ACE_HAS_PTHREADS) || defined(ACE_HAS_STHREADS)
- if (this->process_lock_)
- return ACE_OS::mutex_lock (this->process_lock_);
-#endif /* ACE_HAS_PTHREADS || ACE_HAS_STHREADS */
+#ifdef ACE_MUTEX_PROCESS_LOCK_IS_MUTEX
+ if (this->process_lock_)
+ return ACE_OS::mutex_lock (this->process_lock_);
+#elif defined ACE_MUTEX_PROCESS_LOCK_IS_SEMA
+ if (this->process_lock_)
+ return ACE_OS::sema_wait (this->process_lock_);
+#endif /* ACE_MUTEX_PROCESS_LOCK_IS_MUTEX */
return ACE_OS::mutex_lock (&this->lock_);
}
@@ -92,20 +111,26 @@ ACE_INLINE int
ACE_Mutex::acquire (ACE_Time_Value &tv)
{
// ACE_TRACE ("ACE_Mutex::acquire");
- #if defined (ACE_HAS_PTHREADS) || defined(ACE_HAS_STHREADS)
- if (this->process_lock_)
- return ACE_OS::mutex_lock (this->process_lock_, tv);
-#endif /* ACE_HAS_PTHREADS || ACE_HAS_STHREADS*/
+#ifdef ACE_MUTEX_PROCESS_LOCK_IS_MUTEX
+ if (this->process_lock_)
+ return ACE_OS::mutex_lock (this->process_lock_, tv);
+#elif defined ACE_MUTEX_PROCESS_LOCK_IS_SEMA
+ if (this->process_lock_)
+ return ACE_OS::sema_wait (this->process_lock_, tv);
+#endif /* ACE_MUTEX_PROCESS_LOCK_IS_MUTEX */
return ACE_OS::mutex_lock (&this->lock_, tv);
}
ACE_INLINE int
ACE_Mutex::acquire (ACE_Time_Value *tv)
{
- #if defined (ACE_HAS_PTHREADS) || defined(ACE_HAS_STHREADS)
- if (this->process_lock_)
- return ACE_OS::mutex_lock (this->process_lock_, tv);
-#endif /* ACE_HAS_PTHREADS || ACE_HAS_STHREADS*/
+#ifdef ACE_MUTEX_PROCESS_LOCK_IS_MUTEX
+ if (this->process_lock_)
+ return ACE_OS::mutex_lock (this->process_lock_, tv);
+#elif defined ACE_MUTEX_PROCESS_LOCK_IS_SEMA
+ if (this->process_lock_)
+ return ACE_OS::sema_wait (this->process_lock_, tv);
+#endif /* ACE_MUTEX_PROCESS_LOCK_IS_MUTEX */
return ACE_OS::mutex_lock (&this->lock_, tv);
}
@@ -113,10 +138,13 @@ ACE_INLINE int
ACE_Mutex::tryacquire (void)
{
// ACE_TRACE ("ACE_Mutex::tryacquire");
-#if defined (ACE_HAS_PTHREADS) || defined(ACE_HAS_STHREADS)
- if (this->process_lock_)
- return ACE_OS::mutex_trylock (this->process_lock_);
-#endif /* ACE_HAS_PTHREADS || ACE_HAS_STHREADS */
+#ifdef ACE_MUTEX_PROCESS_LOCK_IS_MUTEX
+ if (this->process_lock_)
+ return ACE_OS::mutex_trylock (this->process_lock_);
+#elif defined ACE_MUTEX_PROCESS_LOCK_IS_SEMA
+ if (this->process_lock_)
+ return ACE_OS::sema_trywait (this->process_lock_);
+#endif /* ACE_MUTEX_PROCESS_LOCK_IS_MUTEX */
return ACE_OS::mutex_trylock (&this->lock_);
}
@@ -124,10 +152,13 @@ ACE_INLINE int
ACE_Mutex::release (void)
{
// ACE_TRACE ("ACE_Mutex::release");
-#if defined (ACE_HAS_PTHREADS) || defined(ACE_HAS_STHREADS)
- if (this->process_lock_)
- return ACE_OS::mutex_unlock (this->process_lock_);
-#endif /* ACE_HAS_PTHREADS || ACE_HAS_STHREADS */
+#ifdef ACE_MUTEX_PROCESS_LOCK_IS_MUTEX
+ if (this->process_lock_)
+ return ACE_OS::mutex_unlock (this->process_lock_);
+#elif defined ACE_MUTEX_PROCESS_LOCK_IS_SEMA
+ if (this->process_lock_)
+ return ACE_OS::sema_post (this->process_lock_);
+#endif /* ACE_MUTEX_PROCESS_LOCK_IS_MUTEX */
return ACE_OS::mutex_unlock (&this->lock_);
}
@@ -136,7 +167,7 @@ ACE_Mutex::remove (void)
{
// ACE_TRACE ("ACE_Mutex::remove");
int result = 0;
-#if defined (ACE_HAS_PTHREADS) || defined (ACE_HAS_STHREADS)
+#ifdef ACE_MUTEX_USE_PROCESS_LOCK
// In the case of a interprocess mutex, the owner is the first
// process that created the shared memory object. In this case, the
// lockname_ pointer will be non-zero (points to allocated memory
@@ -150,6 +181,7 @@ ACE_Mutex::remove (void)
this->removed_ = true;
// Only destroy the lock if we're the ones who initialized
// it.
+# ifdef ACE_MUTEX_PROCESS_LOCK_IS_MUTEX
if (!this->lockname_)
ACE_OS::munmap ((void *) this->process_lock_,
sizeof (ACE_mutex_t));
@@ -159,24 +191,28 @@ ACE_Mutex::remove (void)
ACE_OS::munmap ((void *) this->process_lock_,
sizeof (ACE_mutex_t));
ACE_OS::shm_unlink (this->lockname_);
- ACE_OS::free (
- static_cast<void *> (
- const_cast<ACE_TCHAR *> (this->lockname_)));
}
+# elif defined ACE_MUTEX_PROCESS_LOCK_IS_SEMA
+ result = ACE_OS::sema_destroy (this->process_lock_);
+# endif /* ACE_MUTEX_PROCESS_LOCK_IS_MUTEX */
+
+# ifdef ACE_HAS_ALLOC_HOOKS
+ ACE_Allocator::instance ()->free (const_cast<ACE_TCHAR *> (
+ this->lockname_));
+# else
+ ACE_OS::free (const_cast<ACE_TCHAR *> (this->lockname_));
+# endif /* ACE_HAS_ALLOC_HOOKS */
}
+ return result;
}
- else
- {
-#else /* !ACE_HAS_PTHREADS && !ACE_HAS_STHREADS */
- if (this->removed_ == false)
- {
- this->removed_ = true;
- result = ACE_OS::mutex_destroy (&this->lock_);
- }
-#endif /* ACE_HAS_PTHREADS || ACE_HAS_STHREADS */
-#if defined (ACE_HAS_PTHREADS) || defined (ACE_HAS_STHREADS)
- }
-#endif /* ACE_HAS_PTHREADS || ACE_HAS_STHREADS */
+#endif /* ACE_MUTEX_USE_PROCESS_LOCK */
+
+ if (this->removed_ == false)
+ {
+ this->removed_ = true;
+ result = ACE_OS::mutex_destroy (&this->lock_);
+ }
+
return result;
}