Flutter Engine
thread_local_unittests.cc File Reference
#include <atomic>
#include <thread>
#include "flutter/fml/macros.h"
#include "flutter/fml/thread_local.h"
#include "gtest/gtest.h"

Go to the source code of this file.

Functions

 TEST (ThreadLocal, SimpleInitialization)
 
 TEST (ThreadLocal, SimpleInitializationCheckInAnother)
 
 TEST (ThreadLocal, DestroyCallback)
 
 TEST (ThreadLocal, DestroyCallback2)
 
 TEST (ThreadLocal, DestroyThreadTimeline)
 

Function Documentation

◆ TEST() [1/5]

TEST ( ThreadLocal  ,
SimpleInitialization   
)

Definition at line 37 of file thread_local_unittests.cc.

References value.

37  {
38  std::thread thread([&] {
39  ASSERT_EQ(local.get(), nullptr);
40  auto value = 100;
41  local.reset(new Box(value));
42  ASSERT_EQ(local.get()->value(), value);
43  });
44  thread.join();
45 }
uint8_t value

◆ TEST() [2/5]

TEST ( ThreadLocal  ,
SimpleInitializationCheckInAnother   
)

Definition at line 47 of file thread_local_unittests.cc.

References value.

47  {
48  std::thread thread([&] {
49  ASSERT_EQ(local.get(), nullptr);
50  auto value = 100;
51  local.reset(new Box(value));
52  ASSERT_EQ(local.get()->value(), value);
53  std::thread thread2([&]() { ASSERT_EQ(local.get(), nullptr); });
54  thread2.join();
55  });
56  thread.join();
57 }
uint8_t value

◆ TEST() [3/5]

TEST ( ThreadLocal  ,
DestroyCallback   
)

Definition at line 59 of file thread_local_unittests.cc.

References value.

59  {
60  std::atomic_int destroys{0};
61  std::thread thread([&] {
62  ASSERT_EQ(local.get(), nullptr);
63  auto value = 100;
64  local.reset(new Box(value, &destroys));
65  ASSERT_EQ(local.get()->value(), value);
66  ASSERT_EQ(destroys.load(), 0);
67  });
68  thread.join();
69  ASSERT_EQ(destroys.load(), 1);
70 }
uint8_t value

◆ TEST() [4/5]

TEST ( ThreadLocal  ,
DestroyCallback2   
)

Definition at line 72 of file thread_local_unittests.cc.

72  {
73  std::atomic_int destroys{0};
74  std::thread thread([&] {
75  local.reset(new Box(100, &destroys));
76  ASSERT_EQ(local.get()->value(), 100);
77  ASSERT_EQ(destroys.load(), 0);
78  local.reset(new Box(200, &destroys));
79  ASSERT_EQ(local.get()->value(), 200);
80  ASSERT_EQ(destroys.load(), 1);
81  });
82  thread.join();
83  ASSERT_EQ(destroys.load(), 2);
84 }

◆ TEST() [5/5]

TEST ( ThreadLocal  ,
DestroyThreadTimeline   
)

Definition at line 86 of file thread_local_unittests.cc.

86  {
87  std::atomic_int destroys{0};
88  std::thread thread([&] {
89  std::thread thread2([&]() {
90  local.reset(new Box(100, &destroys));
91  ASSERT_EQ(local.get()->value(), 100);
92  ASSERT_EQ(destroys.load(), 0);
93  local.reset(new Box(200, &destroys));
94  ASSERT_EQ(local.get()->value(), 200);
95  ASSERT_EQ(destroys.load(), 1);
96  });
97  ASSERT_EQ(local.get(), nullptr);
98  thread2.join();
99  ASSERT_EQ(local.get(), nullptr);
100  ASSERT_EQ(destroys.load(), 2);
101  });
102  thread.join();
103  ASSERT_EQ(destroys.load(), 2);
104 }