aboutsummaryrefslogtreecommitdiff
path: root/src/zencore/thread.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/zencore/thread.cpp')
-rw-r--r--src/zencore/thread.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/zencore/thread.cpp b/src/zencore/thread.cpp
index 54459cbaa..067e66c0d 100644
--- a/src/zencore/thread.cpp
+++ b/src/zencore/thread.cpp
@@ -146,6 +146,12 @@ RwLock::AcquireShared() noexcept
m_Mutex.lock_shared();
}
+bool
+RwLock::TryAcquireShared() noexcept
+{
+ return m_Mutex.try_lock_shared();
+}
+
void
RwLock::ReleaseShared() noexcept
{
@@ -158,6 +164,12 @@ RwLock::AcquireExclusive() noexcept
m_Mutex.lock();
}
+bool
+RwLock::TryAcquireExclusive() noexcept
+{
+ return m_Mutex.try_lock();
+}
+
void
RwLock::ReleaseExclusive() noexcept
{
@@ -491,6 +503,18 @@ NamedMutex::~NamedMutex()
if (m_MutexHandle)
{
int Inner = int(intptr_t(m_MutexHandle));
+
+ // Remove the backing file before releasing the lock so that new callers
+ // of Create()/Exists() won't find a stale entry. Other processes that
+ // already have the file open still hold valid fds (unlink only removes
+ // the directory entry; the inode lives until the last fd is closed).
+ std::error_code Ec;
+ std::filesystem::path Name = PathFromHandle((void*)(intptr_t(Inner)), Ec);
+ if (!Ec)
+ {
+ unlink(Name.c_str());
+ }
+
flock(Inner, LOCK_UN);
close(Inner);
}