Allows waiting for the creation of a semaphore (if it does not exist yet) for a maximum of 5 seconds
This commit is contained in:
parent
6a61b3be08
commit
79fdf3f2c9
1 changed files with 16 additions and 6 deletions
|
@ -96,15 +96,25 @@ namespace IPC {
|
||||||
///\param value The initial value of the semaphore if O_CREAT is given in oflag, ignored otherwise
|
///\param value The initial value of the semaphore if O_CREAT is given in oflag, ignored otherwise
|
||||||
void semaphore::open(const char * name, int oflag, mode_t mode, unsigned int value) {
|
void semaphore::open(const char * name, int oflag, mode_t mode, unsigned int value) {
|
||||||
close();
|
close();
|
||||||
|
int timer = 0;
|
||||||
|
while (!(*this) && timer++ < 10){
|
||||||
#ifdef __CYGWIN__
|
#ifdef __CYGWIN__
|
||||||
mySem = CreateSemaphore(0, value, 1 , std::string("Global\\" + std::string(name)).c_str());
|
mySem = CreateSemaphore(0, value, 1 , std::string("Global\\" + std::string(name)).c_str());
|
||||||
#else
|
#else
|
||||||
if (oflag & O_CREAT) {
|
if (oflag & O_CREAT) {
|
||||||
mySem = sem_open(name, oflag, mode, value);
|
mySem = sem_open(name, oflag, mode, value);
|
||||||
} else {
|
} else {
|
||||||
mySem = sem_open(name, oflag);
|
mySem = sem_open(name, oflag);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
if (!(*this)){
|
||||||
|
if (errno == ENOENT){
|
||||||
|
Util::wait(500);
|
||||||
|
}else{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!(*this)){
|
if (!(*this)){
|
||||||
DEBUG_MSG(DLVL_VERYHIGH, "Attempt to open semaphore %s: %s", name, strerror(errno));
|
DEBUG_MSG(DLVL_VERYHIGH, "Attempt to open semaphore %s: %s", name, strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue