Simplify thread synchronization

This commit is contained in:
Matthias Schiffer 2014-09-24 03:19:55 +02:00
parent b5c7b4a162
commit ba321783e7
2 changed files with 1 additions and 9 deletions

View file

@ -74,12 +74,7 @@ void RPGEdit::systemLoop() {
{ {
std::unique_lock<std::mutex> lock(modelMutex); std::unique_lock<std::mutex> lock(modelMutex);
uint64_t time = timeProvider.now(); uint64_t time = std::min(timeProvider.now(), handledTime);
while (time >= handledTime) {
modelCond.wait(lock);
time = timeProvider.now();
}
Model::Position pos = ctx->getViewPosition(time); Model::Position pos = ctx->getViewPosition(time);
mapView->render(pos.x, pos.y, time); mapView->render(pos.x, pos.y, time);
@ -102,7 +97,6 @@ void RPGEdit::eventLoop() {
event.second(); event.second();
handledTime = eventBus.peek(); handledTime = eventBus.peek();
modelCond.notify_one();
} }
} }
} }

View file

@ -30,7 +30,6 @@
#include "InputHandler.hpp" #include "InputHandler.hpp"
#include "MapContext.hpp" #include "MapContext.hpp"
#include <condition_variable>
#include <memory> #include <memory>
#include <mutex> #include <mutex>
#include <thread> #include <thread>
@ -54,7 +53,6 @@ private:
std::thread eventThread; std::thread eventThread;
std::mutex modelMutex; std::mutex modelMutex;
std::condition_variable modelCond;
uint64_t handledTime = std::numeric_limits<uint64_t>::max(); uint64_t handledTime = std::numeric_limits<uint64_t>::max();
void enqueueNow(const EventBus::Event &event) { void enqueueNow(const EventBus::Event &event) {