[MPlayer-dev-eng] [PATCH] Support CineForm DirectShow codec

Reimar Döffinger Reimar.Doeffinger at gmx.de
Tue Feb 9 19:07:26 CET 2010


On Thu, Jan 14, 2010 at 05:08:09PM +0100, Steinar H. Gunderson wrote:
> On Sun, Jan 10, 2010 at 05:00:44PM +0100, Steinar H. Gunderson wrote:
> > The other critical section changes require a bit more explanation. Let me try
> > to explain what's going on.
> 
> I think this fell on the floor -- is there anything else you need to know?

No, that's not the problem, I don't like that it means some loss of debugging
features to switch the implementation.
While I agree with you that this kind of thing normally should be better left to
others, I think it's reasonable to keep the code for now, I think the necessary
change would be something like below.
Index: loader/win32.c
===================================================================
--- loader/win32.c	(revision 30526)
+++ loader/win32.c	(working copy)
@@ -345,6 +346,7 @@
 struct CRITSECT
 {
     pthread_t id;
+    pthread_mutex_t check_mutex;
     pthread_mutex_t mutex;
     int locked;
     long deadbeef;
@@ -1308,6 +1315,7 @@
 	    printf("InitializeCriticalSection(%p) - out of memory\n", c);
 	    return;
 	}
+	pthread_mutex_init(&cs->check_mutex, NULL);
 	pthread_mutex_init(&cs->mutex, NULL);
 	cs->locked = 0;
 	critsecs_list[i].cs_win = c;
@@ -1319,6 +1327,7 @@
     {
 	struct CRITSECT* cs = mreq_private(sizeof(struct CRITSECT) + sizeof(CRITICAL_SECTION),
 					   0, AREATYPE_CRITSECT);
+	pthread_mutex_init(&cs->check_mutex, NULL);
 	pthread_mutex_init(&cs->mutex, NULL);
 	cs->locked=0;
         cs->deadbeef = 0xdeadbeef;
@@ -1330,6 +1339,7 @@
 
 static void WINAPI expEnterCriticalSection(CRITICAL_SECTION* c)
 {
+    int own;
 #ifdef CRITSECS_NEWTYPE
     struct CRITSECT* cs = critsecs_get_unix(c);
 #else
@@ -1347,12 +1357,16 @@
 #endif
 	dbgprintf("Win32 Warning: Accessed uninitialized Critical Section (%p)!\n", c);
     }
-    if(cs->locked)
-	if(cs->id==pthread_self())
-	    return;
-    pthread_mutex_lock(&(cs->mutex));
-    cs->locked=1;
-    cs->id=pthread_self();
+    pthread_mutex_lock(&cs->check_mutex);
+    own = cs->locked && cs->id == pthread_self();
+    pthread_mutex_unlock(&cs->check_mutex);
+    if (!own) {
+        pthread_mutex_lock(&cs->mutex);
+        pthread_mutex_lock(&cs->check_mutex);
+        cs->locked=1;
+        cs->id=pthread_self();
+        pthread_mutex_unlock(&cs->check_mutex);
+    }
     return;
 }
 static void WINAPI expLeaveCriticalSection(CRITICAL_SECTION* c)
@@ -1369,6 +1383,7 @@
 	dbgprintf("Win32 Warning: Leaving uninitialized Critical Section %p!!\n", c);
 	return;
     }
+    pthread_mutex_lock(&cs->check_mutex);
     if (cs->locked)
     {
 	cs->locked=0;
@@ -1376,6 +1391,7 @@
     }
     else
 	dbgprintf("Win32 Warning: Unlocking unlocked Critical Section %p!!\n", c);
+    pthread_mutex_unlock(&cs->check_mutex);
     return;
 }
 
@@ -1397,13 +1413,16 @@
 	return;
     }
 
+    pthread_mutex_lock(&cs->check_mutex);
     if (cs->locked)
     {
 	dbgprintf("Win32 Warning: Deleting unlocked Critical Section %p!!\n", c);
 	pthread_mutex_unlock(&(cs->mutex));
     }
+    pthread_mutex_unlock(&cs->check_mutex);
 
 #ifndef GARBAGE
+    pthread_mutex_destroy(&cs->check_mutex);
     pthread_mutex_destroy(&(cs->mutex));
     // released by GarbageCollector in my_relase otherwise
 #endif



More information about the MPlayer-dev-eng mailing list