From 6a132f80f44880b4feaadfebe7daf18867bea5fa Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Tue, 13 Nov 2018 09:46:30 -0800 Subject: [PATCH] Fix Windows Engine Bot (#6844) Follow-up to https://github.com/flutter/engine/pull/6833 --- fml/thread_local.cc | 33 +++++++++++++++++++++++++++++++++ fml/thread_local.h | 25 +++++-------------------- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/fml/thread_local.cc b/fml/thread_local.cc index 4617f8243c17d..d0afbc00186a0 100644 --- a/fml/thread_local.cc +++ b/fml/thread_local.cc @@ -6,6 +6,8 @@ namespace fml { +#if FML_THREAD_LOCAL_PTHREADS + ThreadLocal::ThreadLocal() : ThreadLocal(nullptr) {} ThreadLocal::ThreadLocal(ThreadLocalDestroyCallback destroy) @@ -33,4 +35,35 @@ ThreadLocal::Box::Box(ThreadLocalDestroyCallback destroy, intptr_t value) ThreadLocal::Box::~Box() = default; +#else // FML_THREAD_LOCAL_PTHREADS + +ThreadLocal::ThreadLocal() : ThreadLocal(nullptr) {} + +ThreadLocal::ThreadLocal(ThreadLocalDestroyCallback destroy) + : destroy_(destroy), value_(0) {} + +void ThreadLocal::Set(intptr_t value) { + if (value_ == value) { + return; + } + + if (value_ != 0 && destroy_) { + destroy_(value_); + } + + value_ = value; +} + +intptr_t ThreadLocal::Get() { + return value_; +} + +ThreadLocal::~ThreadLocal() { + if (value_ != 0 && destroy_) { + destroy_(value_); + } +} + +#endif // FML_THREAD_LOCAL_PTHREADS + } // namespace fml diff --git a/fml/thread_local.h b/fml/thread_local.h index b2d4bdfa774c0..4bf518244a6e9 100644 --- a/fml/thread_local.h +++ b/fml/thread_local.h @@ -101,30 +101,15 @@ class ThreadLocal { class ThreadLocal { public: - ThreadLocal() : ThreadLocal(nullptr) {} - - ThreadLocal(ThreadLocalDestroyCallback destroy) - : destroy_(destroy), value_(0) {} - - void Set(intptr_t value) { - if (value_ == value) { - return; - } + ThreadLocal(); - if (value_ != 0 && destroy_) { - destroy_(value_); - } + ThreadLocal(ThreadLocalDestroyCallback destroy); - value_ = value; - } + void Set(intptr_t value); - intptr_t Get() { return value_; } + intptr_t Get(); - ~ThreadLocal() { - if (value_ != 0 && destroy_) { - destroy_(value_); - } - } + ~ThreadLocal(); private: ThreadLocalDestroyCallback destroy_;