Skip to content

Commit

Permalink
Wrap ConfigFiler::watcher modifications in mutex locks
Browse files Browse the repository at this point in the history
Should fix tests crashing due to the test running on one thread and the
server on another

Co-authored-by: Alan Griffiths <alan@octopull.co.uk>
  • Loading branch information
tarek-y-ismail and AlanGriffiths committed Jan 30, 2025
1 parent e957c65 commit f6f04ce
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/miral/config_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ class miral::ConfigFile::Self
{
public:
Self(MirRunner& runner, path file, Mode mode, Loader load_config);

~Self() { std::lock_guard lock{mutex}; watcher.reset(); }
private:
std::mutex mutex;
std::shared_ptr<Watcher> watcher;
};

Expand Down Expand Up @@ -155,8 +156,11 @@ miral::ConfigFile::Self::Self(MirRunner& runner, path file, Mode mode, Loader lo
break;

case Mode::reload_on_change:
watcher = std::make_shared<Watcher>(file, std::move(load_config));
watcher->register_handler(runner);
{
std::lock_guard lock{mutex};
watcher = std::make_shared<Watcher>(file, std::move(load_config));
watcher->register_handler(runner);
}
break;
}
});
Expand Down

0 comments on commit f6f04ce

Please sign in to comment.