CyberEngineMkIII
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
CYBWin32Thread.cpp
1 #include "CYB.hpp"
2 
4  FThreadable(AThreadable),
5  FThread(Core().FModuleManager.Call<Modules::Kernel32::CreateThread>(nullptr, 0U, ThreadProc, &AThreadable, 0U, nullptr))
6 {
7  if (FThread == nullptr)
9 }
10 
12  Core().FModuleManager.Call<Modules::Kernel32::CloseHandle>(FThread);
13 }
14 
15 unsigned long __stdcall CYB::Platform::System::Implementation::Thread::ThreadProc(void* const AThreadable) noexcept {
16  System::Thread::RunThread(*static_cast<API::Threadable*>(AThreadable));
17  return 0;
18 }
19 bool CYB::Platform::System::Thread::IsFinished(void) const noexcept {
20  using DWORD = Win32::DWORD;
21  return Core().FModuleManager.Call<Modules::Kernel32::WaitForSingleObject>(FThread, 0U) == WAIT_OBJECT_0;
22 }
23 
24 void CYB::Platform::System::Thread::Wait(void) const noexcept {
25  Core().FModuleManager.Call<Modules::Kernel32::WaitForSingleObject>(FThread, INFINITE);
26 }
27 
28 void CYB::Platform::System::Thread::Sleep(const unsigned int AMilliseconds) noexcept {
29  Core().FModuleManager.Call<Modules::Kernel32::Sleep>(AMilliseconds);
30 }
31 
33  Core().FModuleManager.Call<Modules::Kernel32::SwitchToThread>();
34 }
static unsigned long __stdcall ThreadProc(void *const AThreadable) noexcept
The thread startup function called by the kernel.
Platform::Modules::Manager FModuleManager
Loads and contains required modules.
Definition: CYBCore.hpp:20
Exceptions caused by external call failures or invalid external data. Only classifies ones that can p...
Definition: Exception.hpp:65
Thread(API::Threadable &AThreadable)
Construct a Thread. Once returned, the thread will be scheduled to run and BeginThreadedOperation wil...
static void RunThread(API::Threadable &AThreadable) noexcept
Properly traps and logs exceptions generated by threads. And runs AThreadable.
Definition: CYBThread.cpp:4
bool IsFinished(void) const noexcept
Check whether or not the owned thread is terminated.
The basic multithreading interface.
Definition: Threadable.hpp:6
Precompiled header for inter-engine operations.
Engine::Core & Core(void) noexcept
Retrieve the Core singleton.
Definition: CYBCore.cpp:69
static void Sleep(const unsigned int AMilliseconds) noexcept
Put the thread to sleep for at least AMilliseconds.
auto Call(AArgs &&...AArguments)
Call a loaded function.
void Wait(void) const noexcept
Blocks current thread until the owned thread has terminated.
Win32::HANDLE FThread
The thread handle.
static void Yield(void) noexcept
Expires the current threads processor time and sumbits it to the OS for rescheduling.