|
STTNet
|
Synchronization tool class encapsulating System V semaphores. More...
#include <sttnet_English.h>
Public Member Functions | |
| csemp () | |
| Constructor, initializes internal state. More... | |
| bool | init (key_t key, unsigned short value=1, short sem_flg=SEM_UNDO) |
| Initialize the semaphore. More... | |
| bool | wait (short value=-1) |
| P operation (wait), attempts to subtract value from the semaphore. More... | |
| bool | post (short value=1) |
| V operation (release), attempts to add value to the semaphore. More... | |
| int | getvalue () |
| Get the current value of the semaphore. More... | |
| bool | destroy () |
| Destroy the current semaphore. More... | |
| ~csemp () | |
| Destructor, does not automatically destroy the semaphore. More... | |
Synchronization tool class encapsulating System V semaphores.
csemp provides a mutual exclusion mechanism, supporting inter-process synchronization operations. By encapsulating system calls such as semget, semop, semctl, it implements semaphore initialization, P (wait), V (release), destruction, and current value reading.
Copy construction and assignment operators are disabled to ensure resource uniqueness.
|
inline |
Constructor, initializes internal state.
| stt::system::csemp::~csemp | ( | ) |
Destructor, does not automatically destroy the semaphore.
| bool stt::system::csemp::destroy | ( | ) |
Destroy the current semaphore.
Generally used to clean up resources before the main process holding the semaphore exits.
| int stt::system::csemp::getvalue | ( | ) |
Get the current value of the semaphore.
| bool stt::system::csemp::init | ( | key_t | key, |
| unsigned short | value = 1, |
||
| short | sem_flg = SEM_UNDO |
||
| ) |
Initialize the semaphore.
If the semaphore already exists, it is obtained; otherwise, an attempt is made to create and set the initial value.
| key | Unique key of the semaphore. |
| value | Initial value of the semaphore (default 1, representing a mutex). |
| sem_flg | Semaphore operation flags, default SEM_UNDO, operations are automatically revoked when the process terminates. |
| bool stt::system::csemp::post | ( | short | value = 1 | ) |
V operation (release), attempts to add value to the semaphore.
Releases resources or wakes up waiting processes.
| value | Release value (must be greater than 0, default 1). |
| bool stt::system::csemp::wait | ( | short | value = -1 | ) |
P operation (wait), attempts to subtract value from the semaphore.
If the current value is insufficient, it will block until available.
| value | Wait value (must be less than 0, default -1). |
1.8.5