14 #ifndef DTOOLBASE_CC_H
15 #define DTOOLBASE_CC_H
27 #include "checkPandaVersion.h"
31 #define __PDT_STDBOOL_H_
42 #define ALWAYS_INLINE inline
45 #define EXPORT_TEMPLATE_CLASS(expcl, exptp, classname)
50 #define PUBLISHED __published
52 #define PHAVE_ATOMIC 1
54 typedef int ios_openmode;
55 typedef int ios_fmtflags;
56 typedef int ios_iostate;
57 typedef int ios_seekdir;
74 #include "fakestringstream.h"
85 #ifndef HAVE_IOS_TYPEDEFS
86 typedef int ios_openmode;
87 typedef int ios_fmtflags;
88 typedef int ios_iostate;
90 typedef ios::seek_dir ios_seekdir;
92 typedef std::ios::openmode ios_openmode;
93 typedef std::ios::fmtflags ios_fmtflags;
94 typedef std::ios::iostate ios_iostate;
95 typedef std::ios::seekdir ios_seekdir;
99 #define ALWAYS_INLINE __forceinline
100 #elif defined(__GNUC__)
101 #define ALWAYS_INLINE __attribute__((always_inline)) inline
103 #define ALWAYS_INLINE inline
106 #ifdef FORCE_INLINING
110 #define INLINE ALWAYS_INLINE
112 #define INLINE inline
117 #if defined(__GLIBCXX__) && __GLIBCXX__ <= 20070719
122 using std::tr1::tuple;
124 using std::tr1::copysign;
126 typedef decltype(
nullptr) nullptr_t;
128 template<class T> struct remove_reference {
typedef T type;};
129 template<
class T>
struct remove_reference<T&> {
typedef T type;};
130 template<
class T>
struct remove_reference<T&& >{
typedef T type;};
132 template<
class T>
typename remove_reference<T>::type &&move(T &&t) {
133 return static_cast<typename remove_reference<T>::type&&
>(t);
136 template<
class T>
struct owner_less;
138 typedef enum memory_order {
139 memory_order_relaxed,
140 memory_order_consume,
141 memory_order_acquire,
142 memory_order_release,
143 memory_order_acq_rel,
144 memory_order_seq_cst,
147 #define ATOMIC_FLAG_INIT { 0 }
152 atomic_flag() noexcept = default;
153 ALWAYS_INLINE constexpr atomic_flag(
bool flag) noexcept : _flag(flag) {}
154 atomic_flag(
const atomic_flag &) =
delete;
155 ~atomic_flag() noexcept = default;
156 atomic_flag &operator = (const atomic_flag&) = delete;
158 ALWAYS_INLINE
bool test_and_set(memory_order order = memory_order_seq_cst) noexcept {
159 return __atomic_test_and_set(&_flag, order);
161 ALWAYS_INLINE
void clear(memory_order order = memory_order_seq_cst) noexcept {
162 __atomic_clear(&_flag, order);
168 #define PHAVE_ATOMIC 1
172 #if defined(_MSC_VER) && _MSC_VER < 1900 // Visual Studio 2015
173 #error Microsoft Visual C++ 2015 or later is required to compile Panda3D.
177 #define MOVE(x) (std::move(x))
180 #ifndef LINK_ALL_STATIC
185 #define EXPORT_TEMPLATE_CLASS(expcl, exptp, classname) \
186 exptp template class expcl classname;
188 #define EXPORT_TEMPLATE_CLASS(expcl, exptp, classname)
194 #define PUBLISHED public
205 EXPCL_DTOOL_DTOOLBASE
extern MemoryHook *memory_hook;
209 #ifndef USE_MEMORY_NOWRAPPERS
210 #define PANDA_MALLOC_SINGLE(size) (ASSUME_ALIGNED(memory_hook->heap_alloc_single(size), MEMORY_HOOK_ALIGNMENT))
211 #define PANDA_FREE_SINGLE(ptr) memory_hook->heap_free_single(ptr)
212 #define PANDA_MALLOC_ARRAY(size) (ASSUME_ALIGNED(memory_hook->heap_alloc_array(size), MEMORY_HOOK_ALIGNMENT))
213 #define PANDA_REALLOC_ARRAY(ptr, size) (ASSUME_ALIGNED(memory_hook->heap_realloc_array(ptr, size), MEMORY_HOOK_ALIGNMENT))
214 #define PANDA_FREE_ARRAY(ptr) memory_hook->heap_free_array(ptr)
216 #define PANDA_MALLOC_SINGLE(size) ::malloc(size)
217 #define PANDA_FREE_SINGLE(ptr) ::free(ptr)
218 #define PANDA_MALLOC_ARRAY(size) ::malloc(size)
219 #define PANDA_REALLOC_ARRAY(ptr, size) ::realloc(ptr, size)
220 #define PANDA_FREE_ARRAY(ptr) ::free(ptr)
221 #endif // USE_MEMORY_NOWRAPPERS
223 #if defined(HAVE_THREADS) && defined(SIMPLE_THREADS)
226 extern EXPCL_DTOOL_DTOOLBASE void (*global_thread_yield)();
227 extern EXPCL_DTOOL_DTOOLBASE void (*global_thread_consider_yield)();
229 INLINE
void thread_yield() {
230 (*global_thread_yield)();
232 INLINE
void thread_consider_yield() {
233 (*global_thread_consider_yield)();
237 typedef struct _ts PyThreadState;
238 extern EXPCL_DTOOL_DTOOLBASE PyThreadState *(*global_thread_state_swap)(PyThreadState *tstate);
240 INLINE PyThreadState *thread_state_swap(PyThreadState *tstate) {
241 return (*global_thread_state_swap)(tstate);
243 #endif // HAVE_PYTHON
247 INLINE
void thread_yield() {
249 INLINE
void thread_consider_yield() {
252 #endif // HAVE_THREADS && SIMPLE_THREADS
254 #if defined(USE_TAU) && defined(WIN32)
256 extern EXPCL_DTOOL_DTOOLBASE
bool __tau_shutdown;
257 class EXPCL_DTOOL_DTOOLBASE TauProfile {
259 TauProfile(
void *&tautimer,
char *name,
char *type,
int group,
char *group_name) {
260 Tau_profile_c_timer(&tautimer, name, type, group, group_name);
261 _tautimer = tautimer;
262 TAU_PROFILE_START(_tautimer);
265 if (!__tau_shutdown) {
266 TAU_PROFILE_STOP(_tautimer);
275 #define TAU_PROFILE(name, type, group) \
276 static void *__tautimer; \
277 TauProfile __taupr(__tautimer, name, type, group, #group)
279 #undef TAU_PROFILE_EXIT
280 #define TAU_PROFILE_EXIT(msg) \
281 __tau_shutdown = true; \
286 #endif // __cplusplus