Correct feature names
[ACE_TAO.git] / ACE / ace / Process_Semaphore.cpp
blobbb3f94e4efc842e951a8db3995b92aecc05af6fc
1 #include "ace/Process_Semaphore.h"
2 #include "ace/Log_Category.h"
3 #include "ace/OS_Memory.h"
4 #if defined (ACE_HAS_ALLOC_HOOKS)
5 # include "ace/Malloc_Base.h"
6 #endif /* ACE_HAS_ALLOC_HOOKS */
8 #if !defined (__ACE_INLINE__)
9 #include "ace/Process_Semaphore.inl"
10 #endif /* __ACE_INLINE__ */
12 #include "ace/ACE.h"
16 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
18 ACE_ALLOC_HOOK_DEFINE(ACE_Process_Semaphore)
20 void
21 ACE_Process_Semaphore::dump (void) const
23 #if defined (ACE_HAS_DUMP)
24 // ACE_TRACE ("ACE_Process_Semaphore::dump");
25 ACELIB_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
26 this->lock_.dump ();
27 ACELIB_DEBUG ((LM_DEBUG, ACE_END_DUMP));
28 #endif /* ACE_HAS_DUMP */
31 ACE_Process_Semaphore::ACE_Process_Semaphore (u_int count,
32 const ACE_TCHAR *name,
33 void *arg,
34 int max)
35 #if defined (ACE_WIN32) || defined (ACE_HAS_POSIX_SEM)
36 : lock_ (count, USYNC_PROCESS, name, arg, max)
37 #else
38 : lock_ (ACE_TEXT_ALWAYS_CHAR (name),
39 ACE_SV_Semaphore_Complex::ACE_CREATE,
40 count)
41 #endif /* ACE_WIN32 || ACE_HAS_POSIX_SEM */
43 ACE_UNUSED_ARG (arg);
44 ACE_UNUSED_ARG (max);
45 // ACE_TRACE ("ACE_Process_Semaphore::ACE_Process_Semaphore");
48 // Explicitly destroy the semaphore.
50 int
51 ACE_Process_Semaphore::remove (void)
53 // ACE_TRACE ("ACE_Process_Semaphore::remove");
54 return this->lock_.remove ();
57 // Block the thread until the semaphore count becomes
58 // greater than 0, then decrement it.
60 int
61 ACE_Process_Semaphore::acquire (void)
63 // ACE_TRACE ("ACE_Process_Semaphore::acquire");
64 #if defined (ACE_WIN32) || defined (ACE_HAS_POSIX_SEM)
65 return this->lock_.acquire ();
66 #else
67 return this->lock_.acquire (0, SEM_UNDO);
68 #endif /* defined (ACE_WIN32) || defined (ACE_HAS_POSIX_SEM) */
71 // Conditionally decrement the semaphore if count is greater
72 // than 0 (i.e., won't block).
74 int
75 ACE_Process_Semaphore::tryacquire (void)
77 // ACE_TRACE ("ACE_Process_Semaphore::tryacquire");
78 #if defined (ACE_WIN32) || defined (ACE_HAS_POSIX_SEM)
79 return this->lock_.tryacquire ();
80 #else
81 return this->lock_.tryacquire (0, SEM_UNDO);
82 #endif /* defined (ACE_WIN32) || defined (ACE_HAS_POSIX_SEM) */
85 // Increment the semaphore, potentially unblocking
86 // a waiting thread.
88 int
89 ACE_Process_Semaphore::release (void)
91 // ACE_TRACE ("ACE_Process_Semaphore::release");
92 #if defined (ACE_WIN32) || defined (ACE_HAS_POSIX_SEM)
93 return this->lock_.release ();
94 #else
95 return this->lock_.release (0, SEM_UNDO);
96 #endif /* defined (ACE_WIN32) || defined (ACE_HAS_POSIX_SEM) */
99 /*****************************************************************************/
101 ACE_Process_Semaphore *
102 ACE_Malloc_Lock_Adapter_T<ACE_Process_Semaphore>::operator () (const ACE_TCHAR *name)
104 ACE_Process_Semaphore *p = 0;
105 if (name == 0)
106 ACE_NEW_RETURN (p, ACE_Process_Semaphore (1, name), 0);
107 else
108 ACE_NEW_RETURN (p, ACE_Process_Semaphore (1, ACE::basename (name,
109 ACE_DIRECTORY_SEPARATOR_CHAR)),
111 return p;
114 ACE_END_VERSIONED_NAMESPACE_DECL