Use =default for skeleton copy constructor
[ACE_TAO.git] / ACE / ace / Process_Semaphore.cpp
blobfa90ff58a47fd34c358a6f35648f85ad4da4f3ed
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"
14 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
16 ACE_ALLOC_HOOK_DEFINE(ACE_Process_Semaphore)
18 void
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));
24 this->lock_.dump ();
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,
31 void *arg,
32 int max)
33 #if defined (ACE_WIN32) || defined (ACE_HAS_POSIX_SEM)
34 : lock_ (count, USYNC_PROCESS, name, arg, max)
35 #else
36 : lock_ (ACE_TEXT_ALWAYS_CHAR (name),
37 ACE_SV_Semaphore_Complex::ACE_CREATE,
38 count)
39 #endif /* ACE_WIN32 || ACE_HAS_POSIX_SEM */
41 ACE_UNUSED_ARG (arg);
42 ACE_UNUSED_ARG (max);
43 // ACE_TRACE ("ACE_Process_Semaphore::ACE_Process_Semaphore");
46 // Explicitly destroy the semaphore.
48 int
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.
58 int
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 ();
64 #else
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).
72 int
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 ();
78 #else
79 return this->lock_.tryacquire (0, SEM_UNDO);
80 #endif /* defined (ACE_WIN32) || defined (ACE_HAS_POSIX_SEM) */
83 // Increment the semaphore, potentially unblocking
84 // a waiting thread.
86 int
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 ();
92 #else
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;
103 if (name == 0)
104 ACE_NEW_RETURN (p, ACE_Process_Semaphore (1, name), 0);
105 else
106 ACE_NEW_RETURN (p, ACE_Process_Semaphore (1, ACE::basename (name,
107 ACE_DIRECTORY_SEPARATOR_CHAR)),
109 return p;
112 ACE_END_VERSIONED_NAMESPACE_DECL