#include <SV_Semaphore_Simple.h>
Inheritance diagram for ACE_SV_Semaphore_Simple:

Public Types | |
| enum | { ACE_CREATE = IPC_CREAT, ACE_EXCL = IPC_EXCL, ACE_OPEN = 0 } |
Public Methods | |
| ACE_SV_Semaphore_Simple (void) | |
| ACE_SV_Semaphore_Simple (key_t key, int flags=ACE_SV_Semaphore_Simple::ACE_CREATE, int initial_value=1, u_short nsems=1, int perms=ACE_DEFAULT_FILE_PERMS) | |
| ACE_SV_Semaphore_Simple (const char *name, int flags=ACE_SV_Semaphore_Simple::ACE_CREATE, int initial_value=1, u_short nsems=1, int perms=ACE_DEFAULT_FILE_PERMS) | |
| ~ACE_SV_Semaphore_Simple (void) | |
| int | open (const char *name, int flags=ACE_SV_Semaphore_Simple::ACE_CREATE, int initial_value=1, u_short nsems=1, int perms=ACE_DEFAULT_FILE_PERMS) |
| int | open (key_t key, int flags=ACE_SV_Semaphore_Simple::ACE_CREATE, int initial_value=1, u_short nsems=1, int perms=ACE_DEFAULT_FILE_PERMS) |
| Open or create one or more SV_Semaphores. We return 0 if all is OK, else -1. More... | |
| int | close (void) |
| Close a ACE_SV_Semaphore, marking it as invalid for subsequent operations... More... | |
| int | remove (void) const |
| int | acquire (u_short n=0, int flags=0) const |
| int | acquire_read (u_short n=0, int flags=0) const |
| Acquire a semaphore for reading. More... | |
| int | acquire_write (u_short n=0, int flags=0) const |
| Acquire a semaphore for writing. More... | |
| int | tryacquire (u_short n=0, int flags=0) const |
| Non-blocking version of <acquire>. More... | |
| int | tryacquire_read (u_short n=0, int flags=0) const |
| Try to acquire the semaphore for reading. More... | |
| int | tryacquire_write (u_short n=0, int flags=0) const |
| Try to acquire the semaphore for writing. More... | |
| int | release (u_short n=0, int flags=0) const |
| Increment ACE_SV_Semaphore by one. Dijkstra's V operation, Tannenbaums UP operation. More... | |
| int | op (int val, u_short semnum=0, int flags=SEM_UNDO) const |
| General ACE_SV_Semaphore operation. Increment or decrement by a specific amount (positive or negative; amount can`t be zero). More... | |
| int | op (sembuf op_vec[], u_short nsems) const |
| General ACE_SV_Semaphore operation on an array of SV_Semaphores. More... | |
| int | control (int cmd, semun arg, u_short n=0) const |
| int | control (int cmd, int value=0, u_short n=0) const |
| int | get_id (void) const |
| Get underlying internal id. More... | |
| void | dump (void) const |
| Dump the state of an object. More... | |
Public Attributes | |
| ACE_ALLOC_HOOK_DECLARE | |
| Declare the dynamic allocation hooks. More... | |
Protected Methods | |
| int | init (key_t k=ACE_static_cast(key_t, ACE_INVALID_SEM_KEY), int i=-1) |
| key_t | name_2_key (const char *name) |
Protected Attributes | |
| key_t | key_ |
| Semaphore key. More... | |
| int | internal_id_ |
| Internal ID to identify the semaphore group within this process. More... | |
| int | sem_number_ |
| Number of semaphores we're creating. More... | |
Definition at line 33 of file SV_Semaphore_Simple.h.
|
|
Definition at line 36 of file SV_Semaphore_Simple.h.
00037 {
00038 ACE_CREATE = IPC_CREAT,
00039 ACE_EXCL = IPC_EXCL,
00040 ACE_OPEN = 0
00041 };
|
|
|
Definition at line 194 of file SV_Semaphore_Simple.cpp. References ACE_TRACE, and init.
|
|
||||||||||||||||||||||||
|
Definition at line 105 of file SV_Semaphore_Simple.cpp. References ACE_ERROR, ACE_LIB_TEXT, ACE_TRACE, LM_ERROR, and open.
00110 : key_ (k) 00111 { 00112 ACE_TRACE ("ACE_SV_Semaphore_Simple::ACE_SV_Semaphore_Simple"); 00113 if (this->open (k, flags, initial_value, n, perms) == -1) 00114 ACE_ERROR ((LM_ERROR, ACE_LIB_TEXT ("%p\n"), ACE_LIB_TEXT ("ACE_SV_Semaphore::ACE_SV_Semaphore"))); 00115 } |
|
||||||||||||||||||||||||
|
Definition at line 171 of file SV_Semaphore_Simple.cpp. References ACE_ERROR, ACE_LIB_TEXT, ACE_TRACE, LM_ERROR, and open.
00176 {
00177 ACE_TRACE ("ACE_SV_Semaphore_Simple::ACE_SV_Semaphore_Simple");
00178 if (this->open (name,
00179 flags,
00180 initial_value,
00181 n,
00182 perms) == -1)
00183 ACE_ERROR ((LM_ERROR,
00184 ACE_LIB_TEXT ("%p\n"),
00185 ACE_LIB_TEXT ("ACE_SV_Semaphore_Simple::ACE_SV_Semaphore_Simple")));
00186 }
|
|
|
Definition at line 188 of file SV_Semaphore_Simple.cpp. References ACE_TRACE, and close.
|
|
||||||||||||
|
Wait until a ACE_SV_Semaphore's value is greater than 0, the decrement it by 1 and return. Dijkstra's P operation, Tannenbaums DOWN operation. Reimplemented in ACE_SV_Semaphore_Complex. Definition at line 43 of file SV_Semaphore_Simple.i. Referenced by ACE_SV_Semaphore_Complex::acquire, acquire_read, and acquire_write.
|
|
||||||||||||
|
Acquire a semaphore for reading.
Reimplemented in ACE_SV_Semaphore_Complex. Definition at line 50 of file SV_Semaphore_Simple.i. References ACE_TRACE, and acquire.
|
|
||||||||||||
|
Acquire a semaphore for writing.
Reimplemented in ACE_SV_Semaphore_Complex. Definition at line 57 of file SV_Semaphore_Simple.i. References ACE_TRACE, and acquire.
|
|
|
Close a ACE_SV_Semaphore, marking it as invalid for subsequent operations...
Reimplemented in ACE_SV_Semaphore_Complex. Definition at line 22 of file SV_Semaphore_Simple.i. References ACE_TRACE, and init. Referenced by ~ACE_SV_Semaphore_Simple.
|
|
||||||||||||||||
|
Reimplemented in ACE_SV_Semaphore_Complex. Definition at line 24 of file SV_Semaphore_Simple.cpp. References ACE_TRACE, internal_id_, ACE_OS::semctl, and semun::val.
00027 {
00028 ACE_TRACE ("ACE_SV_Semaphore_Simple::control");
00029 if (this->internal_id_ == -1)
00030 return -1;
00031 else
00032 {
00033 semun semctl_arg;
00034
00035 semctl_arg.val = value;
00036 return ACE_OS::semctl (this->internal_id_,
00037 semnum,
00038 cmd,
00039 semctl_arg);
00040 }
00041 }
|
|
||||||||||||||||
|
Reimplemented in ACE_SV_Semaphore_Complex. Definition at line 9 of file SV_Semaphore_Simple.i. References ACE_TRACE, internal_id_, and ACE_OS::semctl. Referenced by ACE_SV_Semaphore_Complex::close, ACE_SV_Semaphore_Complex::control, ACE_SV_Semaphore_Complex::open, and remove.
00012 {
00013 ACE_TRACE ("ACE_SV_Semaphore_Simple::control");
00014 return this->internal_id_ == -1 ?
00015 -1 : ACE_OS::semctl (this->internal_id_, n, cmd, arg);
00016 }
|
|
|
Dump the state of an object.
Reimplemented in ACE_SV_Semaphore_Complex. Definition at line 18 of file SV_Semaphore_Simple.cpp. References ACE_TRACE.
00019 {
00020 ACE_TRACE ("ACE_SV_Semaphore_Simple::dump");
00021 }
|
|
|
Get underlying internal id.
Definition at line 101 of file SV_Semaphore_Simple.i. References ACE_TRACE, and internal_id_.
00102 {
00103 ACE_TRACE ("ACE_SV_Semaphore_Simple::get_id");
00104 return this->internal_id_;
00105 }
|
|
||||||||||||
|
Convert name to key This function is used internally to create keys for the semaphores. A valid name contains letters and digits only and MUST start with a letter. The method for generating names is not very sophisticated, so caller should not pass strings which match each other for the first LUSED characters when he wants to get a different key. Definition at line 44 of file SV_Semaphore_Simple.cpp. References ACE_TRACE, internal_id_, and key_. Referenced by ACE_SV_Semaphore_Complex::ACE_SV_Semaphore_Complex, ACE_SV_Semaphore_Simple, close, ACE_SV_Semaphore_Complex::close, and ACE_SV_Semaphore_Complex::open.
00045 {
00046 ACE_TRACE ("ACE_SV_Semaphore_Simple::init");
00047 this->key_ = k;
00048 this->internal_id_ = i;
00049 return 0;
00050 }
|
|
|
Definition at line 125 of file SV_Semaphore_Simple.cpp. References ACE_INVALID_SEM_KEY, ACE_TRACE, and ACE::crc32. Referenced by ACE_SV_Semaphore_Complex::ACE_SV_Semaphore_Complex, open, and ACE_SV_Semaphore_Complex::open.
00126 {
00127 ACE_TRACE ("ACE_SV_Semaphore_Simple::name_2_key");
00128
00129 if (name == 0)
00130 {
00131 errno = EINVAL;
00132 return ACE_static_cast (key_t, ACE_INVALID_SEM_KEY);
00133 }
00134
00135 // Basically "hash" the values in the <name>. This won't
00136 // necessarily guarantee uniqueness of all keys.
00137 // But (IMHO) CRC32 is good enough for most purposes (Carlos)
00138 #if defined (ACE_WIN64)
00139 // The cast below is legit...
00140 # pragma warning(push)
00141 # pragma warning(disable : 4312)
00142 #endif /* ACE_WIN64 */
00143 return (key_t) ACE::crc32 (name);
00144 #if defined (ACE_WIN64)
00145 # pragma warning(pop)
00146 #endif /* ACE_WIN64 */
00147 }
|
|
||||||||||||
|
General ACE_SV_Semaphore operation on an array of SV_Semaphores.
Reimplemented in ACE_SV_Semaphore_Complex. Definition at line 31 of file SV_Semaphore_Simple.i. References ACE_TRACE, internal_id_, and ACE_OS::semop.
00032 {
00033 ACE_TRACE ("ACE_SV_Semaphore_Simple::op");
00034 return this->internal_id_ == -1
00035 ? -1 : ACE_OS::semop (this->internal_id_, op_vec, n);
00036 }
|
|
||||||||||||||||
|
General ACE_SV_Semaphore operation. Increment or decrement by a specific amount (positive or negative; amount can`t be zero).
Reimplemented in ACE_SV_Semaphore_Complex. Definition at line 56 of file SV_Semaphore_Simple.cpp. References ACE_TRACE, internal_id_, and ACE_OS::semop. Referenced by acquire, ACE_SV_Semaphore_Complex::op, release, and tryacquire.
00057 {
00058 ACE_TRACE ("ACE_SV_Semaphore_Simple::op");
00059 sembuf op_op;
00060
00061 op_op.sem_num = n;
00062 op_op.sem_flg = flags;
00063
00064 if (this->internal_id_ == -1)
00065 return -1;
00066 else if ((op_op.sem_op = val) == 0)
00067 return -1;
00068 else
00069 return ACE_OS::semop (this->internal_id_, &op_op, 1);
00070 }
|
|
||||||||||||||||||||||||
|
Open or create one or more SV_Semaphores. We return 0 if all is OK, else -1.
Reimplemented in ACE_SV_Semaphore_Complex. Definition at line 76 of file SV_Semaphore_Simple.cpp. References ACE_BIT_ENABLED, ACE_INVALID_SEM_KEY, ACE_TRACE, internal_id_, IPC_CREAT, IPC_PRIVATE, key_, sem_number_, ACE_OS::semctl, ACE_OS::semget, SETVAL, and semun::val.
00081 {
00082 ACE_TRACE ("ACE_SV_Semaphore_Simple::open");
00083 union semun ivalue;
00084
00085 if (k == IPC_PRIVATE || k == ACE_static_cast (key_t, ACE_INVALID_SEM_KEY))
00086 return -1;
00087
00088 ivalue.val = initial_value;
00089 this->key_ = k;
00090 this->sem_number_ = n;
00091
00092 this->internal_id_ = ACE_OS::semget (this->key_, n, perms | flags);
00093
00094 if (this->internal_id_ == -1)
00095 return -1;
00096
00097 if (ACE_BIT_ENABLED (flags, IPC_CREAT))
00098 for (int i = 0; i < n; i++)
00099 if (ACE_OS::semctl (this->internal_id_, i, SETVAL, ivalue) == -1)
00100 return -1;
00101
00102 return 0;
00103 }
|
|
||||||||||||||||||||||||
|
Reimplemented in ACE_SV_Semaphore_Complex. Definition at line 153 of file SV_Semaphore_Simple.cpp. References ACE_DEFAULT_SEM_KEY, ACE_TRACE, and name_2_key. Referenced by ACE_SV_Semaphore_Simple.
00158 {
00159 ACE_TRACE ("ACE_SV_Semaphore_Simple::open");
00160
00161 key_t key;
00162
00163 if (name == 0)
00164 key = ACE_DEFAULT_SEM_KEY;
00165 else
00166 key = this->name_2_key (name);
00167
00168 return this->open (key, flags, initial_value, n, perms);
00169 }
|
|
||||||||||||
|
Increment ACE_SV_Semaphore by one. Dijkstra's V operation, Tannenbaums UP operation.
Reimplemented in ACE_SV_Semaphore_Complex. Definition at line 94 of file SV_Semaphore_Simple.i. Referenced by ACE_SV_Semaphore_Complex::release.
|
|
|
Remove all SV_Semaphores associated with a particular key. This call is intended to be called from a server, for example, when it is being shut down, as we do an IPC_RMID on the ACE_SV_Semaphore, regardless of whether other processes may be using it or not. Most other processes should use <close> below. Definition at line 207 of file SV_Semaphore_Simple.cpp. References ACE_TRACE, control, and IPC_RMID. Referenced by ACE_SV_Semaphore_Complex::close.
00208 {
00209 ACE_TRACE ("ACE_SV_Semaphore_Simple::remove");
00210 int result = this->control (IPC_RMID);
00211 ((ACE_SV_Semaphore_Simple *) this)->init ();
00212 return result;
00213 }
|
|
||||||||||||
|
Non-blocking version of <acquire>.
Reimplemented in ACE_SV_Semaphore_Complex. Definition at line 66 of file SV_Semaphore_Simple.i. References ACE_TRACE, IPC_NOWAIT, and op. Referenced by ACE_SV_Semaphore_Complex::tryacquire, tryacquire_read, and tryacquire_write.
00067 {
00068 ACE_TRACE ("ACE_SV_Semaphore_Simple::tryacquire");
00069 return this->op (-1, n, flags | IPC_NOWAIT);
00070 }
|
|
||||||||||||
|
Try to acquire the semaphore for reading.
Reimplemented in ACE_SV_Semaphore_Complex. Definition at line 75 of file SV_Semaphore_Simple.i. References ACE_TRACE, and tryacquire.
00076 {
00077 ACE_TRACE ("ACE_SV_Semaphore_Simple::tryacquire_read");
00078 return this->tryacquire (n, flags);
00079 }
|
|
||||||||||||
|
Try to acquire the semaphore for writing.
Reimplemented in ACE_SV_Semaphore_Complex. Definition at line 84 of file SV_Semaphore_Simple.i. References ACE_TRACE, and tryacquire.
00085 {
00086 ACE_TRACE ("ACE_SV_Semaphore_Simple::tryacquire_write");
00087 return this->tryacquire (n, flags);
00088 }
|
|
|
Declare the dynamic allocation hooks.
Reimplemented in ACE_SV_Semaphore_Complex. Definition at line 130 of file SV_Semaphore_Simple.h. |
|
|
Internal ID to identify the semaphore group within this process.
Definition at line 137 of file SV_Semaphore_Simple.h. Referenced by ACE_SV_Semaphore_Complex::close, control, get_id, init, op, open, ACE_SV_Semaphore_Complex::open, and ACE_SV_Semaphore_Complex::~ACE_SV_Semaphore_Complex. |
|
|
Semaphore key.
Definition at line 134 of file SV_Semaphore_Simple.h. Referenced by ACE_SV_Semaphore_Complex::close, init, open, and ACE_SV_Semaphore_Complex::open. |
|
|
Number of semaphores we're creating.
Definition at line 140 of file SV_Semaphore_Simple.h. Referenced by open, and ACE_SV_Semaphore_Complex::open. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002