少年修仙传客户端基础资源
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
#include "il2cpp-config.h"
 
#if IL2CPP_THREADS_STD
 
#include "os/Thread.h"
#include "ThreadImpl.h"
 
#include <thread>
 
namespace il2cpp
{
namespace os
{
    struct StartData
    {
        Thread::StartFunc m_StartFunc;
        void* m_StartArg;
    };
 
 
    static void ThreadStartWrapper(void* arg)
    {
        StartData* startData = (StartData*)arg;
        startData->m_StartFunc(startData->m_StartArg);
 
        free(startData);
    }
 
    uint64_t ThreadImpl::Id()
    {
        return m_Thread.get_id().hash();
    }
 
    ErrorCode ThreadImpl::Run(Thread::StartFunc func, void* arg, int64_t affinityMask)
    {
        StartData* startData = (StartData*)malloc(sizeof(StartData));
        startData->m_StartFunc = func;
        startData->m_StartArg = arg;
 
        std::thread t(ThreadStartWrapper, startData);
        if (affinityMask != Thread::kThreadAffinityAll)
        {
            IL2CPP_ASSERT(0 && "Using non-default thread affinity is not supported on the STD implementation.");
        }
 
        m_Thread.swap(t);
 
        return kErrorCodeSuccess;
    }
 
    WaitStatus ThreadImpl::Join(uint32_t ms)
    {
        m_Thread.join();
 
        return kWaitStatusSuccess;
    }
 
    ErrorCode ThreadImpl::Sleep(uint32_t milliseconds)
    {
        std::chrono::milliseconds dura(milliseconds);
        std::this_thread::sleep_for(dura);
 
        return kErrorCodeSuccess;
    }
 
    uint64_t ThreadImpl::CurrentThreadId()
    {
        return std::this_thread::get_id().hash();
    }
}
}
 
#endif