From bba3d9838a512c75a63f5eb9263913ec96011e8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Fri, 10 Apr 2015 15:36:32 +0200 Subject: add Thread and RunLoop Thread is a generic thread management object that starts a thread, creates an object T in that thread and calls its .start() function. When the Thread object is destructed (which must happen in the thread that created it), it'll call the object's .stop() function, and wait for thread termination. The .stop() function must somehow get the thread to terminate. Note that object T's constructor/destructor/start()/stop() must be protected/private, and Thread must be declared as a friend class. All public functions may be called from any thread and are exposed through operator->(). RunLoop encapsulates a libuv runloop and has a facility of dispatching function objects to the thread. It can be used either as a worker thread class by itself, or it can be derived from. This commit converts SQLiteCache to derive from RunLoop and removes the custom code used previously for managing the cache thread. --- linux/main.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'linux') diff --git a/linux/main.cpp b/linux/main.cpp index 4d5474c02f..71c2424af5 100644 --- a/linux/main.cpp +++ b/linux/main.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -65,8 +66,8 @@ int main(int argc, char *argv[]) { view = mbgl::util::make_unique(); - mbgl::SQLiteCache cache("/tmp/mbgl-cache.db"); - mbgl::DefaultFileSource fileSource(&cache); + mbgl::util::Thread cache("/tmp/mbgl-cache.db"); + mbgl::DefaultFileSource fileSource(cache); mbgl::Map map(*view, fileSource); // Load settings -- cgit v1.2.1