mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-16 03:42:53 +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;
|
sem_t* _sem;
|
||||||
#else
|
#else
|
||||||
int _semid; // semaphore id
|
int _semid; // semaphore id
|
||||||
|
bool _owned;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -72,12 +72,17 @@ NamedMutexImpl::NamedMutexImpl(const std::string& name):
|
|||||||
union semun arg;
|
union semun arg;
|
||||||
arg.val = 1;
|
arg.val = 1;
|
||||||
semctl(_semid, 0, SETVAL, arg);
|
semctl(_semid, 0, SETVAL, arg);
|
||||||
|
_owned = true;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else if (errno == EEXIST)
|
else if (errno == EEXIST)
|
||||||
{
|
{
|
||||||
_semid = semget(key, 1, 0);
|
_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__)
|
#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__)
|
#if defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(__QNX__) || defined(_AIX) || defined(__EMSCRIPTEN__)
|
||||||
sem_close(_sem);
|
sem_close(_sem);
|
||||||
#else
|
#else
|
||||||
semctl(_semid, 0, IPC_RMID, 0);
|
if (_owned) semctl(_semid, 0, IPC_RMID, 0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user