38 int id = ::semget( IPC_PRIVATE , 1 , IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR ) ;
40 throw std::runtime_error(
"semget failed" ) ;
42 m_storage.filler[0] =
static_cast<unsigned int>(id) ;
44 union {
int val ;
void * p ; } u ; u.val =
static_cast<int>(initial_value) ;
45 int rc = ::semctl(
id , 0 , SETVAL , u ) ;
49 throw std::runtime_error( std::string(
"semctl setval failed: ") + G::Process::strerror(e) ) ;
55 int id =
static_cast<int>( m_storage.filler[0] ) ;
56 m_storage.filler[0] = -1 ;
57 ::semctl(
id , 0 , IPC_RMID ) ;
63 int id =
static_cast<int>( m_storage.filler[0] ) ;
64 struct ::sembuf op_zero ;
65 struct ::sembuf op = op_zero ;
69 ::semop(
id , &op , 1 ) ;
75 int id =
static_cast<int>( m_storage.filler[0] ) ;
76 struct ::sembuf op_zero ;
77 struct ::sembuf op = op_zero ;
81 struct timespec ts = { timeout , 0 } ;
82 int rc = ::semtimedop(
id , &op , 1 , &ts ) ;
83 if( rc < 0 && errno != EAGAIN )
84 throw std::runtime_error(
"semtimedop decrement failed" ) ;
91 int id =
static_cast<int>( m_storage.filler[0] ) ;
92 struct ::sembuf op_zero ;
93 struct ::sembuf op = op_zero ;
97 int rc = ::semop(
id , &op , 1 ) ;
99 throw std::runtime_error(
"semop decrement failed" ) ;
void decrement()
Decrement-but-block-if-zero operator.
static Semaphore * at(storage_type *)
Syntactic sugar to return an object pointer corresponding to the given storage pointer.
void increment()
Increment operator. Used for mutex unlocking.
A semaphore class with a posix or sysv implementation chosen at build-time.
~Semaphore()
Destroys the semaphore.
Semaphore(unsigned int initial_value=1U)
Constructor for a new anonymous semaphore, typically located inside a shared memory segment using "pl...