Skip to content

Commit

Permalink
Continue 6385.5
Browse files Browse the repository at this point in the history
  • Loading branch information
alabuzhev committed Oct 29, 2024
1 parent 108c596 commit fe4898b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
5 changes: 5 additions & 0 deletions far/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
--------------------------------------------------------------------------------
drkns 2024-10-29 02:35:48+00:00 - build 6386

1. Continue 6385.5.

--------------------------------------------------------------------------------
drkns 2024-10-26 20:17:00+01:00 - build 6385

Expand Down
39 changes: 28 additions & 11 deletions far/filesystemwatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class background_watcher: public singleton<background_watcher>

m_Clients.emplace_back(Client);

m_Synchronised = false;
m_Synchronised.reset();

if (!m_Thread.joinable() || m_Thread.is_signaled())
m_Thread = os::thread(&background_watcher::process, this);
Expand All @@ -79,13 +79,17 @@ class background_watcher: public singleton<background_watcher>

void remove(const FileSystemWatcher* Client)
{
SCOPED_ACTION(std::scoped_lock)(m_CS);
{
SCOPED_ACTION(std::scoped_lock)(m_CS);

std::erase(m_Clients, Client);
std::erase(m_Clients, Client);

m_Synchronised = false;
m_Synchronised.reset();
m_Update.set();
}

m_Update.set();
// We have to ensure that the client event handle is no longer used by the watcher before letting the client go
m_Synchronised.wait();
}

private:
Expand All @@ -101,8 +105,10 @@ class background_watcher: public singleton<background_watcher>
{
SCOPED_ACTION(std::scoped_lock)(m_CS);

if (!m_Synchronised)
if (!m_Synchronised.is_signaled())
{
SCOPE_EXIT{ m_Synchronised.set(); };

if (m_Clients.empty())
{
LOGDEBUG(L"FS Watcher exit"sv);
Expand All @@ -121,7 +127,6 @@ class background_watcher: public singleton<background_watcher>
return Handle;
});

m_Synchronised = true;
}
}

Expand All @@ -138,7 +143,7 @@ class background_watcher: public singleton<background_watcher>
{
SCOPED_ACTION(std::scoped_lock)(m_CS);

if (!m_Synchronised)
if (!m_Synchronised.is_signaled())
{
PendingHandle = Handles[Result];
continue;
Expand Down Expand Up @@ -167,8 +172,9 @@ class background_watcher: public singleton<background_watcher>

os::critical_section m_CS;
os::event m_Update{ os::event::type::automatic, os::event::state::nonsignaled };
os::event m_Synchronised{ os::event::type::manual, os::event::state::nonsignaled };
std::vector<const FileSystemWatcher*> m_Clients;
std::atomic_bool m_Exit{}, m_Synchronised{};
std::atomic_bool m_Exit{};
os::thread m_Thread;
};

Expand Down Expand Up @@ -225,9 +231,20 @@ FileSystemWatcher::~FileSystemWatcher()

m_DirectoryHandle = {};

m_Event.wait();
switch (const auto Status = m_Overlapped.Internal)
{
case STATUS_NOTIFY_CLEANUP:
case STATUS_NOTIFY_ENUM_DIR:
break;

case STATUS_PENDING:
(void)get_result();
break;

assert(m_Overlapped.Internal == STATUS_NOTIFY_CLEANUP);
default:
LOGDEBUG(L"Overlapped.Internal: {}"sv, os::error_state{ ERROR_SUCCESS, static_cast<NTSTATUS>(m_Overlapped.Internal) });
break;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion far/vbuild.m4
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6385
6386

0 comments on commit fe4898b

Please sign in to comment.