system.h
1 /*
2 ** UICore
3 ** Copyright (c) 1997-2015 The UICore Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries UICore may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 ** Animehunter
28 */
29 
30 #pragma once
31 
32 #include <cstdint>
33 #include <vector>
34 #include <mutex>
35 
36 namespace uicore
37 {
39  class System
40  {
41  public:
43  static int64_t time();
44 
46  static int64_t microseconds();
47 
50 
51  static bool detect_cpu_extension(CPU_ExtensionX86 ext);
52  static bool detect_cpu_extension(CPU_ExtensionPPC ext);
53 
55  static int num_cores();
56 
58  static void *aligned_alloc(size_t size, size_t alignment = 16);
59 
61  static void aligned_free(void *ptr);
62 
64  static int capture_stack_trace(int frames_to_skip, int max_frames, void **out_frames, unsigned int *out_hash = nullptr);
65 
67 
68  static std::vector<std::string> stack_frames_text(void **frames, int num_frames);
69 
74  static void sleep(int millis);
75 
81  static void pause(int millis);
82 
85 
91  static std::string exe_path();
92  };
93 }
Definition: system.h:48
static bool detect_cpu_extension(CPU_ExtensionX86 ext)
Definition: system.h:48
static int num_cores()
Return the number of CPU cores.
CPU_ExtensionX86
Definition: system.h:48
Definition: system.h:48
Definition: system.h:48
static void aligned_free(void *ptr)
Frees aligned memory.
Definition: system.h:48
static std::vector< std::string > stack_frames_text(void **frames, int num_frames)
Returns the function names and lines for the specified stack frame addresses.
static void pause(int millis)
Pause for 'millis' milliseconds.
Definition: system.h:48
Definition: system.h:48
Definition: system.h:48
static void * aligned_alloc(size_t size, size_t alignment=16)
Allocates aligned memory.
Definition: system.h:48
Definition: system.h:49
Definition: system.h:48
General system helper functions.
Definition: system.h:39
static std::string exe_path()
Returns the full dirname of the executable that started this.
Definition: system.h:48
Definition: system.h:48
Definition: system.h:48
static int64_t time()
Get the current time (since system boot), in milliseconds.
static int64_t microseconds()
Get the current time microseconds.
Definition: system.h:48
static int capture_stack_trace(int frames_to_skip, int max_frames, void **out_frames, unsigned int *out_hash=nullptr)
Captures a stack back trace by walking up the stack and recording the information for each frame...
CPU_ExtensionPPC
Definition: system.h:49
Definition: system.h:48
Definition: system.h:48
static void sleep(int millis)
Sleep for 'millis' milliseconds.
Definition: Application/application.h:35