SpiecsEngine
 
Loading...
Searching...
No Matches

◆ TEST_F() [32/72]

SpicesTest::TEST_F ( ObjectPool_test ,
ThreadSafe  )

Testing Spices::ObjectPool::ThreadNew/ThreadDelete.

Definition at line 152 of file ObjectPool_test.h.

152 {
153
155
156 std::vector<Object*> objects1;
157 std::vector<Object*> objects2;
158
159 objects1.resize(n);
160 objects2.resize(n);
161
162 std::thread t1([&]() {
163 for (int i = 0; i < n; i++)
164 {
165 objects1[i] = m_ObjectPool->ThreadNew();
166 }
167 });
168
169 std::thread t2([&]() {
170 for (int i = 0; i < n; i++)
171 {
172 objects2[i] = m_ObjectPool->ThreadNew();
173 }
174 });
175
176 t1.join();
177 t2.join();
178
179 std::thread t3([&]() {
180 for (int i = 0; i < n; i++)
181 {
182 m_ObjectPool->ThreadDelete(objects1[i]);
183 }
184 });
185
186 std::thread t4([&]() {
187 for (int i = 0; i < n; i++)
188 {
189 m_ObjectPool->ThreadDelete(objects2[i]);
190 }
191 });
192
193 t3.join();
194 t4.join();
195
196 EXPECT_EQ(m_ObjectPool->GetNMemoryBlocks(), 2);
197
198 const size_t allBytes = Spices::MemoryLibrary::align_up<size_t>(n * sizeof(Object), 8 * 1024) * 2;
199 EXPECT_EQ(m_ObjectPool->GetSpareBytes(), allBytes);
200 }
#define SPICESTEST_PROFILE_FUNCTION()