فهرست منبع

DebugObject: BADVPN_THREAD_SAFE should be checked with if not ifdef. Also add check to make sure it's defined.

ambrop7 13 سال پیش
والد
کامیت
8f6285a281
2فایلهای تغییر یافته به همراه11 افزوده شده و 7 حذف شده
  1. 1 1
      base/DebugObject.c
  2. 10 6
      base/DebugObject.h

+ 1 - 1
base/DebugObject.c

@@ -32,7 +32,7 @@
 #ifndef BADVPN_PLUGIN
 #ifndef NDEBUG
 DebugCounter debugobject_counter = DEBUGCOUNTER_STATIC;
-#ifdef BADVPN_THREAD_SAFE
+#if BADVPN_THREAD_SAFE
 pthread_mutex_t debugobject_mutex = PTHREAD_MUTEX_INITIALIZER;
 #endif
 #endif

+ 10 - 6
base/DebugObject.h

@@ -36,7 +36,11 @@
 
 #include <stdint.h>
 
-#ifdef BADVPN_THREAD_SAFE
+#if !defined(BADVPN_THREAD_SAFE) || (BADVPN_THREAD_SAFE != 0 && BADVPN_THREAD_SAFE != 1)
+#error BADVPN_THREAD_SAFE is not defined or incorrect
+#endif
+
+#if BADVPN_THREAD_SAFE
 #include <pthread.h>
 #endif
 
@@ -83,7 +87,7 @@ static void DebugObjectGlobal_Finish (void);
 
 #ifndef NDEBUG
 extern DebugCounter debugobject_counter;
-#ifdef BADVPN_THREAD_SAFE
+#if BADVPN_THREAD_SAFE
 extern pthread_mutex_t debugobject_mutex;
 #endif
 #endif
@@ -94,13 +98,13 @@ void DebugObject_Init (DebugObject *obj)
     
     obj->c = DEBUGOBJECT_VALID;
     
-    #ifdef BADVPN_THREAD_SAFE
+    #if BADVPN_THREAD_SAFE
     ASSERT_FORCE(pthread_mutex_lock(&debugobject_mutex) == 0)
     #endif
     
     DebugCounter_Increment(&debugobject_counter);
     
-    #ifdef BADVPN_THREAD_SAFE
+    #if BADVPN_THREAD_SAFE
     ASSERT_FORCE(pthread_mutex_unlock(&debugobject_mutex) == 0)
     #endif
     
@@ -115,13 +119,13 @@ void DebugObject_Free (DebugObject *obj)
     
     obj->c = 0;
     
-    #ifdef BADVPN_THREAD_SAFE
+    #if BADVPN_THREAD_SAFE
     ASSERT_FORCE(pthread_mutex_lock(&debugobject_mutex) == 0)
     #endif
     
     DebugCounter_Decrement(&debugobject_counter);
     
-    #ifdef BADVPN_THREAD_SAFE
+    #if BADVPN_THREAD_SAFE
     ASSERT_FORCE(pthread_mutex_unlock(&debugobject_mutex) == 0)
     #endif