wip: more thread safety
[physics.git] / src / debug.cpp
index 8c13cbe..e838c8e 100644 (file)
 
 #include "debug.h"
 
-/// ***** Private Method Headers *****
-/// ***** Private Variables *****
+#include <iostream>
+using std::cerr;
+using std::cout;
+using std::endl;
+
+#include <SDL/SDL.h>
 
 /// ***** Public Methods *****
 
+SDL_mutex* muDPF = NULL;
+
 void DPF(int level, const char* pstr)
 {
-  cout << pstr << endl;
+    // lock
+    SDL_mutexP( muDPF );
+
+    cout << pstr << endl;
+
+    //unlock
+    SDL_mutexV( muDPF );
+}
+
+void debug::init()
+{
+    muDPF = SDL_CreateMutex();
+}
+
+void debug::clean()
+{
+    SDL_DestroyMutex( muDPF );
+    muDPF = NULL;
 }
 
 /// ***** Private Methods *****