Flutter Engine
thread_local.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "flutter/fml/thread_local.h"
6 
7 #if FML_THREAD_LOCAL_PTHREADS
8 
9 #include "flutter/fml/logging.h"
10 
11 namespace fml {
12 namespace internal {
13 
14 ThreadLocalPointer::ThreadLocalPointer(void (*destroy)(void*)) {
15  FML_CHECK(pthread_key_create(&key_, destroy) == 0);
16 }
17 
18 ThreadLocalPointer::~ThreadLocalPointer() {
19  FML_CHECK(pthread_key_delete(key_) == 0);
20 }
21 
22 void* ThreadLocalPointer::get() const {
23  return pthread_getspecific(key_);
24 }
25 
26 void* ThreadLocalPointer::swap(void* ptr) {
27  void* old_ptr = get();
28  FML_CHECK(pthread_setspecific(key_, ptr) == 0);
29  return old_ptr;
30 }
31 
32 } // namespace internal
33 } // namespace fml
34 
35 #endif // FML_THREAD_LOCAL_PTHREADS
void swap(scoped_nsprotocol< C > &p1, scoped_nsprotocol< C > &p2)
Definition: ascii_trie.cc:9
#define FML_CHECK(condition)
Definition: logging.h:68