SuperTuxKart
Loading...
Searching...
No Matches
vs.hpp
1// SuperTuxKart - a fun racing game with go-kart
2// Copyright (C) 2014-2015 SuperTuxKart-Team
3//
4// This program is free software; you can redistribute it and/or
5// modify it under the terms of the GNU General Public License
6// as published by the Free Software Foundation; either version 3
7// of the License, or (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program; if not, write to the Free Software
16// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18
19#ifndef HEADER_VS_HPP
20#define HEADER_VS_HPP
26#if defined(WIN32) && defined(_MSC_VER) && _MSC_VER < 1800
27# include <math.h>
28
29# define roundf(x) (floorf(x + 0.5f))
30# define round(x) (floorf(x + 0.5))
31#endif
32
33#ifdef __MINGW32__
34 #include <cmath>
35 using std::isnan;
36#endif
37
38#if defined(WIN32) && defined(DEBUG)
39# define WIN32_LEAN_AND_MEAN
40# include <windows.h>
41#endif
42
43#if (defined(__linux__) && defined(__GLIBC__) && defined(__GLIBC_MINOR__)) || defined(__NetBSD__) || defined(__APPLE__) || defined(__sun)
44# include <pthread.h>
45#endif
46
47#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__OpenBSD__)
48# include <pthread.h>
49# include <pthread_np.h>
50#endif
51
52#if defined(__HAIKU__)
53# include <kernel/scheduler.h>
54#endif
55
56namespace VS
57{
58#if defined(_MSC_VER) && defined(DEBUG)
59# define WIN32_LEAN_AND_MEAN
60# include <windows.h>
61
65 static void setThreadName(const char *name)
66 {
67 const DWORD MS_VC_EXCEPTION=0x406D1388;
68#pragma pack(push,8)
69 typedef struct tagTHREADNAME_INFO
70 {
71 DWORD dwType; // Must be 0x1000.
72 LPCSTR szName; // Pointer to name (in user addr space).
73 DWORD dwThreadID; // Thread ID (-1=caller thread).
74 DWORD dwFlags; // Reserved for future use, must be zero.
75 } THREADNAME_INFO;
76#pragma pack(pop)
77
78 THREADNAME_INFO info;
79 info.dwType = 0x1000;
80 info.szName = name;
81 info.dwThreadID = -1;
82 info.dwFlags = 0;
83
84 __try
85 {
86 RaiseException( MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR),
87 (ULONG_PTR*)&info );
88 }
89 __except(EXCEPTION_EXECUTE_HANDLER)
90 {
91 }
92
93 } // setThreadName
94#else
95 static void setThreadName(const char* name)
96 {
97#if defined(__linux__) && defined(__GLIBC__) && defined(__GLIBC_MINOR__)
98#if __GLIBC__ > 2 || __GLIBC_MINOR__ > 11 || defined(__sun)
99 pthread_setname_np(pthread_self(), name);
100#endif
101#elif defined(__FreeBSD__) || defined(__DragonFly__)
102 pthread_set_name_np(pthread_self(), name);
103#elif defined(__NetBSD__)
104 pthread_setname_np(pthread_self(), "%s", const_cast<char *>(name));
105#elif defined(__OpenBSD__)
106 pthread_set_name_np(pthread_self(), const_cast<char *>(name));
107#elif defined(__APPLE__)
108 pthread_setname_np(name);
109#elif defined(__HAIKU__)
110 rename_thread(find_thread(nullptr), name);
111#endif
112 } // setThreadName
113#endif
114
115} // namespace VS
116
117#endif // HEADER_VS_HPP
Visual studio workarounds in one place Note that Visual Studio 2013 does have the maths functions def...
Definition: vs.hpp:57