summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <tmpsantos@gmail.com>2017-06-21 13:38:49 +0300
committerThiago Marcos P. Santos <tmpsantos@gmail.com>2017-06-21 14:30:09 +0300
commit7e8bdadb91010b83cea7e8bad7a4e7a2488a91f6 (patch)
treee2ed9939f3a1e60fde59536a51336e70749311f7
parent1427628c56d336a21c93ef0a1c57fbfabd98dc5e (diff)
downloadqtlocation-mapboxgl-7e8bdadb91010b83cea7e8bad7a4e7a2488a91f6.tar.gz
[core] Rename ThreadedObject to Thread
Now that the old Thread class is gone, we can give ThreadedObject a better name.
-rw-r--r--cmake/core-files.cmake2
-rw-r--r--cmake/test-files.cmake2
-rw-r--r--include/mbgl/storage/default_file_source.hpp4
-rw-r--r--platform/android/src/asset_manager_file_source.cpp4
-rw-r--r--platform/android/src/asset_manager_file_source.hpp4
-rw-r--r--platform/android/src/run_loop.cpp4
-rw-r--r--platform/android/src/run_loop_impl.hpp4
-rw-r--r--platform/default/asset_file_source.cpp4
-rw-r--r--platform/default/default_file_source.cpp4
-rw-r--r--platform/default/local_file_source.cpp4
-rw-r--r--src/mbgl/storage/asset_file_source.hpp4
-rw-r--r--src/mbgl/storage/local_file_source.hpp4
-rw-r--r--src/mbgl/util/thread.hpp (renamed from src/mbgl/util/threaded_object.hpp)14
-rw-r--r--test/storage/asset_file_source.test.cpp8
-rw-r--r--test/util/thread.test.cpp (renamed from test/util/threaded_object.test.cpp)56
-rw-r--r--test/util/thread_local.test.cpp12
16 files changed, 67 insertions, 67 deletions
diff --git a/cmake/core-files.cmake b/cmake/core-files.cmake
index 220e25d35e..cdbd5c8094 100644
--- a/cmake/core-files.cmake
+++ b/cmake/core-files.cmake
@@ -604,7 +604,7 @@ set(MBGL_CORE_FILES
src/mbgl/util/stopwatch.hpp
src/mbgl/util/string.cpp
src/mbgl/util/thread_local.hpp
- src/mbgl/util/threaded_object.hpp
+ src/mbgl/util/thread.hpp
src/mbgl/util/throttler.cpp
src/mbgl/util/throttler.hpp
src/mbgl/util/tile_coordinate.hpp
diff --git a/cmake/test-files.cmake b/cmake/test-files.cmake
index f85ca03333..edbf100fe2 100644
--- a/cmake/test-files.cmake
+++ b/cmake/test-files.cmake
@@ -131,7 +131,7 @@ set(MBGL_TEST_FILES
test/util/projection.test.cpp
test/util/run_loop.test.cpp
test/util/text_conversions.test.cpp
- test/util/threaded_object.test.cpp
+ test/util/thread.test.cpp
test/util/thread_local.test.cpp
test/util/tile_cover.test.cpp
test/util/timer.test.cpp
diff --git a/include/mbgl/storage/default_file_source.hpp b/include/mbgl/storage/default_file_source.hpp
index df4ab4ab34..556a8df586 100644
--- a/include/mbgl/storage/default_file_source.hpp
+++ b/include/mbgl/storage/default_file_source.hpp
@@ -10,7 +10,7 @@
namespace mbgl {
namespace util {
-template <typename T> class ThreadedObject;
+template <typename T> class Thread;
} // namespace util
class DefaultFileSource : public FileSource {
@@ -143,7 +143,7 @@ public:
private:
// Shared so destruction is done on this thread
const std::shared_ptr<FileSource> assetFileSource;
- const std::unique_ptr<util::ThreadedObject<Impl>> impl;
+ const std::unique_ptr<util::Thread<Impl>> impl;
std::mutex cachedBaseURLMutex;
std::string cachedBaseURL = mbgl::util::API_BASE_URL;
diff --git a/platform/android/src/asset_manager_file_source.cpp b/platform/android/src/asset_manager_file_source.cpp
index 71e03f10b3..aa65e3ff48 100644
--- a/platform/android/src/asset_manager_file_source.cpp
+++ b/platform/android/src/asset_manager_file_source.cpp
@@ -3,7 +3,7 @@
#include <mbgl/storage/file_source_request.hpp>
#include <mbgl/storage/response.hpp>
#include <mbgl/util/util.hpp>
-#include <mbgl/util/threaded_object.hpp>
+#include <mbgl/util/thread.hpp>
#include <mbgl/util/url.hpp>
#include <android/asset_manager.h>
@@ -40,7 +40,7 @@ private:
AssetManagerFileSource::AssetManagerFileSource(jni::JNIEnv& env, jni::Object<android::AssetManager> assetManager_)
: assetManager(assetManager_.NewGlobalRef(env)),
- impl(std::make_unique<util::ThreadedObject<Impl>>("AssetManagerFileSource",
+ impl(std::make_unique<util::Thread<Impl>>("AssetManagerFileSource",
AAssetManager_fromJava(&env, jni::Unwrap(**assetManager)))) {
}
diff --git a/platform/android/src/asset_manager_file_source.hpp b/platform/android/src/asset_manager_file_source.hpp
index 9a86da6c40..dcad95664a 100644
--- a/platform/android/src/asset_manager_file_source.hpp
+++ b/platform/android/src/asset_manager_file_source.hpp
@@ -9,7 +9,7 @@
namespace mbgl {
namespace util {
-template <typename T> class ThreadedObject;
+template <typename T> class Thread;
} // namespace util
class AssetManagerFileSource : public FileSource {
@@ -23,7 +23,7 @@ private:
class Impl;
jni::UniqueObject<android::AssetManager> assetManager;
- std::unique_ptr<util::ThreadedObject<Impl>> impl;
+ std::unique_ptr<util::Thread<Impl>> impl;
};
} // namespace mbgl
diff --git a/platform/android/src/run_loop.cpp b/platform/android/src/run_loop.cpp
index 9a63c9929b..3c605b70e8 100644
--- a/platform/android/src/run_loop.cpp
+++ b/platform/android/src/run_loop.cpp
@@ -2,7 +2,7 @@
#include <mbgl/util/platform.hpp>
#include <mbgl/util/thread_local.hpp>
-#include <mbgl/util/threaded_object.hpp>
+#include <mbgl/util/thread.hpp>
#include <mbgl/util/timer.hpp>
#include <android/looper.h>
@@ -105,7 +105,7 @@ RunLoop::Impl::Impl(RunLoop* runLoop_, RunLoop::Type type) : runLoop(runLoop_) {
case Type::Default:
ret = ALooper_addFd(loop, fds[PIPE_OUT], ALOOPER_POLL_CALLBACK,
ALOOPER_EVENT_INPUT, looperCallbackDefault, this);
- alarm = std::make_unique<ThreadedObject<Alarm>>("Alarm", this);
+ alarm = std::make_unique<Thread<Alarm>>("Alarm", this);
running = true;
break;
}
diff --git a/platform/android/src/run_loop_impl.hpp b/platform/android/src/run_loop_impl.hpp
index 1706051bed..15cbfa14ae 100644
--- a/platform/android/src/run_loop_impl.hpp
+++ b/platform/android/src/run_loop_impl.hpp
@@ -15,7 +15,7 @@ struct ALooper;
namespace mbgl {
namespace util {
-template <typename T> class ThreadedObject;
+template <typename T> class Thread;
class Alarm;
class RunLoop::Impl {
@@ -53,7 +53,7 @@ private:
JNIEnv *env = nullptr;
bool detach = false;
- std::unique_ptr<ThreadedObject<Alarm>> alarm;
+ std::unique_ptr<Thread<Alarm>> alarm;
std::recursive_mutex mtx;
std::list<Runnable*> runnables;
diff --git a/platform/default/asset_file_source.cpp b/platform/default/asset_file_source.cpp
index 5b8a18dd8d..343f3b70ce 100644
--- a/platform/default/asset_file_source.cpp
+++ b/platform/default/asset_file_source.cpp
@@ -2,7 +2,7 @@
#include <mbgl/storage/file_source_request.hpp>
#include <mbgl/storage/response.hpp>
#include <mbgl/util/string.hpp>
-#include <mbgl/util/threaded_object.hpp>
+#include <mbgl/util/thread.hpp>
#include <mbgl/util/url.hpp>
#include <mbgl/util/util.hpp>
#include <mbgl/util/io.hpp>
@@ -57,7 +57,7 @@ private:
};
AssetFileSource::AssetFileSource(const std::string& root)
- : impl(std::make_unique<util::ThreadedObject<Impl>>("AssetFileSource", root)) {
+ : impl(std::make_unique<util::Thread<Impl>>("AssetFileSource", root)) {
}
AssetFileSource::~AssetFileSource() = default;
diff --git a/platform/default/default_file_source.cpp b/platform/default/default_file_source.cpp
index a01c89e3ef..dc3e71b0c0 100644
--- a/platform/default/default_file_source.cpp
+++ b/platform/default/default_file_source.cpp
@@ -8,7 +8,7 @@
#include <mbgl/util/platform.hpp>
#include <mbgl/util/url.hpp>
-#include <mbgl/util/threaded_object.hpp>
+#include <mbgl/util/thread.hpp>
#include <mbgl/util/work_request.hpp>
#include <cassert>
@@ -194,7 +194,7 @@ DefaultFileSource::DefaultFileSource(const std::string& cachePath,
std::unique_ptr<FileSource>&& assetFileSource_,
uint64_t maximumCacheSize)
: assetFileSource(std::move(assetFileSource_))
- , impl(std::make_unique<util::ThreadedObject<Impl>>("DefaultFileSource", assetFileSource, cachePath, maximumCacheSize)) {
+ , impl(std::make_unique<util::Thread<Impl>>("DefaultFileSource", assetFileSource, cachePath, maximumCacheSize)) {
}
DefaultFileSource::~DefaultFileSource() = default;
diff --git a/platform/default/local_file_source.cpp b/platform/default/local_file_source.cpp
index 9d84764433..21a291d8d4 100644
--- a/platform/default/local_file_source.cpp
+++ b/platform/default/local_file_source.cpp
@@ -2,7 +2,7 @@
#include <mbgl/storage/file_source_request.hpp>
#include <mbgl/storage/response.hpp>
#include <mbgl/util/string.hpp>
-#include <mbgl/util/threaded_object.hpp>
+#include <mbgl/util/thread.hpp>
#include <mbgl/util/url.hpp>
#include <mbgl/util/util.hpp>
#include <mbgl/util/io.hpp>
@@ -53,7 +53,7 @@ public:
};
LocalFileSource::LocalFileSource()
- : impl(std::make_unique<util::ThreadedObject<Impl>>("LocalFileSource")) {
+ : impl(std::make_unique<util::Thread<Impl>>("LocalFileSource")) {
}
LocalFileSource::~LocalFileSource() = default;
diff --git a/src/mbgl/storage/asset_file_source.hpp b/src/mbgl/storage/asset_file_source.hpp
index 54b8ba56f7..6ed7af8aaf 100644
--- a/src/mbgl/storage/asset_file_source.hpp
+++ b/src/mbgl/storage/asset_file_source.hpp
@@ -5,7 +5,7 @@
namespace mbgl {
namespace util {
-template <typename T> class ThreadedObject;
+template <typename T> class Thread;
} // namespace util
class AssetFileSource : public FileSource {
@@ -18,7 +18,7 @@ public:
private:
class Impl;
- std::unique_ptr<util::ThreadedObject<Impl>> impl;
+ std::unique_ptr<util::Thread<Impl>> impl;
};
} // namespace mbgl
diff --git a/src/mbgl/storage/local_file_source.hpp b/src/mbgl/storage/local_file_source.hpp
index 1e785379c0..0f065e0b5f 100644
--- a/src/mbgl/storage/local_file_source.hpp
+++ b/src/mbgl/storage/local_file_source.hpp
@@ -5,7 +5,7 @@
namespace mbgl {
namespace util {
-template <typename T> class ThreadedObject;
+template <typename T> class Thread;
} // namespace util
class LocalFileSource : public FileSource {
@@ -20,7 +20,7 @@ public:
private:
class Impl;
- std::unique_ptr<util::ThreadedObject<Impl>> impl;
+ std::unique_ptr<util::Thread<Impl>> impl;
};
} // namespace mbgl
diff --git a/src/mbgl/util/threaded_object.hpp b/src/mbgl/util/thread.hpp
index 7310eed2b1..572f46080e 100644
--- a/src/mbgl/util/threaded_object.hpp
+++ b/src/mbgl/util/thread.hpp
@@ -22,8 +22,8 @@ namespace util {
// Manages a thread with `Object`.
// Upon creation of this object, it launches a thread and creates an object of type `Object`
-// in that thread. When the `ThreadedObject<>` object is destructed, the destructor waits
-// for thread termination. The `ThreadedObject<>` constructor blocks until the thread and
+// in that thread. When the `Thread<>` object is destructed, the destructor waits
+// for thread termination. The `Thread<>` constructor blocks until the thread and
// the `Object` are fully created, so after the object creation, it's safe to obtain the
// `Object` stored in this thread. The thread created will always have low priority on
// the platforms that support setting thread priority.
@@ -32,15 +32,15 @@ namespace util {
//
// - Only one thread is created.
// - `Object` will live in a single thread, providing thread affinity.
-// - It is safe to use `ThreadLocal` in an `Object` managed by `ThreadedObject<>`
+// - It is safe to use `ThreadLocal` in an `Object` managed by `Thread<>`
// - A `RunLoop` is created for the `Object` thread.
// - `Object` can use `Timer` and do asynchronous I/O, like wait for sockets events.
//
template<class Object>
-class ThreadedObject : public Scheduler {
+class Thread : public Scheduler {
public:
template <class... Args>
- ThreadedObject(const std::string& name, Args&&... args) {
+ Thread(const std::string& name, Args&&... args) {
std::promise<void> running;
thread = std::thread([&] {
@@ -60,7 +60,7 @@ public:
running.get_future().get();
}
- ~ThreadedObject() override {
+ ~Thread() override {
MBGL_VERIFY_THREAD(tid);
if (paused) {
@@ -86,7 +86,7 @@ public:
// Returns a non-owning reference to `Object` that
// can be used to send messages to `Object`. It is safe
// to the non-owning reference to outlive this object
- // and be used after the `ThreadedObject<>` gets destroyed.
+ // and be used after the `Thread<>` gets destroyed.
ActorRef<std::decay_t<Object>> actor() const {
return object->self();
}
diff --git a/test/storage/asset_file_source.test.cpp b/test/storage/asset_file_source.test.cpp
index 5dd03256dc..a39d2963d2 100644
--- a/test/storage/asset_file_source.test.cpp
+++ b/test/storage/asset_file_source.test.cpp
@@ -2,7 +2,7 @@
#include <mbgl/util/platform.hpp>
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/run_loop.hpp>
-#include <mbgl/util/threaded_object.hpp>
+#include <mbgl/util/thread.hpp>
#include <mbgl/actor/actor_ref.hpp>
#include <gtest/gtest.h>
@@ -56,11 +56,11 @@ TEST(AssetFileSource, Load) {
std::function<void(mbgl::Response)> requestCallback;
};
- std::vector<std::unique_ptr<util::ThreadedObject<TestWorker>>> threads;
+ std::vector<std::unique_ptr<util::Thread<TestWorker>>> threads;
for (unsigned i = 0; i < numThreads; ++i) {
- std::unique_ptr<util::ThreadedObject<TestWorker>> thread =
- std::make_unique<util::ThreadedObject<TestWorker>>("Test", &fs);
+ std::unique_ptr<util::Thread<TestWorker>> thread =
+ std::make_unique<util::Thread<TestWorker>>("Test", &fs);
thread->actor().invoke(&TestWorker::run, [&] { if (!--completed) loop.stop(); });
threads.push_back(std::move(thread));
diff --git a/test/util/threaded_object.test.cpp b/test/util/thread.test.cpp
index 9a78290305..76fb5ce3f0 100644
--- a/test/util/threaded_object.test.cpp
+++ b/test/util/thread.test.cpp
@@ -2,7 +2,7 @@
#include <mbgl/test/util.hpp>
#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/util/run_loop.hpp>
-#include <mbgl/util/threaded_object.hpp>
+#include <mbgl/util/thread.hpp>
#include <mbgl/util/timer.hpp>
#include <atomic>
@@ -58,9 +58,9 @@ public:
const std::thread::id tid;
};
-TEST(ThreadedObject, invoke) {
+TEST(Thread, invoke) {
const std::thread::id tid = std::this_thread::get_id();
- ThreadedObject<TestObject> thread("Test", tid);
+ Thread<TestObject> thread("Test", tid);
thread.actor().invoke(&TestObject::fn1, 1);
thread.actor().invoke(&TestObject::fn2, [] (int result) { EXPECT_EQ(result, 1); } );
@@ -77,9 +77,9 @@ TEST(ThreadedObject, invoke) {
resultFuture.get();
}
-TEST(ThreadedObject, Context) {
+TEST(Thread, Context) {
const std::thread::id tid = std::this_thread::get_id();
- ThreadedObject<TestObject> thread("Test", tid);
+ Thread<TestObject> thread("Test", tid);
std::promise<bool> result;
auto resultFuture = result.get_future();
@@ -106,9 +106,9 @@ private:
Timer timer;
};
-TEST(ThreadedObject, ExecutesAfter) {
+TEST(Thread, ExecutesAfter) {
RunLoop loop;
- ThreadedObject<TestWorker> thread("Test");
+ Thread<TestWorker> thread("Test");
bool didWork = false;
bool didAfter = false;
@@ -122,9 +122,9 @@ TEST(ThreadedObject, ExecutesAfter) {
EXPECT_TRUE(didAfter);
}
-TEST(ThreadedObject, CanSelfWakeUp) {
+TEST(Thread, CanSelfWakeUp) {
RunLoop loop;
- ThreadedObject<TestWorker> thread("Test");
+ Thread<TestWorker> thread("Test");
thread.actor().invoke(&TestWorker::sendDelayed, [&] {
loop.stop();
@@ -133,7 +133,7 @@ TEST(ThreadedObject, CanSelfWakeUp) {
loop.run();
}
-TEST(ThreadedObject, Concurrency) {
+TEST(Thread, Concurrency) {
auto loop = std::make_shared<RunLoop>();
unsigned numMessages = 100000;
@@ -143,10 +143,10 @@ TEST(ThreadedObject, Concurrency) {
Actor<TestWorker> poolWorker(threadPool);
auto poolWorkerRef = poolWorker.self();
- ThreadedObject<TestWorker> threadedObject("Test");
+ Thread<TestWorker> threadedObject("Test");
auto threadedObjectRef = threadedObject.actor();
- // 10 threads sending 100k messages to the ThreadedObject. The
+ // 10 threads sending 100k messages to the Thread. The
// idea here is to test if the scheduler is handling concurrency
// correctly, otherwise this test should crash.
for (unsigned i = 0; i < numMessages; ++i) {
@@ -162,18 +162,18 @@ TEST(ThreadedObject, Concurrency) {
loop->run();
}
-TEST(ThreadedObject, ThreadPoolMessaging) {
+TEST(Thread, ThreadPoolMessaging) {
auto loop = std::make_shared<RunLoop>();
ThreadPool threadPool(1);
Actor<TestWorker> poolWorker(threadPool);
auto poolWorkerRef = poolWorker.self();
- ThreadedObject<TestWorker> threadedObject("Test");
+ Thread<TestWorker> threadedObject("Test");
auto threadedObjectRef = threadedObject.actor();
- // This is sending a message to the ThreadedObject from the main
- // thread. Then the ThreadedObject will send another message to
+ // This is sending a message to the Thread from the main
+ // thread. Then the Thread will send another message to
// a worker on the ThreadPool.
threadedObjectRef.invoke(&TestWorker::send, [poolWorkerRef, loop] () mutable {
poolWorkerRef.invoke(&TestWorker::send, [loop] () { loop->stop(); });
@@ -189,8 +189,8 @@ TEST(ThreadedObject, ThreadPoolMessaging) {
loop->run();
}
-TEST(ThreadedObject, ReferenceCanOutliveThreadedObject) {
- auto thread = std::make_unique<ThreadedObject<TestWorker>>("Test");
+TEST(Thread, ReferenceCanOutliveThread) {
+ auto thread = std::make_unique<Thread<TestWorker>>("Test");
auto worker = thread->actor();
thread.reset();
@@ -202,10 +202,10 @@ TEST(ThreadedObject, ReferenceCanOutliveThreadedObject) {
usleep(10000);
}
-TEST(ThreadedObject, DeletePausedThreadedObject) {
+TEST(Thread, DeletePausedThread) {
std::atomic_bool flag(false);
- auto thread = std::make_unique<ThreadedObject<TestWorker>>("Test");
+ auto thread = std::make_unique<Thread<TestWorker>>("Test");
thread->pause();
thread->actor().invoke(&TestWorker::send, [&] { flag = true; });
@@ -216,15 +216,15 @@ TEST(ThreadedObject, DeletePausedThreadedObject) {
ASSERT_TRUE(flag);
}
-TEST(ThreadedObject, Pause) {
+TEST(Thread, Pause) {
RunLoop loop;
std::atomic_bool flag(false);
- ThreadedObject<TestWorker> thread1("Test1");
+ Thread<TestWorker> thread1("Test1");
thread1.pause();
- ThreadedObject<TestWorker> thread2("Test2");
+ Thread<TestWorker> thread2("Test2");
for (unsigned i = 0; i < 100; ++i) {
thread1.actor().invoke(&TestWorker::send, [&] { flag = true; });
@@ -236,19 +236,19 @@ TEST(ThreadedObject, Pause) {
loop.run();
}
-TEST(ThreadedObject, Resume) {
+TEST(Thread, Resume) {
RunLoop loop;
std::atomic_bool flag(false);
- ThreadedObject<TestWorker> thread("Test");
+ Thread<TestWorker> thread("Test");
thread.pause();
for (unsigned i = 0; i < 100; ++i) {
thread.actor().invoke(&TestWorker::send, [&] { flag = true; });
}
- // ThreadedObject messages are ondered, when we resume, this is going
+ // Thread messages are ondered, when we resume, this is going
// to me the last thing to run on the message queue.
thread.actor().invoke(&TestWorker::send, [&] { loop.stop(); });
@@ -261,10 +261,10 @@ TEST(ThreadedObject, Resume) {
ASSERT_TRUE(flag);
}
-TEST(ThreadedObject, PauseResume) {
+TEST(Thread, PauseResume) {
RunLoop loop;
- ThreadedObject<TestWorker> thread("Test");
+ Thread<TestWorker> thread("Test");
// Test if multiple pause/resume work.
for (unsigned i = 0; i < 100; ++i) {
diff --git a/test/util/thread_local.test.cpp b/test/util/thread_local.test.cpp
index b2eae74c5f..0590e8b4dc 100644
--- a/test/util/thread_local.test.cpp
+++ b/test/util/thread_local.test.cpp
@@ -1,5 +1,5 @@
#include <mbgl/util/run_loop.hpp>
-#include <mbgl/util/threaded_object.hpp>
+#include <mbgl/util/thread.hpp>
#include <mbgl/util/thread_local.hpp>
#include <mbgl/test/util.hpp>
@@ -39,9 +39,9 @@ TEST(ThreadLocalStorage, Basic) {
int number2 = 2;
int number3 = 3;
- ThreadedObject<TestThread> thread1("Test", &number1);
- ThreadedObject<TestThread> thread2("Test", &number2);
- ThreadedObject<TestThread> thread3("Test", &number3);
+ Thread<TestThread> thread1("Test", &number1);
+ Thread<TestThread> thread2("Test", &number2);
+ Thread<TestThread> thread3("Test", &number3);
auto thread1Ref = thread1.actor();
auto thread2Ref = thread2.actor();
@@ -98,8 +98,8 @@ TEST(ThreadLocalStorage, AutoReclaim) {
auto dtorCounter1 = new DtorCounter{ &counter };
auto dtorCounter2 = new DtorCounter{ &counter };
- auto thread1 = std::make_unique<ThreadedObject<TestThreadReclaim>>("Test", dtorCounter1);
- auto thread2 = std::make_unique<ThreadedObject<TestThreadReclaim>>("Test", dtorCounter2);
+ auto thread1 = std::make_unique<Thread<TestThreadReclaim>>("Test", dtorCounter1);
+ auto thread2 = std::make_unique<Thread<TestThreadReclaim>>("Test", dtorCounter2);
thread1.reset();
thread2.reset();