Gaia-ECS v1.0.0
A simple and powerful entity component system
Loading...
Searching...
No Matches
win32.h
1#pragma once
2
3#include "gaia/config/config.h"
4
5#if GAIA_PLATFORM_WINDOWS
6
7 #include <cstdint>
8
10// The Win32 API Gaia calls, without <windows.h>. Including <windows.h> from a public header would
11// leak its macros (near, far, small, min, max, ERROR, CreateWindow, ...) into every translation unit
12// of the program. Each function is declared exactly as the Windows SDK declares it, so programs
13// may still include <windows.h> before or after Gaia.
14struct _SECURITY_ATTRIBUTES;
15struct HINSTANCE__;
16
17extern "C" {
18__declspec(dllimport) void* __stdcall CreateSemaphoreExW(
19 _SECURITY_ATTRIBUTES* lpSemaphoreAttributes, long lInitialCount, long lMaximumCount, const wchar_t* lpName,
20 unsigned long dwFlags, unsigned long dwDesiredAccess);
21__declspec(dllimport) int __stdcall ReleaseSemaphore(void* hSemaphore, long lReleaseCount, long* lpPreviousCount);
22__declspec(dllimport) unsigned long __stdcall WaitForSingleObject(void* hHandle, unsigned long dwMilliseconds);
23__declspec(dllimport) int __stdcall CloseHandle(void* hObject);
24__declspec(dllimport) HINSTANCE__* __stdcall GetModuleHandleA(const char* lpModuleName);
25__declspec(dllimport) intptr_t(__stdcall* __stdcall GetProcAddress(HINSTANCE__* hModule, const char* lpProcName))();
26}
28
29namespace gaia {
30 namespace mt {
31 namespace win32 {
33 inline constexpr unsigned long SemaphoreAllAccess = 0x1F0003UL;
35 inline constexpr unsigned long Infinite = 0xFFFFFFFFUL;
37 inline constexpr unsigned long WaitObject0 = 0UL;
38
40 inline constexpr int RelationProcessorCore = 0;
43 inline constexpr uint32_t ProcessorInfoEfficiencyClassOffset = 9;
44
46 inline constexpr int ThreadPowerThrottling = 3;
48 inline constexpr unsigned long ThreadPowerThrottlingCurrentVersion = 1UL;
50 inline constexpr unsigned long ThreadPowerThrottlingExecutionSpeed = 0x1UL;
51
53 struct ThreadPowerThrottlingState {
54 unsigned long Version;
55 unsigned long ControlMask;
56 unsigned long StateMask;
57 };
58
60 using GetLogicalProcessorInformationExFunc = int(__stdcall*)(int, void*, unsigned long*);
62 using SetThreadInformationFunc = int(__stdcall*)(void*, int, void*, unsigned long);
64 using SetThreadDescriptionFunc = long(__stdcall*)(void*, const wchar_t*);
65
72 template <typename Func>
73 inline Func kernel32_func(const char* name) {
74 HINSTANCE__* module = ::GetModuleHandleA("kernel32.dll");
75 if (module == nullptr)
76 return nullptr;
77 return reinterpret_cast<Func>(reinterpret_cast<void*>(::GetProcAddress(module, name)));
78 }
79 } // namespace win32
80 } // namespace mt
81} // namespace gaia
82
83#endif