am cd79a59b: Merge "Add test for thread_local keyword."
				
					
				
			* commit 'cd79a59b18f8e81b5f37258f376a726dc8acb81a': Add test for thread_local keyword.
This commit is contained in:
		@@ -287,6 +287,10 @@ bionic-unit-tests_shared_libraries_target := \
 | 
			
		||||
    libdl_preempt_test_1 \
 | 
			
		||||
    libdl_preempt_test_2
 | 
			
		||||
 | 
			
		||||
# TODO: clang support for thread_local on arm is done via __aeabi_read_tp()
 | 
			
		||||
# which bionic does not support. Reenable this once this question is resolved.
 | 
			
		||||
bionic-unit-tests_clang_target := false
 | 
			
		||||
 | 
			
		||||
ifneq ($(filter $(TARGET_ARCH),arm arm64),$(TARGET_ARCH))
 | 
			
		||||
bionic-unit-tests_shared_libraries_target += libdl_test_df_1_global
 | 
			
		||||
endif
 | 
			
		||||
 
 | 
			
		||||
@@ -20,6 +20,36 @@
 | 
			
		||||
 | 
			
		||||
#include <string>
 | 
			
		||||
 | 
			
		||||
static std::string class_with_dtor_output;
 | 
			
		||||
 | 
			
		||||
class ClassWithDtor {
 | 
			
		||||
 public:
 | 
			
		||||
  void set_message(const std::string& msg) {
 | 
			
		||||
    message = msg;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  ~ClassWithDtor() {
 | 
			
		||||
    class_with_dtor_output += message;
 | 
			
		||||
  }
 | 
			
		||||
 private:
 | 
			
		||||
  std::string message;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
thread_local ClassWithDtor class_with_dtor;
 | 
			
		||||
 | 
			
		||||
static void* thread_nop(void* arg) {
 | 
			
		||||
  class_with_dtor.set_message(*static_cast<std::string*>(arg));
 | 
			
		||||
  return nullptr;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST(thread_local, smoke) {
 | 
			
		||||
  std::string msg("dtor called.");
 | 
			
		||||
  pthread_t t;
 | 
			
		||||
  ASSERT_EQ(0, pthread_create(&t, nullptr, thread_nop, &msg));
 | 
			
		||||
  ASSERT_EQ(0, pthread_join(t, nullptr));
 | 
			
		||||
  ASSERT_EQ("dtor called.", class_with_dtor_output);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extern "C" int __cxa_thread_atexit_impl(void (*fn)(void*), void* arg, void* dso_handle);
 | 
			
		||||
 | 
			
		||||
static void thread_atexit_fn1(void* arg) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user