mirror of https://github.com/auygun/kaliber.git
Make thread-local-task-runner a shared_ptr
This commit is contained in:
parent
83400a0b52
commit
305b23738c
|
@ -4,12 +4,14 @@
|
|||
|
||||
#include "base/log.h"
|
||||
|
||||
namespace base {
|
||||
|
||||
namespace {
|
||||
|
||||
void PostTaskAndReplyRelay(base::Location from,
|
||||
base::Closure task_cb,
|
||||
base::Closure reply_cb,
|
||||
base::TaskRunner* destination) {
|
||||
void PostTaskAndReplyRelay(Location from,
|
||||
Closure task_cb,
|
||||
Closure reply_cb,
|
||||
std::shared_ptr<TaskRunner> destination) {
|
||||
task_cb();
|
||||
|
||||
if (reply_cb)
|
||||
|
@ -18,22 +20,20 @@ void PostTaskAndReplyRelay(base::Location from,
|
|||
|
||||
} // namespace
|
||||
|
||||
namespace base {
|
||||
|
||||
// The task runner that belongs to the thread it's created in. Tasks to be run
|
||||
// on a specific thread can be posted to this task runner.
|
||||
// TaskRunner::GetThreadLocalTaskRunner()->SingleConsumerRun() is expected to be
|
||||
// periodically called.
|
||||
thread_local std::unique_ptr<TaskRunner> TaskRunner::thread_local_task_runner;
|
||||
thread_local std::shared_ptr<TaskRunner> TaskRunner::thread_local_task_runner;
|
||||
|
||||
void TaskRunner::CreateThreadLocalTaskRunner() {
|
||||
DCHECK(!thread_local_task_runner);
|
||||
|
||||
thread_local_task_runner = std::make_unique<TaskRunner>();
|
||||
thread_local_task_runner = std::make_shared<TaskRunner>();
|
||||
}
|
||||
|
||||
TaskRunner* TaskRunner::GetThreadLocalTaskRunner() {
|
||||
return thread_local_task_runner.get();
|
||||
std::shared_ptr<TaskRunner> TaskRunner::GetThreadLocalTaskRunner() {
|
||||
return thread_local_task_runner;
|
||||
}
|
||||
|
||||
void TaskRunner::PostTask(Location from, Closure task) {
|
||||
|
@ -49,8 +49,8 @@ void TaskRunner::PostTaskAndReply(Location from, Closure task, Closure reply) {
|
|||
DCHECK(reply) << LOCATION(from);
|
||||
DCHECK(thread_local_task_runner) << LOCATION(from);
|
||||
|
||||
auto relay = std::bind(::PostTaskAndReplyRelay, from, std::move(task),
|
||||
std::move(reply), thread_local_task_runner.get());
|
||||
auto relay = std::bind(PostTaskAndReplyRelay, from, std::move(task),
|
||||
std::move(reply), thread_local_task_runner);
|
||||
PostTask(from, std::move(relay));
|
||||
}
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ class TaskRunner {
|
|||
void WaitForCompletion();
|
||||
|
||||
static void CreateThreadLocalTaskRunner();
|
||||
static TaskRunner* GetThreadLocalTaskRunner();
|
||||
static std::shared_ptr<TaskRunner> GetThreadLocalTaskRunner();
|
||||
|
||||
private:
|
||||
using Task = std::tuple<Location, Closure>;
|
||||
|
@ -76,7 +76,7 @@ class TaskRunner {
|
|||
std::atomic<size_t> task_count_{0};
|
||||
std::atomic<bool> cancel_tasks_{false};
|
||||
|
||||
static thread_local std::unique_ptr<TaskRunner> thread_local_task_runner;
|
||||
static thread_local std::shared_ptr<TaskRunner> thread_local_task_runner;
|
||||
|
||||
void CancelTasksInternal();
|
||||
|
||||
|
|
|
@ -11,8 +11,6 @@
|
|||
|
||||
namespace base {
|
||||
|
||||
class TaskRunner;
|
||||
|
||||
// Feed the ThreadPool tasks (in the form of Closure objects) and they will be
|
||||
// called on any thread from the pool.
|
||||
class ThreadPool {
|
||||
|
|
|
@ -84,7 +84,7 @@ class AudioMixer : public AudioSink::Delegate {
|
|||
|
||||
std::list<std::shared_ptr<Resource>> end_list_;
|
||||
|
||||
base::TaskRunner* main_thread_task_runner_;
|
||||
std::shared_ptr<base::TaskRunner> main_thread_task_runner_;
|
||||
|
||||
std::unique_ptr<AudioSink> audio_sink_;
|
||||
|
||||
|
|
|
@ -144,7 +144,7 @@ class RendererOpenGL final : public Renderer {
|
|||
|
||||
std::counting_semaphore<> draw_complete_semaphore_{0};
|
||||
|
||||
base::TaskRunner* main_thread_task_runner_;
|
||||
std::shared_ptr<base::TaskRunner> main_thread_task_runner_;
|
||||
#endif // THREADED_RENDERING
|
||||
|
||||
// Stats.
|
||||
|
|
Loading…
Reference in New Issue