123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- #include "thread_windows.h"
- #if defined(WINDOWS_ENABLED) && !defined(UWP_ENABLED)
- #include "core/os/memory.h"
- Thread::ID ThreadWindows::get_id() const {
- return id;
- }
- Thread *ThreadWindows::create_thread_windows() {
- return memnew(ThreadWindows);
- }
- DWORD ThreadWindows::thread_callback(LPVOID userdata) {
- ThreadWindows *t = reinterpret_cast<ThreadWindows *>(userdata);
- ScriptServer::thread_enter();
- t->id = (ID)GetCurrentThreadId();
- t->callback(t->user);
- ScriptServer::thread_exit();
- return 0;
- }
- Thread *ThreadWindows::create_func_windows(ThreadCreateCallback p_callback, void *p_user, const Settings &) {
- ThreadWindows *tr = memnew(ThreadWindows);
- tr->callback = p_callback;
- tr->user = p_user;
- tr->handle = CreateThread(
- NULL,
- 0,
- thread_callback,
- tr,
- 0,
- NULL);
- return tr;
- }
- Thread::ID ThreadWindows::get_thread_id_func_windows() {
- return (ID)GetCurrentThreadId();
- }
- void ThreadWindows::wait_to_finish_func_windows(Thread *p_thread) {
- ThreadWindows *tp = static_cast<ThreadWindows *>(p_thread);
- ERR_FAIL_COND(!tp);
- WaitForSingleObject(tp->handle, INFINITE);
- CloseHandle(tp->handle);
-
- }
- void ThreadWindows::make_default() {
- create_func = create_func_windows;
- get_thread_id_func = get_thread_id_func_windows;
- wait_to_finish_func = wait_to_finish_func_windows;
- }
- ThreadWindows::ThreadWindows() :
- handle(NULL) {
- }
- ThreadWindows::~ThreadWindows() {
- }
- #endif
|