brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · 0939a76 Raw
64 lines · cpp
1//===-- Tests for thrd_exit -----------------------------------------------===//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-exception6//7//===----------------------------------------------------------------------===//8 9#include "src/threads/thrd_create.h"10#include "src/threads/thrd_exit.h"11#include "src/threads/thrd_join.h"12#include "test/IntegrationTest/test.h"13 14#include <threads.h>15 16bool dtor_called = false;17 18class A {19  int val;20 21public:22  A(int i) { val = i; }23 24  void set(int i) { val = i; }25 26  ~A() {27    val = 0;28    dtor_called = true;29  }30};31 32thread_local A thread_local_a(123);33 34int func(void *) {35  thread_local_a.set(321);36  LIBC_NAMESPACE::thrd_exit(0);37  return 0;38}39 40TEST_MAIN() {41  thrd_t th;42  int retval;43 44  ASSERT_EQ(LIBC_NAMESPACE::thrd_create(&th, func, nullptr), thrd_success);45  ASSERT_EQ(LIBC_NAMESPACE::thrd_join(th, &retval), thrd_success);46 47  ASSERT_TRUE(dtor_called);48  LIBC_NAMESPACE::thrd_exit(0);49  return 0;50}51 52extern "C" {53 54using Destructor = void(void *);55 56int __cxa_thread_atexit_impl(Destructor *, void *, void *);57 58// We do not link integration tests to C++ runtime pieces like the libcxxabi.59// So, we provide our own simple __cxa_thread_atexit implementation.60int __cxa_thread_atexit(Destructor *dtor, void *obj, void *) {61  return __cxa_thread_atexit_impl(dtor, obj, nullptr);62}63}64