Process_Semaphore.cpp

Go to the documentation of this file.
00001 // Process_Semaphore.cpp,v 4.11 2006/05/30 13:15:25 schmidt Exp
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, "Process_Semaphore.cpp,v 4.11 2006/05/30 13:15:25 schmidt Exp")
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   arg = arg;
00041   max = max;
00042 // ACE_TRACE ("ACE_Process_Semaphore::ACE_Process_Semaphore");
00043 }
00044 
00045 // ACE_Process_Semaphore::~ACE_Process_Semaphore (void)
00046 // {
00047 //   // ACE_TRACE ("ACE_Process_Semaphore::~ACE_Process_Semaphore");
00048 // }
00049 
00050 // Explicitly destroy the semaphore.
00051 
00052 int
00053 ACE_Process_Semaphore::remove (void)
00054 {
00055 // ACE_TRACE ("ACE_Process_Semaphore::remove");
00056   return this->lock_.remove ();
00057 }
00058 
00059 // Block the thread until the semaphore count becomes
00060 // greater than 0, then decrement it.
00061 
00062 int
00063 ACE_Process_Semaphore::acquire (void)
00064 {
00065 // ACE_TRACE ("ACE_Process_Semaphore::acquire");
00066 #if defined (ACE_WIN32) || defined (ACE_HAS_POSIX_SEM)
00067   return this->lock_.acquire ();
00068 #else
00069   return this->lock_.acquire (0, SEM_UNDO);
00070 #endif /* defined (ACE_WIN32) || defined (ACE_HAS_POSIX_SEM) */
00071 }
00072 
00073 // Conditionally decrement the semaphore if count is greater
00074 // than 0 (i.e., won't block).
00075 
00076 int
00077 ACE_Process_Semaphore::tryacquire (void)
00078 {
00079 // ACE_TRACE ("ACE_Process_Semaphore::tryacquire");
00080 #if defined (ACE_WIN32) || defined (ACE_HAS_POSIX_SEM)
00081   return this->lock_.tryacquire ();
00082 #else
00083   return this->lock_.tryacquire (0, SEM_UNDO);
00084 #endif /* defined (ACE_WIN32) || defined (ACE_HAS_POSIX_SEM) */
00085 }
00086 
00087 // Increment the semaphore, potentially unblocking
00088 // a waiting thread.
00089 
00090 int
00091 ACE_Process_Semaphore::release (void)
00092 {
00093 // ACE_TRACE ("ACE_Process_Semaphore::release");
00094 #if defined (ACE_WIN32) || defined (ACE_HAS_POSIX_SEM)
00095   return this->lock_.release ();
00096 #else
00097   return this->lock_.release (0, SEM_UNDO);
00098 #endif /* defined (ACE_WIN32) || defined (ACE_HAS_POSIX_SEM) */
00099 }
00100 
00101 /*****************************************************************************/
00102 
00103 ACE_Process_Semaphore *
00104 ACE_Malloc_Lock_Adapter_T<ACE_Process_Semaphore>::operator () (const ACE_TCHAR *name)
00105 {
00106   ACE_Process_Semaphore *p = 0;
00107   if (name == 0)
00108     ACE_NEW_RETURN (p, ACE_Process_Semaphore (1, name), 0);
00109   else
00110     ACE_NEW_RETURN (p, ACE_Process_Semaphore (1, ACE::basename (name,
00111                                                                 ACE_DIRECTORY_SEPARATOR_CHAR)),
00112                     0);
00113   return p;
00114 }
00115 
00116 ACE_END_VERSIONED_NAMESPACE_DECL

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