少年修仙传客户端基础资源
hch
2024-04-01 d01413b00ef631ac20347716b23818b0b811f65f
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "il2cpp-config.h"
#include "WindowsHelpers.h"
#include "os/Time.h"
 
#if IL2CPP_TARGET_WINDOWS
 
namespace il2cpp
{
namespace os
{
namespace win
{
    WaitStatus WaitForSingleObjectAndAccountForAPCs(HANDLE handle, uint32_t ms, bool interruptible)
    {
        uint32_t remainingWaitTimeMS = ms;
        while (true)
        {
            uint32_t waitStartTime = os::Time::GetTicksMillisecondsMonotonic();
            DWORD result = ::WaitForSingleObjectEx(handle, remainingWaitTimeMS, interruptible);
 
            if (result == WAIT_OBJECT_0)
                return kWaitStatusSuccess;
 
            if (result == WAIT_TIMEOUT)
                return kWaitStatusTimeout;
 
            if (result == WAIT_IO_COMPLETION)
            {
                if (ms != INFINITE)
                {
                    uint32_t haveWaitedTimeMS = os::Time::GetTicksMillisecondsMonotonic() - waitStartTime;
                    if (haveWaitedTimeMS >= remainingWaitTimeMS)
                        return kWaitStatusTimeout;
                    remainingWaitTimeMS -= haveWaitedTimeMS;
                }
                continue;
            }
 
            break;
        }
 
        return kWaitStatusFailure;
    }
 
    int32_t WaitForAnyObjectAndAccountForAPCs(const std::vector<HANDLE>& handles, uint32_t ms, bool interruptible)
    {
        IL2CPP_ASSERT(handles.size() != 0);
 
        uint32_t remainingWaitTimeMS = ms;
        while (true)
        {
            uint32_t waitStartTime = os::Time::GetTicksMillisecondsMonotonic();
            DWORD result = ::WaitForMultipleObjectsEx((DWORD)handles.size(), handles.data(), false, remainingWaitTimeMS, interruptible);
 
            // If we are waiting for just one of many objects, the return value
            // might be WAIT_OBJECT_0 + the index of the handle that was signaled.
            // Check for a return value in that range and return the index of that handle.
            if (result >= WAIT_OBJECT_0 && result < WAIT_OBJECT_0 + handles.size())
                return result - WAIT_OBJECT_0;
 
            if (result == WAIT_TIMEOUT)
                return WAIT_TIMEOUT;
 
            if (result == WAIT_IO_COMPLETION)
            {
                if (ms != INFINITE)
                {
                    uint32_t haveWaitedTimeMS = os::Time::GetTicksMillisecondsMonotonic() - waitStartTime;
                    if (haveWaitedTimeMS >= remainingWaitTimeMS)
                        return WAIT_TIMEOUT;
                    remainingWaitTimeMS -= haveWaitedTimeMS;
                }
                continue;
            }
 
            break;
        }
 
        return WAIT_FAILED;
    }
 
    bool WaitForAllObjectsAndAccountForAPCs(const std::vector<HANDLE>& handles, uint32_t ms, bool interruptible)
    {
        IL2CPP_ASSERT(handles.size() != 0);
 
        uint32_t remainingWaitTimeMS = ms;
        while (true)
        {
            uint32_t waitStartTime = os::Time::GetTicksMillisecondsMonotonic();
            DWORD result = ::WaitForMultipleObjectsEx((DWORD)handles.size(), handles.data(), true, remainingWaitTimeMS, interruptible);
 
            if (result == WAIT_OBJECT_0)
                return true;
 
            if (result == WAIT_TIMEOUT)
                return false;
 
            if (result == WAIT_IO_COMPLETION)
            {
                if (ms != INFINITE)
                {
                    uint32_t haveWaitedTimeMS = os::Time::GetTicksMillisecondsMonotonic() - waitStartTime;
                    if (haveWaitedTimeMS >= remainingWaitTimeMS)
                        return false;
                    remainingWaitTimeMS -= haveWaitedTimeMS;
                }
                continue;
            }
 
            break;
        }
 
        return false;
    }
}
}
}
 
#endif // IL2CPP_TARGET_WINDOWS