2 #include "ace/Global_Macros.h"
3 #include "ace/OS_NS_Thread.h"
5 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
7 #if defined (ACE_HAS_WCHAR)
8 // Semaphores don't offer wide-char names, so convert the name and forward
9 // to the narrow-char open().
11 ACE_SV_Semaphore_Simple::open (const wchar_t *name,
17 ACE_TRACE ("ACE_SV_Semaphore_Simple::open (wchar_t)");
18 return this->open (ACE_Wide_To_Ascii (name).char_rep (),
24 #endif /* ACE_HAS_WCHAR */
27 ACE_SV_Semaphore_Simple::control (int cmd,
31 ACE_TRACE ("ACE_SV_Semaphore_Simple::control");
32 return this->internal_id_ == -1 ?
33 -1 : ACE_OS::semctl (this->internal_id_, n, cmd, arg);
36 // Close a ACE_SV_Semaphore, marking it as invalid for subsequent
40 ACE_SV_Semaphore_Simple::close (void)
42 ACE_TRACE ("ACE_SV_Semaphore_Simple::close");
43 #ifdef ACE_HAS_SYSV_IPC
46 ACE_NOTSUP_RETURN (-1);
50 // General ACE_SV_Semaphore operation on an array of SV_Semaphores.
53 ACE_SV_Semaphore_Simple::op (sembuf op_vec[], u_short n) const
55 ACE_TRACE ("ACE_SV_Semaphore_Simple::op");
56 return this->internal_id_ == -1
57 ? -1 : ACE_OS::semop (this->internal_id_, op_vec, n);
60 // Wait until a ACE_SV_Semaphore's value is greater than 0, the
61 // decrement it by 1 and return. Dijkstra's P operation, Tannenbaums
65 ACE_SV_Semaphore_Simple::acquire (u_short n, short flags) const
67 ACE_TRACE ("ACE_SV_Semaphore_Simple::acquire");
68 return this->op (-1, n, flags);
72 ACE_SV_Semaphore_Simple::acquire_read (u_short n, short flags) const
74 ACE_TRACE ("ACE_SV_Semaphore_Simple::acquire_read");
75 return this->acquire (n, flags);
79 ACE_SV_Semaphore_Simple::acquire_write (u_short n, short flags) const
81 ACE_TRACE ("ACE_SV_Semaphore_Simple::acquire_write");
82 return this->acquire (n, flags);
85 // Non-blocking version of acquire().
88 ACE_SV_Semaphore_Simple::tryacquire (u_short n, short flags) const
90 ACE_TRACE ("ACE_SV_Semaphore_Simple::tryacquire");
91 return this->op (-1, n, flags | IPC_NOWAIT);
94 // Non-blocking version of acquire().
97 ACE_SV_Semaphore_Simple::tryacquire_read (u_short n, short flags) const
99 ACE_TRACE ("ACE_SV_Semaphore_Simple::tryacquire_read");
100 return this->tryacquire (n, flags);
103 // Non-blocking version of acquire().
106 ACE_SV_Semaphore_Simple::tryacquire_write (u_short n, short flags) const
108 ACE_TRACE ("ACE_SV_Semaphore_Simple::tryacquire_write");
109 return this->tryacquire (n, flags);
112 // Increment ACE_SV_Semaphore by one. Dijkstra's V operation,
113 // Tannenbaums UP operation.
116 ACE_SV_Semaphore_Simple::release (u_short n, short flags) const
118 ACE_TRACE ("ACE_SV_Semaphore_Simple::release");
119 return this->op (1, n, flags);
123 ACE_SV_Semaphore_Simple::get_id (void) const
125 ACE_TRACE ("ACE_SV_Semaphore_Simple::get_id");
126 return this->internal_id_;
129 ACE_END_VERSIONED_NAMESPACE_DECL