Panda3D

Loading...
Searching...
No Matches
dtoolbase.cxx
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file dtoolbase.cxx
10 * @author drose
11 * @date 2000-09-12
12 */
13
14#include "dtoolbase.h"
15#include "memoryHook.h"
16
17#if !defined(CPPPARSER) && !defined(LINK_ALL_STATIC) && !defined(BUILDING_DTOOL_DTOOLBASE)
18 #error Buildsystem error: BUILDING_DTOOL_DTOOLBASE not defined
19#endif
20
21#if defined(USE_TAU) && defined(WIN32)
22// Hack around tau's lack of DLL export declarations for Profiler class.
23 bool __tau_shutdown = false;
24#endif
25
26 MemoryHook *memory_hook;
27
28/**
29 * Any code that might need to use PANDA_MALLOC or PANDA_FREE, or any methods
30 * of the global memory_hook object, at static init time, should ensure that
31 * it calls init_memory_hook() first to ensure that the pointer has been
32 * properly initialized. There is no harm in calling this function more than
33 * once.
34 *
35 * There is no need to call this function other than at static init time.
36 */
37 void
38 init_memory_hook() {
39 if (memory_hook == nullptr) {
40 memory_hook = new MemoryHook;
41 }
42}
43
44// Here's a quick way to ensure the above function is called at least once at
45// static init time.
46 class InitMemoryHook {
47 public:
48 InitMemoryHook() {
49 init_memory_hook();
50 }
51};
52 static InitMemoryHook _imh_object;
53
54#if defined(HAVE_THREADS) && defined(SIMPLE_THREADS)
55
56 static void
57default_thread_yield() {
58}
59 static void
60default_thread_consider_yield() {
61}
62void (*global_thread_yield)() = default_thread_yield;
63void (*global_thread_consider_yield)() = default_thread_consider_yield;
64
65#ifdef HAVE_PYTHON
66 static PyThreadState *
67default_thread_state_swap(PyThreadState *state) {
68 return nullptr;
69}
70PyThreadState *(*global_thread_state_swap)(PyThreadState *tstate) = default_thread_state_swap;
71#endif // HAVE_PYTHON
72
73#endif // HAVE_THREADS && SIMPLE_THREADS
MemoryHook
This class provides a wrapper around the various possible malloc schemes Panda might employ.
Definition memoryHook.h:37
init_memory_hook
void init_memory_hook()
Any code that might need to use PANDA_MALLOC or PANDA_FREE, or any methods of the global memory_hook ...
Definition dtoolbase.cxx:38
dtoolbase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
memoryHook.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.