mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-15 11:30:59 +01:00
only remove named mutex semaphore if owned (see #271)
This commit is contained in:
parent
d33db357ca
commit
d578109d4d
@ -46,6 +46,7 @@ private:
|
||||
sem_t* _sem;
|
||||
#else
|
||||
int _semid; // semaphore id
|
||||
bool _owned;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -72,12 +72,17 @@ NamedMutexImpl::NamedMutexImpl(const std::string& name):
|
||||
union semun arg;
|
||||
arg.val = 1;
|
||||
semctl(_semid, 0, SETVAL, arg);
|
||||
_owned = true;
|
||||
return;
|
||||
}
|
||||
else if (errno == EEXIST)
|
||||
{
|
||||
_semid = semget(key, 1, 0);
|
||||
_owned = false;
|
||||
if (_semid >= 0) return;
|
||||
}
|
||||
else throw SystemException(Poco::format("cannot create named mutex %s (semget() failed, errno=%d)", fileName, errno), _name);
|
||||
|
||||
throw SystemException(Poco::format("cannot create named mutex %s (semget() failed, errno=%d)", fileName, errno), _name);
|
||||
#endif // defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(__QNX__) || defined(_AIX) || defined(__EMSCRIPTEN__)
|
||||
}
|
||||
|
||||
@ -87,7 +92,7 @@ NamedMutexImpl::~NamedMutexImpl()
|
||||
#if defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(__QNX__) || defined(_AIX) || defined(__EMSCRIPTEN__)
|
||||
sem_close(_sem);
|
||||
#else
|
||||
semctl(_semid, 0, IPC_RMID, 0);
|
||||
if (_owned) semctl(_semid, 0, IPC_RMID, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user