forked from focus-creative-games/il2cpp_plus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHandle.cpp
More file actions
81 lines (66 loc) · 2.1 KB
/
Handle.cpp
File metadata and controls
81 lines (66 loc) · 2.1 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "il2cpp-config.h"
#include "os/Handle.h"
#if IL2CPP_SUPPORT_THREADS
#include <algorithm>
#include "os/Thread.h"
namespace il2cpp
{
namespace os
{
int32_t Handle::WaitAny(const std::vector<Handle*>& handles, int32_t ms)
{
int timeWaitedMs = 0;
while (ms == -1 || timeWaitedMs <= ms)
{
int32_t numberOfOsHandles = (int32_t)handles.size();
for (int32_t i = 0; i < numberOfOsHandles; ++i)
{
if (handles[i]->Wait(0U))
return i;
}
os::Thread::Sleep(m_waitIntervalMs, true);
timeWaitedMs += m_waitIntervalMs;
}
return 258; // WAIT_TIMEOUT value
}
bool Handle::WaitAll(std::vector<Handle*>& handles, int32_t ms)
{
int timeWaitedMs = 0;
while (ms == -1 || timeWaitedMs <= ms)
{
size_t numberOfOsHandles = handles.size();
std::vector<Handle*> signaledHandles;
for (size_t i = 0; i < numberOfOsHandles; ++i)
{
if (handles[i]->Wait(0U))
signaledHandles.push_back(handles[i]);
}
if (signaledHandles.size() == numberOfOsHandles)
return true; // All handles have been signaled
for (size_t i = 0; i < signaledHandles.size(); ++i)
handles.erase(std::remove(handles.begin(), handles.end(), signaledHandles[i]), handles.end());
os::Thread::Sleep(m_waitIntervalMs, true);
timeWaitedMs += m_waitIntervalMs;
}
return false; // Timed out waiting for all handles to be signaled
}
} // namespace os
} // naemspace il2cpp
#else
namespace il2cpp
{
namespace os
{
int32_t Handle::WaitAny(const std::vector<Handle*>& handles, int32_t ms)
{
IL2CPP_ASSERT(0 && "Threads are not enabled for this platform.");
return 0;
}
bool Handle::WaitAll(std::vector<Handle*>& handles, int32_t ms)
{
IL2CPP_ASSERT(0 && "Threads are not enabled for this platform.");
return false;
}
} // namespace os
} // naemspace il2cpp
#endif