-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathg_thread.cpp
More file actions
43 lines (36 loc) · 830 Bytes
/
g_thread.cpp
File metadata and controls
43 lines (36 loc) · 830 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
extern "C"
{
#define QCVM_INTERNAL
#include "shared/shared.h"
#include "vm.h"
#include "g_thread.h"
};
#if ALLOW_DEBUGGING
#include <thread>
#include <mutex>
#include <chrono>
qcvm_mutex_t qcvm_cpp_create_mutex(void)
{
return reinterpret_cast<qcvm_mutex_t>(new std::mutex);
}
void qcvm_cpp_free_mutex(qcvm_mutex_t mutex)
{
delete reinterpret_cast<std::mutex *>(mutex);
}
void qcvm_cpp_lock_mutex(qcvm_mutex_t mutex)
{
reinterpret_cast<std::mutex *>(mutex)->lock();
}
void qcvm_cpp_unlock_mutex(qcvm_mutex_t mutex)
{
reinterpret_cast<std::mutex *>(mutex)->unlock();
}
qcvm_thread_t qcvm_cpp_create_thread(qcvm_thread_func_t func)
{
return reinterpret_cast<qcvm_thread_t>(new std::thread(func));
}
void qcvm_cpp_thread_sleep(const uint32_t ms)
{
std::this_thread::sleep_for(std::chrono::milliseconds(ms));
}
#endif