diff options
-rw-r--r-- | main.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
@@ -106,6 +106,7 @@ struct MatchResult { }; struct Player { + mutex lock; string fname, safename; vector<MatchResult> results; int64_t lastModified; @@ -113,6 +114,14 @@ struct Player { Player(const string &fname) : fname(fname), safename(makeSafe(fname)), lastModified(fileLastModified(fname)) {} + + // Do not call this in a threaded setting (wouldn't make sense anyway) + Player(Player &&other) + : fname{move(other.fname)} + , safename{move(other.safename)} + , results{move(other.results)} + , lastModified{other.lastModified} + {} }; int MatchResult::score() const { @@ -225,8 +234,14 @@ static void writeMatchCache(const Player &p1, const Player &p2, int index, const } static void recordResult(Player &p1, Player &p2, const MatchResult &result) { - p1.results.push_back(result); - p2.results.push_back(result.inverted()); + { + lock_guard guard{p1.lock}; + p1.results.push_back(result); + } + { + lock_guard guard{p2.lock}; + p2.results.push_back(result.inverted()); + } } static void playMatch(MultiLog &multiLog, Player &p1, Player &p2, int index, const Params ¶ms) { |