diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2015-04-10 15:36:32 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2015-04-10 15:36:32 +0200 |
commit | bba3d9838a512c75a63f5eb9263913ec96011e8d (patch) | |
tree | afe1462c6e134fffae55fceaae45a8920e63644b /linux/main.cpp | |
parent | 8eafe36932c3c5407a305268bc5b62e70ad8b8b0 (diff) | |
download | qtlocation-mapboxgl-bba3d9838a512c75a63f5eb9263913ec96011e8d.tar.gz |
add Thread<T> and RunLoop
Thread<T> 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<T> 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<T> 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.
Diffstat (limited to 'linux/main.cpp')
-rw-r--r-- | linux/main.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
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 <mbgl/platform/default/glfw_view.hpp> #include <mbgl/storage/default_file_source.hpp> #include <mbgl/storage/default/sqlite_cache.hpp> +#include <mbgl/util/thread.hpp> #include <signal.h> #include <getopt.h> @@ -65,8 +66,8 @@ int main(int argc, char *argv[]) { view = mbgl::util::make_unique<GLFWView>(); - mbgl::SQLiteCache cache("/tmp/mbgl-cache.db"); - mbgl::DefaultFileSource fileSource(&cache); + mbgl::util::Thread<mbgl::SQLiteCache> cache("/tmp/mbgl-cache.db"); + mbgl::DefaultFileSource fileSource(cache); mbgl::Map map(*view, fileSource); // Load settings |