changeset 6321:c254cb1c26ef

new (cleaner, nore robust) critsect code by Zdenek Kabelac <kabi@informatics.muni.cz>
author arpi
date Fri, 07 Jun 2002 00:55:55 +0000
parents 12136df07dbd
children 91d14f75fcef
files loader/win32.c
diffstat 1 files changed, 12 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/loader/win32.c	Fri Jun 07 00:42:08 2002 +0000
+++ b/loader/win32.c	Fri Jun 07 00:55:55 2002 +0000
@@ -335,6 +335,7 @@
     pthread_t id;
     pthread_mutex_t mutex;
     int locked;
+    long deadbeef;
 };
 
 void* mreq_private(int size, int to_zero, int type);
@@ -1232,10 +1233,12 @@
     }
 #else
     {
-	struct CRITSECT* cs = mreq_private(sizeof(struct CRITSECT), 0, AREATYPE_CRITSECT);
+	struct CRITSECT* cs = mreq_private(sizeof(struct CRITSECT) + sizeof(CRITICAL_SECTION),
+					   0, AREATYPE_CRITSECT);
 	pthread_mutex_init(&cs->mutex, NULL);
 	cs->locked=0;
-	*(void**)c = cs;
+        cs->deadbeef = 0xdeadbeef;
+	*(void**)c = cs + 1;
     }
 #endif
     return;
@@ -1246,9 +1249,10 @@
 #ifdef CRITSECS_NEWTYPE
     struct CRITSECT* cs = critsecs_get_unix(c);
 #else
-    struct CRITSECT* cs=*(struct CRITSECT**)c;
+    struct CRITSECT* cs = (*(struct CRITSECT**)c) - 1;
+
 #endif
-    dbgprintf("EnterCriticalSection(0x%x)\n",c);
+    dbgprintf("EnterCriticalSection(0x%x) %p maso:0x%x\n",c, cs, cs->deadbeef);
     if (!cs)
     {
 	dbgprintf("entered uninitialized critisec!\n");
@@ -1256,7 +1260,7 @@
 #ifdef CRITSECS_NEWTYPE
 	cs=critsecs_get_unix(c);
 #else
-	cs=*(struct CRITSECT**)c;
+	cs = (*(struct CRITSECT**)c) - 1;
 #endif
 	printf("Win32 Warning: Accessed uninitialized Critical Section (%p)!\n", c);
     }
@@ -1273,10 +1277,10 @@
 #ifdef CRITSECS_NEWTYPE
     struct CRITSECT* cs = critsecs_get_unix(c);
 #else
-    struct CRITSECT* cs=*(struct CRITSECT**)c;
+    struct CRITSECT* cs = (*(struct CRITSECT**)c) - 1;
 #endif
     //    struct CRITSECT* cs=(struct CRITSECT*)c;
-    dbgprintf("LeaveCriticalSection(0x%x)\n",c);
+    dbgprintf("LeaveCriticalSection(0x%x) 0x%x\n",c, cs->deadbeef);
     if (!cs)
     {
 	printf("Win32 Warning: Leaving uninitialized Critical Section %p!!\n", c);
@@ -1291,7 +1295,7 @@
 #ifdef CRITSECS_NEWTYPE
     struct CRITSECT* cs = critsecs_get_unix(c);
 #else
-    struct CRITSECT* cs=*(struct CRITSECT**)c;
+    struct CRITSECT* cs= (*(struct CRITSECT**)c) - 1;
 #endif
     //    struct CRITSECT* cs=(struct CRITSECT*)c;
     dbgprintf("DeleteCriticalSection(0x%x)\n",c);