SV_Semaphore_Simple.inl

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // SV_Semaphore_Simple.inl,v 4.4 2006/03/14 21:15:49 sjiang Exp
00004 
00005 #include "ace/Global_Macros.h"
00006 #include "ace/OS_NS_Thread.h"
00007 
00008 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00009 
00010 #if defined (ACE_HAS_WCHAR)
00011 // Semaphores don't offer wide-char names, so convert the name and forward
00012 // to the narrow-char open().
00013 ACE_INLINE int
00014 ACE_SV_Semaphore_Simple::open (const wchar_t *name,
00015                                short flags,
00016                                int initial_value,
00017                                u_short nsems,
00018                                mode_t perms)
00019 {
00020   ACE_TRACE ("ACE_SV_Semaphore_Simple::open (wchar_t)");
00021   return this->open (ACE_Wide_To_Ascii (name).char_rep (),
00022                      flags,
00023                      initial_value,
00024                      nsems,
00025                      perms);
00026 }
00027 #endif /* ACE_HAS_WCHAR */
00028 
00029 ACE_INLINE int
00030 ACE_SV_Semaphore_Simple::control (int cmd,
00031                                   semun arg,
00032                                   u_short n) const
00033 {
00034   ACE_TRACE ("ACE_SV_Semaphore_Simple::control");
00035   return this->internal_id_ == -1 ?
00036     -1 : ACE_OS::semctl (this->internal_id_, n, cmd, arg);
00037 }
00038 
00039 // Close a ACE_SV_Semaphore, marking it as invalid for subsequent
00040 // operations...
00041 
00042 ACE_INLINE int
00043 ACE_SV_Semaphore_Simple::close (void)
00044 {
00045   ACE_TRACE ("ACE_SV_Semaphore_Simple::close");
00046   return this->init ();
00047 }
00048 
00049 // General ACE_SV_Semaphore operation on an array of SV_Semaphores.
00050 
00051 ACE_INLINE int
00052 ACE_SV_Semaphore_Simple::op (sembuf op_vec[], u_short n) const
00053 {
00054   ACE_TRACE ("ACE_SV_Semaphore_Simple::op");
00055   return this->internal_id_ == -1
00056     ? -1 : ACE_OS::semop (this->internal_id_, op_vec, n);
00057 }
00058 
00059 // Wait until a ACE_SV_Semaphore's value is greater than 0, the
00060 // decrement it by 1 and return. Dijkstra's P operation, Tannenbaums
00061 // DOWN operation.
00062 
00063 ACE_INLINE int
00064 ACE_SV_Semaphore_Simple::acquire (u_short n, short flags) const
00065 {
00066   ACE_TRACE ("ACE_SV_Semaphore_Simple::acquire");
00067   return this->op (-1, n, flags);
00068 }
00069 
00070 ACE_INLINE int
00071 ACE_SV_Semaphore_Simple::acquire_read (u_short n, short flags) const
00072 {
00073   ACE_TRACE ("ACE_SV_Semaphore_Simple::acquire_read");
00074   return this->acquire (n, flags);
00075 }
00076 
00077 ACE_INLINE int
00078 ACE_SV_Semaphore_Simple::acquire_write (u_short n, short flags) const
00079 {
00080   ACE_TRACE ("ACE_SV_Semaphore_Simple::acquire_write");
00081   return this->acquire (n, flags);
00082 }
00083 
00084 // Non-blocking version of acquire().
00085 
00086 ACE_INLINE int
00087 ACE_SV_Semaphore_Simple::tryacquire (u_short n, short flags) const
00088 {
00089   ACE_TRACE ("ACE_SV_Semaphore_Simple::tryacquire");
00090   return this->op (-1, n, flags | IPC_NOWAIT);
00091 }
00092 
00093 // Non-blocking version of acquire().
00094 
00095 ACE_INLINE int
00096 ACE_SV_Semaphore_Simple::tryacquire_read (u_short n, short flags) const
00097 {
00098   ACE_TRACE ("ACE_SV_Semaphore_Simple::tryacquire_read");
00099   return this->tryacquire (n, flags);
00100 }
00101 
00102 // Non-blocking version of acquire().
00103 
00104 ACE_INLINE int
00105 ACE_SV_Semaphore_Simple::tryacquire_write (u_short n, short flags) const
00106 {
00107   ACE_TRACE ("ACE_SV_Semaphore_Simple::tryacquire_write");
00108   return this->tryacquire (n, flags);
00109 }
00110 
00111 // Increment ACE_SV_Semaphore by one. Dijkstra's V operation,
00112 // Tannenbaums UP operation.
00113 
00114 ACE_INLINE int
00115 ACE_SV_Semaphore_Simple::release (u_short n, short flags) const
00116 {
00117   ACE_TRACE ("ACE_SV_Semaphore_Simple::release");
00118   return this->op (1, n, flags);
00119 }
00120 
00121 ACE_INLINE int
00122 ACE_SV_Semaphore_Simple::get_id (void) const
00123 {
00124   ACE_TRACE ("ACE_SV_Semaphore_Simple::get_id");
00125   return this->internal_id_;
00126 }
00127 
00128 ACE_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 09:42:06 2006 for ACE by doxygen 1.3.6