[clang] Handle __declspec() attributes in using
[llvm-project.git] / compiler-rt / lib / memprof / memprof_posix.cpp
blobee0821b85102d91f5fd690f750f120e3cbb1e663
1 //===-- memprof_posix.cpp ------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file is a part of MemProfiler, a memory profiler.
11 // Posix-specific details.
12 //===----------------------------------------------------------------------===//
14 #include "sanitizer_common/sanitizer_platform.h"
15 #if !SANITIZER_POSIX
16 #error Only Posix supported
17 #endif
19 #include "memprof_thread.h"
20 #include "sanitizer_common/sanitizer_internal_defs.h"
22 #include <pthread.h>
24 namespace __memprof {
26 // ---------------------- TSD ---------------- {{{1
28 static pthread_key_t tsd_key;
29 static bool tsd_key_inited = false;
30 void TSDInit(void (*destructor)(void *tsd)) {
31 CHECK(!tsd_key_inited);
32 tsd_key_inited = true;
33 CHECK_EQ(0, pthread_key_create(&tsd_key, destructor));
36 void *TSDGet() {
37 CHECK(tsd_key_inited);
38 return pthread_getspecific(tsd_key);
41 void TSDSet(void *tsd) {
42 CHECK(tsd_key_inited);
43 pthread_setspecific(tsd_key, tsd);
46 void PlatformTSDDtor(void *tsd) {
47 MemprofThreadContext *context = (MemprofThreadContext *)tsd;
48 if (context->destructor_iterations > 1) {
49 context->destructor_iterations--;
50 CHECK_EQ(0, pthread_setspecific(tsd_key, tsd));
51 return;
53 MemprofThread::TSDDtor(tsd);
55 } // namespace __memprof