00001 
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 
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 
00022   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00023   this->lock_.dump ();
00024   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00025 #endif 
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 
00039 {
00040   arg = arg;
00041   max = max;
00042 
00043 }
00044 
00045 
00046 
00047 
00048 
00049 
00050 
00051 
00052 int
00053 ACE_Process_Semaphore::remove (void)
00054 {
00055 
00056   return this->lock_.remove ();
00057 }
00058 
00059 
00060 
00061 
00062 int
00063 ACE_Process_Semaphore::acquire (void)
00064 {
00065 
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 
00071 }
00072 
00073 
00074 
00075 
00076 int
00077 ACE_Process_Semaphore::tryacquire (void)
00078 {
00079 
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 
00085 }
00086 
00087 
00088 
00089 
00090 int
00091 ACE_Process_Semaphore::release (void)
00092 {
00093 
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 
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