Alexandre Julliard : ntdll: Use a pthread mutex for the CD-ROM cache section.

Alexandre Julliard julliard at winehq.org
Mon Jul 13 16:08:50 CDT 2020


Module: wine
Branch: master
Commit: 992bdd77a05755ccbde22bf244a41ab3c50086db
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=992bdd77a05755ccbde22bf244a41ab3c50086db

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Mon Jul 13 18:43:56 2020 +0200

ntdll: Use a pthread mutex for the CD-ROM cache section.

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/ntdll/unix/cdrom.c | 33 +++++++++++++--------------------
 1 file changed, 13 insertions(+), 20 deletions(-)

diff --git a/dlls/ntdll/unix/cdrom.c b/dlls/ntdll/unix/cdrom.c
index b60a01df8f..0d8b624308 100644
--- a/dlls/ntdll/unix/cdrom.c
+++ b/dlls/ntdll/unix/cdrom.c
@@ -298,14 +298,7 @@ struct cdrom_cache {
 #define MAX_CACHE_ENTRIES       5
 static struct cdrom_cache cdrom_cache[MAX_CACHE_ENTRIES];
 
-static RTL_CRITICAL_SECTION cache_section;
-static RTL_CRITICAL_SECTION_DEBUG critsect_debug =
-{
-    0, 0, &cache_section,
-    { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
-      0, 0, { (DWORD_PTR)(__FILE__ ": cache_section") }
-};
-static RTL_CRITICAL_SECTION cache_section = { &critsect_debug, -1, 0, 0, 0, 0 };
+static pthread_mutex_t cache_mutex = PTHREAD_MUTEX_INITIALIZER;
 
 /* Proposed media change function: not really needed at this time */
 /* This is a 1 or 0 type of function */
@@ -566,9 +559,9 @@ static NTSTATUS CDROM_SyncCache(int dev, int fd)
 
 static void CDROM_ClearCacheEntry(int dev)
 {
-    RtlEnterCriticalSection( &cache_section );
+    pthread_mutex_lock( &cache_mutex );
     cdrom_cache[dev].toc_good = 0;
-    RtlLeaveCriticalSection( &cache_section );
+    pthread_mutex_unlock( &cache_mutex );
 }
 
 
@@ -674,7 +667,7 @@ static NTSTATUS CDROM_Open(int fd, int* dev)
 
     if (fstat(fd, &st) == -1) return errno_to_status( errno );
 
-    RtlEnterCriticalSection( &cache_section );
+    pthread_mutex_lock( &cache_mutex );
     for (*dev = 0; *dev < MAX_CACHE_ENTRIES; (*dev)++)
     {
         if (empty == -1 &&
@@ -695,7 +688,7 @@ static NTSTATUS CDROM_Open(int fd, int* dev)
             cdrom_cache[*dev].inode   = st.st_ino;
         }
     }
-    RtlLeaveCriticalSection( &cache_section );
+    pthread_mutex_unlock( &cache_mutex );
 
     TRACE("%d, %d\n", *dev, fd);
     return ret;
@@ -847,13 +840,13 @@ static NTSTATUS CDROM_ReadTOC(int dev, int fd, CDROM_TOC* toc)
     if (dev < 0 || dev >= MAX_CACHE_ENTRIES)
         return STATUS_INVALID_PARAMETER;
 
-    RtlEnterCriticalSection( &cache_section );
+    pthread_mutex_lock( &cache_mutex );
     if (cdrom_cache[dev].toc_good || !(ret = CDROM_SyncCache(dev, fd)))
     {
         *toc = cdrom_cache[dev].toc;
         ret = STATUS_SUCCESS;
     }
-    RtlLeaveCriticalSection( &cache_section );
+    pthread_mutex_unlock( &cache_mutex );
     return ret;
 }
 
@@ -933,7 +926,7 @@ static NTSTATUS CDROM_ReadQChannel(int dev, int fd, const CDROM_SUB_Q_DATA_FORMA
     switch (fmt->Format)
     {
     case IOCTL_CDROM_CURRENT_POSITION:
-        RtlEnterCriticalSection( &cache_section );
+        pthread_mutex_lock( &cache_mutex );
 	if (hdr->AudioStatus==AUDIO_STATUS_IN_PROGRESS) {
           data->CurrentPosition.FormatCode = IOCTL_CDROM_CURRENT_POSITION;
           data->CurrentPosition.Control = sc.cdsc_ctrl;
@@ -958,7 +951,7 @@ static NTSTATUS CDROM_ReadQChannel(int dev, int fd, const CDROM_SUB_Q_DATA_FORMA
 	  cdrom_cache[dev].CurrentPosition.Header = *hdr; /* Preserve header info */
 	  data->CurrentPosition = cdrom_cache[dev].CurrentPosition;
 	}
-        RtlLeaveCriticalSection( &cache_section );
+        pthread_mutex_unlock( &cache_mutex );
         break;
     case IOCTL_CDROM_MEDIA_CATALOG:
         data->MediaCatalog.FormatCode = IOCTL_CDROM_MEDIA_CATALOG;
@@ -1044,7 +1037,7 @@ static NTSTATUS CDROM_ReadQChannel(int dev, int fd, const CDROM_SUB_Q_DATA_FORMA
     switch (fmt->Format)
     {
     case IOCTL_CDROM_CURRENT_POSITION:
-        RtlEnterCriticalSection( &cache_section );
+        pthread_mutex_lock( &cache_mutex );
 	if (hdr->AudioStatus==AUDIO_STATUS_IN_PROGRESS) {
           data->CurrentPosition.FormatCode = IOCTL_CDROM_CURRENT_POSITION;
           data->CurrentPosition.Control = sc.what.position.control;
@@ -1066,7 +1059,7 @@ static NTSTATUS CDROM_ReadQChannel(int dev, int fd, const CDROM_SUB_Q_DATA_FORMA
 	  cdrom_cache[dev].CurrentPosition.Header = *hdr; /* Preserve header info */
 	  data->CurrentPosition = cdrom_cache[dev].CurrentPosition;
 	}
-        RtlLeaveCriticalSection( &cache_section );
+        pthread_mutex_unlock( &cache_mutex );
         break;
     case IOCTL_CDROM_MEDIA_CATALOG:
         data->MediaCatalog.FormatCode = IOCTL_CDROM_MEDIA_CATALOG;
@@ -1255,7 +1248,7 @@ static NTSTATUS CDROM_SeekAudioMSF(int dev, int fd, const CDROM_SEEK_AUDIO_MSF*
     if (i <= toc.FirstTrack || i > toc.LastTrack+1)
       return STATUS_INVALID_PARAMETER;
     i--;
-    RtlEnterCriticalSection( &cache_section );
+    pthread_mutex_lock( &cache_mutex );
     cp = &cdrom_cache[dev].CurrentPosition;
     cp->FormatCode = IOCTL_CDROM_CURRENT_POSITION;
     cp->Control = toc.TrackData[i-toc.FirstTrack].Control;
@@ -1269,7 +1262,7 @@ static NTSTATUS CDROM_SeekAudioMSF(int dev, int fd, const CDROM_SEEK_AUDIO_MSF*
     frame -= FRAME_OF_TOC(toc,i);
     cp->TrackRelativeAddress[0] = 0;
     MSF_OF_FRAME(cp->TrackRelativeAddress[1], frame);
-    RtlLeaveCriticalSection( &cache_section );
+    pthread_mutex_unlock( &cache_mutex );
 
     /* If playing, then issue a seek command, otherwise do nothing */
 #ifdef linux




More information about the wine-cvs mailing list