Skip to content

Commit

Permalink
Apply mutex lock guard around notification write after obtaining from…
Browse files Browse the repository at this point in the history
… server.
  • Loading branch information
ebarlas committed Sep 4, 2024
1 parent d2af95b commit 97c8c41
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/net/StagingArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ void trippin::StagingArea::setTopScores(std::vector<Score> scores) {
topSet = true;
}

void trippin::StagingArea::setNotification(std::string n) {
std::lock_guard<std::mutex> lock(mutex);
notification = std::move(n);
}

std::vector<trippin::Score> trippin::StagingArea::getTodayScores(int limit) const {
std::lock_guard<std::mutex> lock(mutex);
return combine(todayScores, addedScores, limit);
Expand Down Expand Up @@ -70,7 +75,7 @@ void trippin::StagingArea::run() {
while (true) {
auto n = transport.getNotification();
if (!n.empty()) {
notification = n;
setNotification(n);
SDL_Log("set notification in staging area");
}
auto top = transport.topScores();
Expand Down
1 change: 1 addition & 0 deletions src/net/StagingArea.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace trippin {
void run();
void setTodayScores(std::vector<Score> scores);
void setTopScores(std::vector<Score> scores);
void setNotification(std::string notification);
};
}

Expand Down

0 comments on commit 97c8c41

Please sign in to comment.