ClanLib  2.3.7
system.h
Go to the documentation of this file.
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2011 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 
32 
33 
34 #pragma once
35 
36 
37 #include "../api_core.h"
38 #include "../Text/string_types.h"
39 #include "../System/cl_platform.h"
40 #include <vector>
41 
45 {
46  int dummy;
47 };
48 
49 class CL_Mutex;
50 
55 {
58 
59 public:
61  static unsigned int get_time();
62 
64  static cl_ubyte64 get_microseconds();
65 
66  enum CL_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 };
67  enum CL_CPU_ExtensionPPC { altivec };
68 
69  static bool detect_cpu_extension(CL_CPU_ExtensionX86 ext);
70  static bool detect_cpu_extension(CL_CPU_ExtensionPPC ext);
71 
73  static CL_Mutex *get_sharedptr_mutex();
74 
76  static int get_num_cores();
77 
78 
82 
83 public:
85  static void *aligned_alloc(size_t size, size_t alignment = 16);
86 
88  static void aligned_free(void *ptr);
89 
91  static int capture_stack_trace(int frames_to_skip, int max_frames, void **out_frames, unsigned int *out_hash = 0);
92 
94 
95  static std::vector<CL_String> get_stack_frames_text(void **frames, int num_frames);
96 
101  static void sleep(int millis);
102 
108  static void pause(int millis);
109 
112 
118  static CL_String get_exe_path();
119 
121  template<typename T>
122  static void call_constructor(T *memory)
123  {
124  new ((CL_PreallocatedMemory *) memory) T;
125  }
126 
127  template<typename T, typename P1>
128  static void call_constructor(T *memory, P1 p1)
129  {
130  new ((CL_PreallocatedMemory *) memory) T(p1);
131  }
132 
133  template<typename T, typename P1, typename P2>
134  static void call_constructor(T *memory, P1 p1, P2 p2)
135  {
136  new ((CL_PreallocatedMemory *) memory) T(p1, p2);
137  }
138 
139  template<typename T, typename P1, typename P2, typename P3>
140  static void call_constructor(T *memory, P1 p1, P2 p2, P3 p3)
141  {
142  new ((CL_PreallocatedMemory *) memory) T(p1, p2, p3);
143  }
144 
145  template<typename T, typename P1, typename P2, typename P3, typename P4>
146  static void call_constructor(T *memory, P1 p1, P2 p2, P3 p3, P4 p4)
147  {
148  new ((CL_PreallocatedMemory *) memory) T(p1, p2, p3, p4);
149  }
150 
151  template<typename T, typename P1, typename P2, typename P3, typename P4, typename P5>
152  static void call_constructor(T *memory, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5)
153  {
154  new ((CL_PreallocatedMemory *) memory) T(p1, p2, p3, p4, p5);
155  }
156 
157  template<typename T, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
158  static void call_constructor(T *memory, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6)
159  {
160  new ((CL_PreallocatedMemory *) memory) T(p1, p2, p3, p4, p5, p6);
161  }
162 
163  template<typename T, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
164  static void call_constructor(T *memory, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7)
165  {
166  new ((CL_PreallocatedMemory *) memory) T(p1, p2, p3, p4, p5, p6, p7);
167  }
168 
170  template<typename T>
171  static void call_destructor(T *memory)
172  {
173  memory->~T();
174  }
175 
176 
180 
181 private:
183 };
184 
185