forked from Shell4026/ShellEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadSyncManager.cpp
More file actions
49 lines (39 loc) · 988 Bytes
/
Copy pathThreadSyncManager.cpp
File metadata and controls
49 lines (39 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "PCH.h"
#include "ThreadSyncManager.h"
#include "Logger.h"
#include <algorithm>
#include <string>
namespace sh::core
{
void ThreadSyncManager::PushSyncable(ISyncable& syncable)
{
syncables.push(&syncable);
}
void ThreadSyncManager::AddThread(EngineThread& thread)
{
auto it = std::find(threads.begin(), threads.end(), &thread);
if (it != threads.end()) // 중복 확인
return;
threads.push_back(&thread);
}
void ThreadSyncManager::Sync()
{
//SH_INFO("Start sync");
for (int i = 0; i < threads.size(); ++i)
threads[i]->mutex.lock(); // 자고 있는 상태면 잠금을 획득 할 수 있다. 아니면 대기
while (!syncables.empty())
{
core::ISyncable* syncable = syncables.front();
syncables.pop();
if (syncable)
syncable->Sync();
}
for (int i = threads.size() - 1; i >= 0; --i)
threads[i]->mutex.unlock();
}
void ThreadSyncManager::AwakeThread()
{
for (auto& thr : threads)
thr->Awake();
}
}//namespace