Skip to content

Commit

Permalink
Fix Windows Engine Bot (flutter#6844)
Browse files Browse the repository at this point in the history
Follow-up to flutter/engine#6833
  • Loading branch information
goderbauer authored Nov 13, 2018
1 parent e6d6f18 commit 6a132f8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 20 deletions.
33 changes: 33 additions & 0 deletions fml/thread_local.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

namespace fml {

#if FML_THREAD_LOCAL_PTHREADS

ThreadLocal::ThreadLocal() : ThreadLocal(nullptr) {}

ThreadLocal::ThreadLocal(ThreadLocalDestroyCallback destroy)
Expand Down Expand Up @@ -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
25 changes: 5 additions & 20 deletions fml/thread_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down

0 comments on commit 6a132f8

Please sign in to comment.