Skip to content

Commit

Permalink
tloadscreen: Use atomic access for current stage
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Apr 1, 2016
1 parent 8580245 commit 7c767e6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/gui/dialogs/loadscreen.cpp
Expand Up @@ -118,7 +118,7 @@ void tloadscreen::progress(const char* stage)
WRN_LS << "Stage ID '" << stage << "' missing description." << std::endl;
return;
}
current_load->current_stage_ = iter;
current_load->current_stage_.store(iter, std::memory_order_release);
}
}

Expand All @@ -129,10 +129,11 @@ void tloadscreen::timer_callback(twindow& window)
if (!worker_ || worker_->timed_join(boost::posix_time::milliseconds(0))) {
window.close();
}
if (current_stage_ != current_visible_stage_)
auto stage = current_stage_.load(std::memory_order_acquire);
if (stage != current_visible_stage_)
{
current_visible_stage_ = current_stage_;
progress_stage_label_->set_label(t_string(current_stage_->second, "wesnoth-lib") + "...");
current_visible_stage_ = stage;
progress_stage_label_->set_label(t_string(stage->second, "wesnoth-lib") + "...");
}
++animation_counter_;
if (animation_counter_ % 2 == 0) {
Expand Down
3 changes: 2 additions & 1 deletion src/gui/dialogs/loadscreen.hpp
Expand Up @@ -19,6 +19,7 @@
#include <boost/function.hpp>
#include <boost/scoped_ptr.hpp>
#include <map>
#include <atomic>

class CVideo;
namespace boost
Expand Down Expand Up @@ -78,7 +79,7 @@ class tloadscreen : public tdialog
tlabel* animation_label_;
static tloadscreen* current_load;

std::map<std::string,std::string>::const_iterator current_stage_;
volatile std::atomic<std::map<std::string,std::string>::const_iterator> current_stage_;
std::map<std::string,std::string>::const_iterator current_visible_stage_;
};

Expand Down

0 comments on commit 7c767e6

Please sign in to comment.