This is a more complex semaphore wrapper that handles race conditions for initialization correctly...
More...
|
| ACE_SV_Semaphore_Complex (void) |
|
| ACE_SV_Semaphore_Complex (key_t key, short create=ACE_SV_Semaphore_Complex::ACE_CREATE, int initial_value=1, u_short nsems=1, mode_t perms=ACE_DEFAULT_FILE_PERMS) |
|
| ACE_SV_Semaphore_Complex (const char *name, short create=ACE_SV_Semaphore_Complex::ACE_CREATE, int initial_value=1, u_short nsems=1, mode_t perms=ACE_DEFAULT_FILE_PERMS) |
|
| ~ACE_SV_Semaphore_Complex (void) |
|
int | open (const char *name, short flags=ACE_SV_Semaphore_Simple::ACE_CREATE, int initial_value=1, u_short nsems=1, mode_t perms=ACE_DEFAULT_FILE_PERMS) |
|
int | open (key_t key, short flags=ACE_SV_Semaphore_Simple::ACE_CREATE, int initial_value=1, u_short nsems=1, mode_t perms=ACE_DEFAULT_FILE_PERMS) |
|
int | close (void) |
|
int | acquire (u_short n=0, short flags=0) const |
| Acquire the semaphore. More...
|
|
int | acquire_read (u_short n=0, short flags=0) const |
| Acquire a semaphore for reading. More...
|
|
int | acquire_write (u_short n=0, short flags=0) const |
| Acquire a semaphore for writing. More...
|
|
int | tryacquire (u_short n=0, short flags=0) const |
| Try to acquire the semaphore. More...
|
|
int | tryacquire_read (u_short n=0, short flags=0) const |
| Try to acquire the semaphore for reading. More...
|
|
int | tryacquire_write (u_short n=0, short flags=0) const |
| Try to acquire the semaphore for writing. More...
|
|
int | release (u_short n=0, short flags=0) const |
| Release the semaphore. More...
|
|
int | op (short val, u_short n=0, short flags=0) const |
|
int | op (sembuf op_vec[], u_short n) const |
|
int | control (int cmd, semun arg, u_short n=0) const |
|
int | control (int cmd, int value=0, u_short n=0) const |
|
void | dump (void) const |
| Dump the state of an object. More...
|
|
|
enum | { ACE_CREATE = IPC_CREAT,
ACE_EXCL = IPC_EXCL,
ACE_OPEN = 0
} |
|
| ACE_SV_Semaphore_Simple (void) |
|
| ACE_SV_Semaphore_Simple (key_t key, short flags=ACE_SV_Semaphore_Simple::ACE_CREATE, int initial_value=1, u_short nsems=1, mode_t perms=ACE_DEFAULT_FILE_PERMS) |
|
| ACE_SV_Semaphore_Simple (const char *name, short flags=ACE_SV_Semaphore_Simple::ACE_CREATE, int initial_value=1, u_short nsems=1, mode_t perms=ACE_DEFAULT_FILE_PERMS) |
|
| ACE_SV_Semaphore_Simple (const wchar_t *name, short flags=ACE_SV_Semaphore_Simple::ACE_CREATE, int initial_value=1, u_short nsems=1, mode_t perms=ACE_DEFAULT_FILE_PERMS) |
|
| ~ACE_SV_Semaphore_Simple (void) |
|
int | open (const char *name, short flags=ACE_SV_Semaphore_Simple::ACE_CREATE, int initial_value=1, u_short nsems=1, mode_t perms=ACE_DEFAULT_FILE_PERMS) |
|
int | open (const wchar_t *name, short flags=ACE_SV_Semaphore_Simple::ACE_CREATE, int initial_value=1, u_short nsems=1, mode_t perms=ACE_DEFAULT_FILE_PERMS) |
|
int | open (key_t key, short flags=ACE_SV_Semaphore_Simple::ACE_CREATE, int initial_value=1, u_short nsems=1, mode_t perms=ACE_DEFAULT_FILE_PERMS) |
|
int | close (void) |
|
int | remove (void) const |
|
int | acquire (u_short n=0, short flags=0) const |
|
int | acquire_read (u_short n=0, short flags=0) const |
| Acquire a semaphore for reading. More...
|
|
int | acquire_write (u_short n=0, short flags=0) const |
| Acquire a semaphore for writing. More...
|
|
int | tryacquire (u_short n=0, short flags=0) const |
| Non-blocking version of <acquire>. More...
|
|
int | tryacquire_read (u_short n=0, short flags=0) const |
| Try to acquire the semaphore for reading. More...
|
|
int | tryacquire_write (u_short n=0, short flags=0) const |
| Try to acquire the semaphore for writing. More...
|
|
int | release (u_short n=0, short flags=0) const |
|
int | op (short val, u_short semnum=0, short flags=SEM_UNDO) const |
|
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...
|
|
key_t | name_2_key (const char *name) |
|
| ACE_ALLOC_HOOK_DECLARE |
| Declare the dynamic allocation hooks. More...
|
|
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...
|
|
This is a more complex semaphore wrapper that handles race conditions for initialization correctly...
This code is a port to C++, inspired by: W. Richard Stevens from his book: UNIX Network Programming (Prentice Hall, ISBN 0-13-949876-1 - 1990). We provide a simpler and easier to understand interface to the System V Semaphore system calls. We create and use a 2 + n-member set for the requested ACE_SV_Semaphore_Complex. The first member, [0], is a counter used to know when all processes have finished with the ACE_SV_Semaphore_Complex. The counter is initialized to a large number, decremented on every create or open and incremented on every close. This way we can use the "adjust" feature provided by System V so that any process that exit's without calling <close> is accounted for. It doesn't help us if the last process does this (as we have no way of getting control to remove the ACE_SV_Semaphore_Complex) but it will work if any process other than the last does an exit (intentional or unintentional). The second member, [1], of the semaphore is used as a lock variable to avoid any race conditions in the create() and close() functions. The members beyond [1] are actual semaphore values in the array of semaphores, which may be sized by the user in the constructor.