mirror of https://github.com/OpenMW/openmw.git
Merge branch 'sleep_free_preload' into 'master'
Make sync terrain preloading sleep free See merge request OpenMW/openmw!1203pull/3096/head
commit
44d1a77a87
@ -0,0 +1,41 @@
|
||||
#include "reporter.hpp"
|
||||
#include "loadinglistener.hpp"
|
||||
|
||||
#include <condition_variable>
|
||||
#include <cstddef>
|
||||
#include <mutex>
|
||||
|
||||
namespace Loading
|
||||
{
|
||||
void Reporter::addTotal(std::size_t value)
|
||||
{
|
||||
const std::lock_guard lock(mMutex);
|
||||
mTotal += value;
|
||||
mUpdated.notify_all();
|
||||
}
|
||||
|
||||
void Reporter::addProgress(std::size_t value)
|
||||
{
|
||||
const std::lock_guard lock(mMutex);
|
||||
mProgress += value;
|
||||
mUpdated.notify_all();
|
||||
}
|
||||
|
||||
void Reporter::complete()
|
||||
{
|
||||
const std::lock_guard lock(mMutex);
|
||||
mDone = true;
|
||||
mUpdated.notify_all();
|
||||
}
|
||||
|
||||
void Reporter::wait(Listener& listener) const
|
||||
{
|
||||
std::unique_lock lock(mMutex);
|
||||
while (!mDone)
|
||||
{
|
||||
listener.setProgressRange(mTotal);
|
||||
listener.setProgress(mProgress);
|
||||
mUpdated.wait(lock);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
#ifndef COMPONENTS_LOADINGLISTENER_REPORTER_H
|
||||
#define COMPONENTS_LOADINGLISTENER_REPORTER_H
|
||||
|
||||
#include <condition_variable>
|
||||
#include <cstddef>
|
||||
#include <mutex>
|
||||
|
||||
namespace Loading
|
||||
{
|
||||
class Listener;
|
||||
|
||||
class Reporter
|
||||
{
|
||||
public:
|
||||
void addTotal(std::size_t value);
|
||||
|
||||
void addProgress(std::size_t value);
|
||||
|
||||
void complete();
|
||||
|
||||
void wait(Listener& listener) const;
|
||||
|
||||
private:
|
||||
std::size_t mProgress = 0;
|
||||
std::size_t mTotal = 0;
|
||||
bool mDone = false;
|
||||
mutable std::mutex mMutex;
|
||||
mutable std::condition_variable mUpdated;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue