From 0f083843bc31bf985991728125ef74efca6ef7b7 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sun, 27 Dec 2015 10:07:24 +0100 Subject: Introduce thread synchronization for tracking init and logging This obviously leads to synchronizing syscalls that would otherwise happen in parallel. Luckily the goal of this library is to monitor file changes performed by single, user facing applications and as such it doesn't matter if some operations are slightly slower. --- src/tracking/change_tracker.cc | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/tracking/change_tracker.cc') diff --git a/src/tracking/change_tracker.cc b/src/tracking/change_tracker.cc index 1b554aa..ca07214 100644 --- a/src/tracking/change_tracker.cc +++ b/src/tracking/change_tracker.cc @@ -82,6 +82,8 @@ bool ChangeTracker::track(const std::string& file_path) { boost::filesystem::canonical(file_path).string() }; + std::unique_lock guard(this->write_mutex_); + auto result = this->children_.emplace( full_file_path, std::make_unique( @@ -92,6 +94,8 @@ bool ChangeTracker::track(const std::string& file_path) { ) ); + guard.unlock(); + if ( std::get(result) ) { boost::filesystem::ifstream file( std::get(*result.first) -- cgit v1.2.3