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.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/zencore/thread.cpp b/src/zencore/thread.cpp
index f74791333..067e66c0d 100644
--- a/src/zencore/thread.cpp
+++ b/src/zencore/thread.cpp
@@ -503,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);
}