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 <cstring>
10
11#include "flutter/fml/logging.h"
12
13namespace fml {
14namespace internal {
15
16ThreadLocalPointer::ThreadLocalPointer(void (*destroy)(void*)) {
17 FML_CHECK(pthread_key_create(&key_, destroy) == 0);
18}
19
20ThreadLocalPointer::~ThreadLocalPointer() {
21 FML_CHECK(pthread_key_delete(key_) == 0);
22}
23
24void* ThreadLocalPointer::get() const {
25 return pthread_getspecific(key: key_);
26}
27
28void* ThreadLocalPointer::swap(void* ptr) {
29 void* old_ptr = get();
30 int err = pthread_setspecific(key: key_, pointer: ptr);
31 if (err) {
32 FML_CHECK(false) << "pthread_setspecific failed (" << err
33 << "): " << strerror(errnum: err);
34 }
35 return old_ptr;
36}
37
38} // namespace internal
39} // namespace fml
40
41#endif // FML_THREAD_LOCAL_PTHREADS
42

Provided by KDAB

Privacy Policy
Learn more about Flutter for embedded and desktop on industrialflutter.com

source code of flutter_engine/flutter/fml/thread_local.cc