3 // $Id: SV_Semaphore_Simple.inl 80826 2008-03-04 14:51:23Z wotte $
5 #include "ace/Global_Macros.h"
6 #include "ace/OS_NS_Thread.h"
8 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
10 #if defined (ACE_HAS_WCHAR)
11 // Semaphores don't offer wide-char names, so convert the name and forward
12 // to the narrow-char open().
14 ACE_SV_Semaphore_Simple::open (const wchar_t *name,
20 ACE_TRACE ("ACE_SV_Semaphore_Simple::open (wchar_t)");
21 return this->open (ACE_Wide_To_Ascii (name).char_rep (),
27 #endif /* ACE_HAS_WCHAR */
30 ACE_SV_Semaphore_Simple::control (int cmd,
34 ACE_TRACE ("ACE_SV_Semaphore_Simple::control");
35 return this->internal_id_ == -1 ?
36 -1 : ACE_OS::semctl (this->internal_id_, n, cmd, arg);
39 // Close a ACE_SV_Semaphore, marking it as invalid for subsequent
43 ACE_SV_Semaphore_Simple::close (void)
45 ACE_TRACE ("ACE_SV_Semaphore_Simple::close");
49 // General ACE_SV_Semaphore operation on an array of SV_Semaphores.
52 ACE_SV_Semaphore_Simple::op (sembuf op_vec[], u_short n) const
54 ACE_TRACE ("ACE_SV_Semaphore_Simple::op");
55 return this->internal_id_ == -1
56 ? -1 : ACE_OS::semop (this->internal_id_, op_vec, n);
59 // Wait until a ACE_SV_Semaphore's value is greater than 0, the
60 // decrement it by 1 and return. Dijkstra's P operation, Tannenbaums
64 ACE_SV_Semaphore_Simple::acquire (u_short n, short flags) const
66 ACE_TRACE ("ACE_SV_Semaphore_Simple::acquire");
67 return this->op (-1, n, flags);
71 ACE_SV_Semaphore_Simple::acquire_read (u_short n, short flags) const
73 ACE_TRACE ("ACE_SV_Semaphore_Simple::acquire_read");
74 return this->acquire (n, flags);
78 ACE_SV_Semaphore_Simple::acquire_write (u_short n, short flags) const
80 ACE_TRACE ("ACE_SV_Semaphore_Simple::acquire_write");
81 return this->acquire (n, flags);
84 // Non-blocking version of acquire().
87 ACE_SV_Semaphore_Simple::tryacquire (u_short n, short flags) const
89 ACE_TRACE ("ACE_SV_Semaphore_Simple::tryacquire");
90 return this->op (-1, n, flags | IPC_NOWAIT);
93 // Non-blocking version of acquire().
96 ACE_SV_Semaphore_Simple::tryacquire_read (u_short n, short flags) const
98 ACE_TRACE ("ACE_SV_Semaphore_Simple::tryacquire_read");
99 return this->tryacquire (n, flags);
102 // Non-blocking version of acquire().
105 ACE_SV_Semaphore_Simple::tryacquire_write (u_short n, short flags) const
107 ACE_TRACE ("ACE_SV_Semaphore_Simple::tryacquire_write");
108 return this->tryacquire (n, flags);
111 // Increment ACE_SV_Semaphore by one. Dijkstra's V operation,
112 // Tannenbaums UP operation.
115 ACE_SV_Semaphore_Simple::release (u_short n, short flags) const
117 ACE_TRACE ("ACE_SV_Semaphore_Simple::release");
118 return this->op (1, n, flags);
122 ACE_SV_Semaphore_Simple::get_id (void) const
124 ACE_TRACE ("ACE_SV_Semaphore_Simple::get_id");
125 return this->internal_id_;
128 ACE_END_VERSIONED_NAMESPACE_DECL