[clang][extract-api] Emit "navigator" property of "name" in SymbolGraph
[llvm-project.git] / compiler-rt / lib / sanitizer_common / tests / sanitizer_stoptheworld_testlib.cpp
blobe333bf0835232852a0222822b6ecce2454031ba0
1 //===-- sanitizer_stoptheworld_testlib.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 // Dynamic library to test StopTheWorld functionality.
9 // When loaded with LD_PRELOAD, it will periodically suspend all threads.
10 //===----------------------------------------------------------------------===//
11 /* Usage:
12 clang++ -fno-exceptions -g -fPIC -I. \
13 sanitizer_common/tests/sanitizer_stoptheworld_testlib.cpp \
14 sanitizer_common/sanitizer_*.cpp -shared -lpthread -o teststoptheworld.so
15 LD_PRELOAD=`pwd`/teststoptheworld.so /your/app
18 #include "sanitizer_common/sanitizer_platform.h"
19 #if SANITIZER_LINUX
21 #include <dlfcn.h>
22 #include <stddef.h>
23 #include <stdio.h>
24 #include <pthread.h>
25 #include <unistd.h>
27 #include "sanitizer_common/sanitizer_stoptheworld.h"
29 namespace {
30 const uptr kSuspendDuration = 3;
31 const uptr kRunDuration = 3;
33 void Callback(const SuspendedThreadsList &suspended_threads_list,
34 void *argument) {
35 sleep(kSuspendDuration);
38 void *SuspenderThread(void *argument) {
39 while (true) {
40 sleep(kRunDuration);
41 StopTheWorld(Callback, NULL);
43 return NULL;
46 __attribute__((constructor)) void StopTheWorldTestLibConstructor(void) {
47 pthread_t thread_id;
48 pthread_create(&thread_id, NULL, SuspenderThread, NULL);
50 } // namespace
52 #endif // SANITIZER_LINUX