more guardedalloc use in C++, also make compositorMutex a static var, was allocated...
authorCampbell Barton <ideasman42@gmail.com>
Mon, 25 Jun 2012 10:35:24 +0000 (10:35 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 25 Jun 2012 10:35:24 +0000 (10:35 +0000)
18 files changed:
CMakeLists.txt
intern/ghost/GHOST_ISystem.h
intern/ghost/GHOST_ISystemPaths.h
intern/ghost/GHOST_ITimerTask.h
intern/ghost/GHOST_Types.h
intern/ghost/intern/GHOST_CallbackEventConsumer.h
intern/ghost/intern/GHOST_DisplayManager.h
intern/ghost/intern/GHOST_EventManager.h
intern/ghost/intern/GHOST_SystemPaths.h
intern/ghost/intern/GHOST_TimerManager.h
intern/guardedalloc/cpp/mallocn.cpp
source/blender/compositor/intern/COM_ChunkOrderHotspot.h
source/blender/compositor/intern/COM_ExecutionSystem.cpp
source/blender/compositor/intern/COM_NodeOperation.h
source/blender/compositor/intern/COM_Socket.h
source/blender/compositor/intern/COM_SocketReader.h
source/blender/compositor/intern/COM_compositor.cpp
source/gameengine/Expressions/PyObjectPlus.h

index f3614007ef98b4fb3aae19a77d9e822ad47410d7..0fb635d45d58dc95145bb660e4b632549d434331 100644 (file)
@@ -1723,6 +1723,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PLATFORM_CFLAGS} ${CXX_WARNINGS}")
 # better not set includes here but this debugging option is off by default.
 if(WITH_CXX_GUARDEDALLOC)
        include_directories(${CMAKE_SOURCE_DIR}/intern/guardedalloc)
+       add_definitions(-DWITH_CXX_GUARDEDALLOC)
 endif()
 
 if(WITH_ASSERT_ABORT)
index bd4f3aed5aae7914816f186fd5e7b0e26f1e301a..0bc09077f391735a3eb496b2a6980aa4367509de 100644 (file)
@@ -415,14 +415,9 @@ protected:
        /** The one and only system */
        static GHOST_ISystem *m_system;
 
+
 #ifdef WITH_CXX_GUARDEDALLOC
-public:
-       void *operator new(size_t num_bytes) {
-               return MEM_mallocN(num_bytes, "GHOST:GHOST_ISystem");
-       }
-       void operator delete(void *mem) {
-               MEM_freeN(mem);
-       }
+       MEM_CXX_CLASS_ALLOC_FUNCS("GHOST:GHOST_ISystem")
 #endif
 };
 
index ee8bd9d1edaf4401ef86baeacec4669d11790b98..1ba4ceaaabaf683cccd9b44f5250bd1a2c772d5d 100644 (file)
@@ -98,6 +98,11 @@ public:
 private:
        /** The one and only system paths*/
        static GHOST_ISystemPaths *m_systemPaths;
+
+
+#ifdef WITH_CXX_GUARDEDALLOC
+       MEM_CXX_CLASS_ALLOC_FUNCS("GHOST:GHOST_ISystemPaths")
+#endif
 };
 
 #endif
index bb4a81be5f84aa659be20d5174dfeb95ed4a706f..08c4890939fc4e7009a3671d80bf47252d4c6c01 100644 (file)
@@ -84,14 +84,9 @@ public:
         */
        virtual void setUserData(const GHOST_TUserDataPtr userData) = 0;
 
+
 #ifdef WITH_CXX_GUARDEDALLOC
-public:
-       void *operator new(size_t num_bytes) {
-               return MEM_mallocN(num_bytes, "GHOST:GHOST_ITimerTask");
-       }
-       void operator delete(void *mem) {
-               MEM_freeN(mem);
-       }
+       MEM_CXX_CLASS_ALLOC_FUNCS("GHOST:GHOST_ITimerTask")
 #endif
 };
 
index 8454f338645fca58ab3693901f8f7f1f15d29d6a..4921acde6707cc73317b52f112152472ef285538 100644 (file)
 #include "MEM_guardedalloc.h"
 #endif
 
-#define GHOST_DECLARE_HANDLE(name) typedef struct name##__ { int unused; } *name
+#if defined(WITH_CXX_GUARDEDALLOC) && defined(__cplusplus)
+#  define GHOST_DECLARE_HANDLE(name) typedef struct name##__ { int unused; MEM_CXX_CLASS_ALLOC_FUNCS(#name) } *name
+#else
+#  define GHOST_DECLARE_HANDLE(name) typedef struct name##__ { int unused; } *name
+#endif
 
 typedef char GHOST_TInt8;
 typedef unsigned char GHOST_TUns8;
index 61aef742a48aa8eaf810b69d1afc4601549a90c4..e13a56c38f4ba314d42add98944e9c9cd8b56dd1 100644 (file)
@@ -73,6 +73,10 @@ protected:
        GHOST_EventCallbackProcPtr m_eventCallback;
        /** The data passed back though the call-back routine. */
        GHOST_TUserDataPtr m_userData;
+
+#ifdef WITH_CXX_GUARDEDALLOC
+       MEM_CXX_CLASS_ALLOC_FUNCS("GHOST:GHOST_CallbackEventConsumer")
+#endif
 };
 
 #endif // __GHOST_CALLBACKEVENTCONSUMER_H__
index 3e867054d019e2e818ec4b7cad8f9ac8cc352d5b..7893f0936b323bf5002ebb4826e1cf2759b35f39 100644 (file)
@@ -133,6 +133,11 @@ protected:
        bool m_settingsInitialized;
        /** The list with display settings for the main display. */
        std::vector<GHOST_DisplaySettings> m_settings;
+
+
+#ifdef WITH_CXX_GUARDEDALLOC
+       MEM_CXX_CLASS_ALLOC_FUNCS("GHOST:GHOST_DisplayManager")
+#endif
 };
 
 
index f941dac9fb463f03041e873bf3e032e8279da9d9..eec00789800cc4b0ea5c877e951b051dad484354 100644 (file)
@@ -168,6 +168,11 @@ protected:
 
        /** The list with event consumers. */
        TConsumerVector m_consumers;
+
+
+#ifdef WITH_CXX_GUARDEDALLOC
+       MEM_CXX_CLASS_ALLOC_FUNCS("GHOST:GHOST_EventManager")
+#endif
 };
 
 #endif // __GHOST_EVENTMANAGER_H__
index 75acbf885e3a650adb8a2c08748d358ced6ea9a7..f53d4f4a7b77fc5a6ac6c8027856888d28605a8e 100644 (file)
@@ -57,7 +57,7 @@ public:
         */
        virtual const GHOST_TUns8 *getSystemDir(int version, const char *versionstr) const = 0;
 
-    /**
+       /**
          * Determine the base dir in which user configuration is stored, including versioning.
          * If needed, it will create the base directory.
          * @return Unsigned char string pointing to user dir (eg ~/.blender/).
@@ -74,7 +74,6 @@ public:
         * Add the file to the operating system most recently used files
         */
        virtual void addToSystemRecentFiles(const char *filename) const = 0;
-
 };
 
 #endif
index 0b189cf3aa913b8c612e7f600418934e20aa14d5..88d27088c1ded414bb2027d65e6657818f0a7557 100644 (file)
@@ -119,6 +119,11 @@ protected:
        typedef std::vector<GHOST_TimerTask *> TTimerVector;
        /** The list with event consumers. */
        TTimerVector m_timers;
+
+
+#ifdef WITH_CXX_GUARDEDALLOC
+       MEM_CXX_CLASS_ALLOC_FUNCS("GHOST:GHOST_TimerManager")
+#endif
 };
 
 #endif // __GHOST_TIMERMANAGER_H__
index 130fcb6960bd5a62d27fac4caabba093284066ac..21f5e323cf271918406c0d858f56b8fd5556de0f 100644 (file)
 #include <new>
 #include "../MEM_guardedalloc.h"
 
-void* operator new (size_t size)
+/* not default but can be used when needing to set a string */
+void *operator new(size_t size, const char *str)
 {
-       return MEM_mallocN(size, "C++/anonymous");
+       return MEM_mallocN(size, str);
 }
-
-/* not default but can be used when needing to set a string */
-void* operator new (size_t size, const char *str)
+void *operator new[](size_t size, const char *str)
 {
        return MEM_mallocN(size, str);
 }
 
-void operator delete (void *p)
+
+void *operator new(size_t size)
+{
+       return MEM_mallocN(size, "C++/anonymous");
+}
+void *operator new[](size_t size)
+{
+       return MEM_mallocN(size, "C++/anonymous[]");
+}
+
+
+void operator delete(void *p)
+{
+       /* delete NULL is valid in c++ */
+       if (p)
+               MEM_freeN(p);
+}
+void operator delete[](void *p)
 {
        /* delete NULL is valid in c++ */
-       if(p)
+       if (p)
                MEM_freeN(p);
 }
index ceb5934a7dfa626687364fa31725f308036ae034..68140745f8b900616b6df9f1cfda958b2ba544df 100644 (file)
 #ifndef _COM_ChunkOrderHotSpot_h_
 #define _COM_ChunkOrderHotSpot_h_
 
+#ifdef WITH_CXX_GUARDEDALLOC
+#include "MEM_guardedalloc.h"
+#endif
+
 class ChunkOrderHotspot {
 private:
        int x;
@@ -32,6 +36,11 @@ private:
 public:
        ChunkOrderHotspot(int x, int y, float addition);
        double determineDistance(int x, int y);
+
+
+#ifdef WITH_CXX_GUARDEDALLOC
+       MEM_CXX_CLASS_ALLOC_FUNCS("COM:ChunkOrderHotspot")
+#endif
 };
 
 #endif
index 7e09486fd0bc57cf3eb11246cb2ed1c5ba4b13d2..5001cabbd9f4094ecef8983cc9385b525393db06 100644 (file)
 
 #include "BKE_global.h"
 
+#ifdef WITH_CXX_GUARDEDALLOC
+#include "MEM_guardedalloc.h"
+#endif
+
 ExecutionSystem::ExecutionSystem(RenderData *rd, bNodeTree *editingtree, bool rendering)
 {
        context.setbNodeTree(editingtree);
index f96b994685a4fa78c4c16f3cb5f3ee5d6220f88f..bf2dbd8c9c0a723499883756a471391351d9fdf4 100644 (file)
@@ -270,6 +270,10 @@ protected:
         * @brief set if this NodeOperation can be scheduled on a OpenCLDevice
         */
        void setOpenCL(bool openCL) { this->openCL = openCL; }
+
+#ifdef WITH_CXX_GUARDEDALLOC
+       MEM_CXX_CLASS_ALLOC_FUNCS("COM:NodeOperation")
+#endif
 };
 
 #endif
index 4f82a490e1473b17307fdc5ea6c830a2c8e00de2..9feef1bae939d370174a1865be850f8e520b7878 100644 (file)
 #include "DNA_node_types.h"
 #include "COM_defines.h"
 
+#ifdef WITH_CXX_GUARDEDALLOC
+#include "MEM_guardedalloc.h"
+#endif
+
 using namespace std;
 class SocketConnection;
 class NodeBase;
index f4f58e6e00769a86ef3acf5b86780a62573eef19..df8899e8eeabf740a7b7dbfa0b84befe53c43fe0 100644 (file)
 #include "BLI_rect.h"
 #include "COM_defines.h"
 
+#ifdef WITH_CXX_GUARDEDALLOC
+#include "MEM_guardedalloc.h"
+#endif
+
 typedef enum PixelSampler {
        COM_PS_NEAREST,
        COM_PS_BILINEAR,
index bec9ff95eed209df7a1d6a4400d4e5e7136ee934..ccd3b2e6458defa48406d85e74341b6d078c3864 100644 (file)
@@ -33,20 +33,21 @@ extern "C" {
 #include "COM_WorkScheduler.h"
 #include "OCL_opencl.h"
 
-static ThreadMutex *compositorMutex;
+static ThreadMutex compositorMutex = {{0}};
+static char is_compositorMutex_init = FALSE;
 void COM_execute(RenderData *rd, bNodeTree *editingtree, int rendering)
 {
-       if (compositorMutex == NULL) { /// TODO: move to blender startup phase
-               compositorMutex = new ThreadMutex();
-               BLI_mutex_init(compositorMutex);
+       if (is_compositorMutex_init == FALSE) { /// TODO: move to blender startup phase
+               BLI_mutex_init(&compositorMutex);
                OCL_init();
                WorkScheduler::initialize(); ///TODO: call workscheduler.deinitialize somewhere
+               is_compositorMutex_init = TRUE;
        }
-       BLI_mutex_lock(compositorMutex);
+       BLI_mutex_lock(&compositorMutex);
        if (editingtree->test_break(editingtree->tbh)) {
                // during editing multiple calls to this method can be triggered.
                // make sure one the last one will be doing the work.
-               BLI_mutex_unlock(compositorMutex);
+               BLI_mutex_unlock(&compositorMutex);
                return;
 
        }
@@ -60,5 +61,5 @@ void COM_execute(RenderData *rd, bNodeTree *editingtree, int rendering)
        system->execute();
        delete system;
 
-       BLI_mutex_unlock(compositorMutex);
+       BLI_mutex_unlock(&compositorMutex);
 }
index af8acaa993f04c93a3309b3f8d6bc65a26ae6d1d..2fee6aaab92536552ac802f9903c0aa2a4020a45 100644 (file)
@@ -166,7 +166,7 @@ public:                                                                       \
        void *operator new(size_t num_bytes) {                                    \
                return MEM_mallocN(num_bytes, Type.tp_name);                          \
        }                                                                         \
-       void operator delete( void *mem ) {                                       \
+       void operator delete(void *mem) {                                         \
                MEM_freeN(mem);                                                       \
        }                                                                         \