Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
PlatformDefinesUnix.cpp
Go to the documentation of this file.
1
2
3#if !defined(_WIN32) && !defined(__APPLE_CC__)
4
6
7#include <SDL2/SDL_syswm.h>
8#include <malloc.h>
9#include <unistd.h>
10#include <signal.h>
11
12int _vscprintf (const char * format, va_list pargs) {
13 int retval;
14 va_list argcopy;
15 va_copy(argcopy, pargs);
16 retval = vsnprintf(NULL, 0, format, argcopy);
17 va_end(argcopy);
18 return retval;
19}
20
21namespace Divide {
22
23 bool DebugBreak(const bool condition) noexcept {
24 if (!condition) {
25 return false;
26 }
27#if defined(SIGTRAP)
28 raise(SIGTRAP);
29#else
30 raise(SIGABRT);
31#endif
32 return true;
33 }
34
35 void EnforceDPIScaling() noexcept
36 {
37 NOP();
38 }
39
41 long pages = sysconf(_SC_PHYS_PAGES);
42 long page_size = sysconf(_SC_PAGESIZE);
43 info._availableRamInBytes = pages * page_size;
44 return true;
45 }
46
48 return 96.f;
49 }
50
51 void GetWindowHandle(void* window, WindowHandle& handleOut) noexcept {
52 SDL_SysWMinfo wmInfo;
53 SDL_VERSION(&wmInfo.version);
54 SDL_GetWindowWMInfo(static_cast<SDL_Window*>(window), &wmInfo);
55
56 handleOut._handle = wmInfo.info.x11.window;
57 }
58
59 void SetThreadPriorityInternal(pthread_t thread, const ThreadPriority priority) {
60 if (priority == ThreadPriority::COUNT) {
61 return;
62 }
63 sched_param sch_params;
64 int policy;
65 pthread_getschedparam(thread, &policy, &sch_params);
66
67 switch (priority) {
68 default:
70 sch_params.sched_priority = 10;
71 } break;
73 sch_params.sched_priority = 25;
74 } break;
76 sch_params.sched_priority = 50;
77 } break;
79 sch_params.sched_priority = 75;
80 } break;
82 sch_params.sched_priority = 85;
83 } break;
85 sch_params.sched_priority = 99;
86 } break;
87 }
88
89 if (!pthread_setschedparam(thread, SCHED_FIFO, &sch_params)) {
91 }
92 }
93
94 void SetThreadPriority(const ThreadPriority priority)
95 {
96 SetThreadPriorityInternal(pthread_self(), priority);
97 }
98
99 #include <sys/prctl.h>
100 void SetThreadName(const std::string_view threadName) noexcept
101 {
102 pthread_setname_np(pthread_self(), threadName.data());
103 }
104
105 bool CallSystemCmd(const std::string_view cmd, const std::string_view args)
106 {
107 return std::system(Util::StringFormat("{} {}", cmd, args).c_str()) == 0;
108 }
109
110}; //namespace Divide
111
112#endif //defined(_UNIX)
SDL_Window SDL_Window
Definition: DisplayWindow.h:42
#define DIVIDE_UNEXPECTED_CALL()
#define NOP()
int _vscprintf(const char *format, va_list pargs)
Str StringFormat(const char *fmt, Args &&...args)
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
void GetWindowHandle(void *window, WindowHandle &handleOut) noexcept
F32 PlatformDefaultDPI() noexcept
void SetThreadName(std::string_view threadName) noexcept
bool CallSystemCmd(std::string_view cmd, std::string_view args)
void SetThreadPriorityInternal(pthread_t thread, const ThreadPriority priority)
bool DebugBreak(const bool condition) noexcept
void SetThreadPriority(ThreadPriority priority)
void EnforceDPIScaling() noexcept
bool GetAvailableMemory(SysInfo &info)
size_t _availableRamInBytes