Provide Thread objects with access to loop

This commit is contained in:
John Firebaugh
2015-04-21 10:44:38 -07:00
parent 41a44280ca
commit 32c818feea
5 changed files with 11 additions and 7 deletions

View File

@@ -67,7 +67,7 @@ SQLiteCache::SQLiteCache(const std::string& path_)
SQLiteCache::~SQLiteCache() = default;
SQLiteCache::Impl::Impl(const std::string& path_)
SQLiteCache::Impl::Impl(uv_loop_t*, const std::string& path_)
: path(path_) {
}

View File

@@ -3,6 +3,8 @@
#include <mbgl/storage/sqlite_cache.hpp>
typedef struct uv_loop_s uv_loop_t;
namespace mapbox {
namespace sqlite {
class Database;
@@ -14,7 +16,7 @@ namespace mbgl {
class SQLiteCache::Impl {
public:
Impl(const std::string &path = ":memory:");
Impl(uv_loop_t*, const std::string &path = ":memory:");
~Impl();
std::unique_ptr<Response> get(const Resource&);

View File

@@ -61,7 +61,7 @@ void DefaultFileSource::cancel(Request *req) {
// ----- Impl -----
DefaultFileSource::Impl::Impl(FileCache* cache_, const std::string& root)
DefaultFileSource::Impl::Impl(uv_loop_t*, FileCache* cache_, const std::string& root)
: cache(cache_), assetRoot(root.empty() ? platform::assetRoot() : root) {
}

View File

@@ -6,6 +6,8 @@
#include <set>
#include <unordered_map>
typedef struct uv_loop_s uv_loop_t;
namespace mbgl {
class RequestBase;
@@ -22,7 +24,7 @@ struct DefaultFileRequest {
class DefaultFileSource::Impl {
public:
Impl(FileCache*, const std::string& = "");
Impl(uv_loop_t*, FileCache*, const std::string& = "");
void add(Request*, uv_loop_t*);
void cancel(Request*);

View File

@@ -96,12 +96,12 @@ Thread<Object>::Thread(const std::string& name, Args&&... args) {
template <class Object>
template <typename P, std::size_t... I>
void Thread<Object>::run(P&& params, index_sequence<I...>) {
Object object_(std::get<I>(std::forward<P>(params))...);
object = &object_;
RunLoop loop_;
loop = &loop_;
Object object_(loop_.get(), std::get<I>(std::forward<P>(params))...);
object = &object_;
running.set_value();
loop_.run();