Process_Semaphore.cpp

Go to the documentation of this file.
00001 // $Id: Process_Semaphore.cpp 80826 2008-03-04 14:51:23Z wotte $
00002 
00003 #include "ace/Process_Semaphore.h"
00004 #include "ace/Log_Msg.h"
00005 #include "ace/OS_Memory.h"
00006 
00007 #if !defined (__ACE_INLINE__)
00008 #include "ace/Process_Semaphore.inl"
00009 #endif /* __ACE_INLINE__ */
00010 
00011 #include "ace/ACE.h"
00012 
00013 ACE_RCSID(ace, Process_Semaphore, "$Id: Process_Semaphore.cpp 80826 2008-03-04 14:51:23Z wotte $")
00014 
00015 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00016 
00017 void
00018 ACE_Process_Semaphore::dump (void) const
00019 {
00020 #if defined (ACE_HAS_DUMP)
00021 // ACE_TRACE ("ACE_Process_Semaphore::dump");
00022   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00023   this->lock_.dump ();
00024   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00025 #endif /* ACE_HAS_DUMP */
00026 }
00027 
00028 ACE_Process_Semaphore::ACE_Process_Semaphore (u_int count,
00029                                               const ACE_TCHAR *name,
00030                                               void *arg,
00031                                               int max)
00032 #if defined (ACE_WIN32) || defined (ACE_HAS_POSIX_SEM)
00033   : lock_ (count, USYNC_PROCESS, name, arg, max)
00034 #else
00035   : lock_ (ACE_TEXT_ALWAYS_CHAR (name),
00036            ACE_SV_Semaphore_Complex::ACE_CREATE,
00037            count)
00038 #endif /* ACE_WIN32 || ACE_HAS_POSIX_SEM */
00039 {
00040   ACE_UNUSED_ARG (arg);
00041   ACE_UNUSED_ARG (max);
00042 // ACE_TRACE ("ACE_Process_Semaphore::ACE_Process_Semaphore");
00043 }
00044 
00045 // Explicitly destroy the semaphore.
00046 
00047 int
00048 ACE_Process_Semaphore::remove (void)
00049 {
00050 // ACE_TRACE ("ACE_Process_Semaphore::remove");
00051   return this->lock_.remove ();
00052 }
00053 
00054 // Block the thread until the semaphore count becomes
00055 // greater than 0, then decrement it.
00056 
00057 int
00058 ACE_Process_Semaphore::acquire (void)
00059 {
00060 // ACE_TRACE ("ACE_Process_Semaphore::acquire");
00061 #if defined (ACE_WIN32) || defined (ACE_HAS_POSIX_SEM)
00062   return this->lock_.acquire ();
00063 #else
00064   return this->lock_.acquire (0, SEM_UNDO);
00065 #endif /* defined (ACE_WIN32) || defined (ACE_HAS_POSIX_SEM) */
00066 }
00067 
00068 // Conditionally decrement the semaphore if count is greater
00069 // than 0 (i.e., won't block).
00070 
00071 int
00072 ACE_Process_Semaphore::tryacquire (void)
00073 {
00074 // ACE_TRACE ("ACE_Process_Semaphore::tryacquire");
00075 #if defined (ACE_WIN32) || defined (ACE_HAS_POSIX_SEM)
00076   return this->lock_.tryacquire ();
00077 #else
00078   return this->lock_.tryacquire (0, SEM_UNDO);
00079 #endif /* defined (ACE_WIN32) || defined (ACE_HAS_POSIX_SEM) */
00080 }
00081 
00082 // Increment the semaphore, potentially unblocking
00083 // a waiting thread.
00084 
00085 int
00086 ACE_Process_Semaphore::release (void)
00087 {
00088 // ACE_TRACE ("ACE_Process_Semaphore::release");
00089 #if defined (ACE_WIN32) || defined (ACE_HAS_POSIX_SEM)
00090   return this->lock_.release ();
00091 #else
00092   return this->lock_.release (0, SEM_UNDO);
00093 #endif /* defined (ACE_WIN32) || defined (ACE_HAS_POSIX_SEM) */
00094 }
00095 
00096 /*****************************************************************************/
00097 
00098 ACE_Process_Semaphore *
00099 ACE_Malloc_Lock_Adapter_T<ACE_Process_Semaphore>::operator () (const ACE_TCHAR *name)
00100 {
00101   ACE_Process_Semaphore *p = 0;
00102   if (name == 0)
00103     ACE_NEW_RETURN (p, ACE_Process_Semaphore (1, name), 0);
00104   else
00105     ACE_NEW_RETURN (p, ACE_Process_Semaphore (1, ACE::basename (name,
00106                                                                 ACE_DIRECTORY_SEPARATOR_CHAR)),
00107                     0);
00108   return p;
00109 }
00110 
00111 ACE_END_VERSIONED_NAMESPACE_DECL

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