system.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2015 The ClanLib 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 ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 ** Animehunter
28 */
29
30
31
32 #pragma once
33
34 #include "../System/cl_platform.h"
35 #include <vector>
36 #include <mutex>
37
38 namespace clan
39 {
42
44 class System
45 {
48
49 public:
51 static uint64_t get_time();
52
54 static uint64_t get_microseconds();
55
56 enum CPU_ExtensionX86 { mmx, mmx_ex, _3d_now, _3d_now_ex, sse, sse2, sse3, ssse3, sse4_a, sse4_1, sse4_2, xop, avx, aes, fma3, fma4 };
57 enum CPU_ExtensionPPC { altivec };
58
59 static bool detect_cpu_extension(CPU_ExtensionX86 ext);
60 static bool detect_cpu_extension(CPU_ExtensionPPC ext);
61
63 static int get_num_cores();
64
65
69
70 public:
72 static void *aligned_alloc(size_t size, size_t alignment = 16);
73
75 static void aligned_free(void *ptr);
76
78 static int capture_stack_trace(int frames_to_skip, int max_frames, void **out_frames, unsigned int *out_hash = nullptr);
79
81
82 static std::vector<std::string> get_stack_frames_text(void **frames, int num_frames);
83
88 static void sleep(int millis);
89
95 static void pause(int millis);
96
99
105 static std::string get_exe_path();
106
110
111 private:
113 };
114
115 }
116
clan::System::_3d_now
Definition: system.h:56
clan
Definition: clanapp.h:35
clan::System::sse
Definition: system.h:56
clan::System::detect_cpu_extension
static bool detect_cpu_extension(CPU_ExtensionX86 ext)
clan::System::aligned_alloc
static void * aligned_alloc(size_t size, size_t alignment=16)
Allocates aligned memory.
clan::System::CPU_ExtensionPPC
CPU_ExtensionPPC
Definition: system.h:57
clan::System::aligned_free
static void aligned_free(void *ptr)
Frees aligned memory.
clan::System::mmx_ex
Definition: system.h:56
clan::System::sleep
static void sleep(int millis)
Sleep for 'millis' milliseconds.
clan::System::fma4
Definition: system.h:56
clan::StyleTokenType::string
@ keyword
clan::System::fma3
Definition: system.h:56
clan::System::CPU_ExtensionX86
CPU_ExtensionX86
Definition: system.h:56
clan::System::get_microseconds
static uint64_t get_microseconds()
Get the current time microseconds.
clan::System::pause
static void pause(int millis)
Pause for 'millis' milliseconds.
clan::System::sse3
Definition: system.h:56
clan::System::sse4_1
Definition: system.h:56
clan::System
General system helper functions.
Definition: system.h:44
clan::System::get_stack_frames_text
static std::vector< std::string > get_stack_frames_text(void **frames, int num_frames)
Returns the function names and lines for the specified stack frame addresses.
clan::System::ssse3
Definition: system.h:56
clan::System::aes
Definition: system.h:56
clan::System::altivec
Definition: system.h:57
clan::System::mmx
Definition: system.h:56
clan::System::_3d_now_ex
Definition: system.h:56
clan::System::sse2
Definition: system.h:56
clan::System::sse4_a
Definition: system.h:56
clan::System::get_exe_path
static std::string get_exe_path()
Returns the full dirname of the executable that started this.
clan::System::capture_stack_trace
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...
clan::System::get_num_cores
static int get_num_cores()
Return the number of CPU cores.
clan::System::avx
Definition: system.h:56
clan::System::xop
Definition: system.h:56
clan::System::sse4_2
Definition: system.h:56
clan::System::get_time
static uint64_t get_time()
Get the current time (since system boot), in milliseconds.