diff options
author | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2019-10-04 12:30:41 +0300 |
---|---|---|
committer | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2019-10-04 17:42:21 +0300 |
commit | bef635765a1bbec14d7732856c38c037ea8add6a (patch) | |
tree | 47443222a5982031b4c9ecd531bea14edc61a8c8 /src/mbgl/util | |
parent | 198e3453394ccb2b1f7db72d1858cfd18e302a1e (diff) | |
download | qtlocation-mapboxgl-bef635765a1bbec14d7732856c38c037ea8add6a.tar.gz |
[core] Decouple Scheduler interface from actor model
So that it is possible to schedule normal `std::function` and use `mapbox::base::WeakPtr`.
Diffstat (limited to 'src/mbgl/util')
-rw-r--r-- | src/mbgl/util/thread_pool.cpp | 9 | ||||
-rw-r--r-- | src/mbgl/util/thread_pool.hpp | 4 |
2 files changed, 6 insertions, 7 deletions
diff --git a/src/mbgl/util/thread_pool.cpp b/src/mbgl/util/thread_pool.cpp index e839d1b4be..d8df0cd575 100644 --- a/src/mbgl/util/thread_pool.cpp +++ b/src/mbgl/util/thread_pool.cpp @@ -26,11 +26,10 @@ ThreadPool::ThreadPool(std::size_t count) { return; } - auto mailbox = queue.front(); + auto function = std::move(queue.front()); queue.pop(); lock.unlock(); - - Mailbox::maybeReceive(mailbox); + if (function) function(); } }); } @@ -49,10 +48,10 @@ ThreadPool::~ThreadPool() { } } -void ThreadPool::schedule(std::weak_ptr<Mailbox> mailbox) { +void ThreadPool::schedule(std::function<void()> fn) { { std::lock_guard<std::mutex> lock(mutex); - queue.push(mailbox); + queue.push(std::move(fn)); } cv.notify_one(); diff --git a/src/mbgl/util/thread_pool.hpp b/src/mbgl/util/thread_pool.hpp index 509fd06061..96fc13bda5 100644 --- a/src/mbgl/util/thread_pool.hpp +++ b/src/mbgl/util/thread_pool.hpp @@ -15,11 +15,11 @@ public: explicit ThreadPool(std::size_t count); ~ThreadPool() override; - void schedule(std::weak_ptr<Mailbox>) override; + void schedule(std::function<void()>) override; private: std::vector<std::thread> threads; - std::queue<std::weak_ptr<Mailbox>> queue; + std::queue<std::function<void()>> queue; std::mutex mutex; std::condition_variable cv; bool terminate{ false }; |