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__ */
14 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
16 ACE_ALLOC_HOOK_DEFINE(ACE_Process_Semaphore
)
19 ACE_Process_Semaphore::dump () const
21 #if defined (ACE_HAS_DUMP)
22 // ACE_TRACE ("ACE_Process_Semaphore::dump");
23 ACELIB_DEBUG ((LM_DEBUG
, ACE_BEGIN_DUMP
, this));
25 ACELIB_DEBUG ((LM_DEBUG
, ACE_END_DUMP
));
26 #endif /* ACE_HAS_DUMP */
29 ACE_Process_Semaphore::ACE_Process_Semaphore (u_int count
,
30 const ACE_TCHAR
*name
,
33 #if defined (ACE_WIN32) || defined (ACE_HAS_POSIX_SEM)
34 : lock_ (count
, USYNC_PROCESS
, name
, arg
, max
)
36 : lock_ (ACE_TEXT_ALWAYS_CHAR (name
),
37 ACE_SV_Semaphore_Complex::ACE_CREATE
,
39 #endif /* ACE_WIN32 || ACE_HAS_POSIX_SEM */
43 // ACE_TRACE ("ACE_Process_Semaphore::ACE_Process_Semaphore");
46 // Explicitly destroy the semaphore.
49 ACE_Process_Semaphore::remove ()
51 // ACE_TRACE ("ACE_Process_Semaphore::remove");
52 return this->lock_
.remove ();
55 // Block the thread until the semaphore count becomes
56 // greater than 0, then decrement it.
59 ACE_Process_Semaphore::acquire ()
61 // ACE_TRACE ("ACE_Process_Semaphore::acquire");
62 #if defined (ACE_WIN32) || defined (ACE_HAS_POSIX_SEM)
63 return this->lock_
.acquire ();
65 return this->lock_
.acquire (0, SEM_UNDO
);
66 #endif /* defined (ACE_WIN32) || defined (ACE_HAS_POSIX_SEM) */
69 // Conditionally decrement the semaphore if count is greater
70 // than 0 (i.e., won't block).
73 ACE_Process_Semaphore::tryacquire ()
75 // ACE_TRACE ("ACE_Process_Semaphore::tryacquire");
76 #if defined (ACE_WIN32) || defined (ACE_HAS_POSIX_SEM)
77 return this->lock_
.tryacquire ();
79 return this->lock_
.tryacquire (0, SEM_UNDO
);
80 #endif /* defined (ACE_WIN32) || defined (ACE_HAS_POSIX_SEM) */
83 // Increment the semaphore, potentially unblocking
87 ACE_Process_Semaphore::release ()
89 // ACE_TRACE ("ACE_Process_Semaphore::release");
90 #if defined (ACE_WIN32) || defined (ACE_HAS_POSIX_SEM)
91 return this->lock_
.release ();
93 return this->lock_
.release (0, SEM_UNDO
);
94 #endif /* defined (ACE_WIN32) || defined (ACE_HAS_POSIX_SEM) */
97 /*****************************************************************************/
99 ACE_Process_Semaphore
*
100 ACE_Malloc_Lock_Adapter_T
<ACE_Process_Semaphore
>::operator () (const ACE_TCHAR
*name
)
102 ACE_Process_Semaphore
*p
= 0;
104 ACE_NEW_RETURN (p
, ACE_Process_Semaphore (1, name
), 0);
106 ACE_NEW_RETURN (p
, ACE_Process_Semaphore (1, ACE::basename (name
,
107 ACE_DIRECTORY_SEPARATOR_CHAR
)),
112 ACE_END_VERSIONED_NAMESPACE_DECL