• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
ThreadLocalPointer(void (* destroy)(void *))14 ThreadLocalPointer::ThreadLocalPointer(void (*destroy)(void*)) {
15   FML_CHECK(pthread_key_create(&key_, destroy) == 0);
16 }
17 
~ThreadLocalPointer()18 ThreadLocalPointer::~ThreadLocalPointer() {
19   FML_CHECK(pthread_key_delete(key_) == 0);
20 }
21 
get() const22 void* ThreadLocalPointer::get() const {
23   return pthread_getspecific(key_);
24 }
25 
swap(void * ptr)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
36