[PATCH v5 2/5] winegstreamer: Use the GstObject lock instead of a new allocator mutex.

Rémi Bernon wine at gitlab.winehq.org
Thu Jun 30 07:33:42 CDT 2022


From: Rémi Bernon <rbernon at codeweavers.com>

Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---
 dlls/winegstreamer/wg_allocator.c | 37 ++++++++++++++-----------------
 1 file changed, 17 insertions(+), 20 deletions(-)

diff --git a/dlls/winegstreamer/wg_allocator.c b/dlls/winegstreamer/wg_allocator.c
index c31751ce83f..16e961a57d4 100644
--- a/dlls/winegstreamer/wg_allocator.c
+++ b/dlls/winegstreamer/wg_allocator.c
@@ -57,8 +57,7 @@ typedef struct
     wg_allocator_request_sample_cb request_sample;
     void *request_sample_context;
 
-    pthread_mutex_t mutex;
-    pthread_cond_t release_cond;
+    GCond release_cond;
     struct list memory_list;
 } WgAllocator;
 
@@ -79,7 +78,7 @@ static gpointer wg_allocator_map(GstMemory *gst_memory, GstMapInfo *info, gsize
 
     GST_LOG("memory %p, info %p, maxsize %#zx", memory, info, maxsize);
 
-    pthread_mutex_lock(&allocator->mutex);
+    GST_OBJECT_LOCK(allocator);
 
     if (!memory->sample)
         info->data = memory->unix_map_info.data;
@@ -91,7 +90,7 @@ static gpointer wg_allocator_map(GstMemory *gst_memory, GstMapInfo *info, gsize
     if (info->flags & GST_MAP_WRITE)
         memory->written = max(memory->written, maxsize);
 
-    pthread_mutex_unlock(&allocator->mutex);
+    GST_OBJECT_UNLOCK(allocator);
 
     GST_INFO("Mapped memory %p to %p", memory, info->data);
     return info->data;
@@ -107,15 +106,15 @@ static void wg_allocator_unmap(GstMemory *gst_memory, GstMapInfo *info)
 
     GST_LOG("memory %p, info %p", memory, info);
 
-    pthread_mutex_lock(&allocator->mutex);
+    GST_OBJECT_LOCK(allocator);
 
     if (memory->sample && info->data == memory->sample->data)
     {
         InterlockedDecrement(&memory->sample->refcount);
-        pthread_cond_signal(&allocator->release_cond);
+        g_cond_signal(&allocator->release_cond);
     }
 
-    pthread_mutex_unlock(&allocator->mutex);
+    GST_OBJECT_UNLOCK(allocator);
 }
 
 static void wg_allocator_init(WgAllocator *allocator)
@@ -129,8 +128,7 @@ static void wg_allocator_init(WgAllocator *allocator)
 
     GST_OBJECT_FLAG_SET(allocator, GST_ALLOCATOR_FLAG_CUSTOM_ALLOC);
 
-    pthread_mutex_init(&allocator->mutex, NULL);
-    pthread_cond_init(&allocator->release_cond, NULL);
+    g_cond_init(&allocator->release_cond);
     list_init(&allocator->memory_list);
 }
 
@@ -140,8 +138,7 @@ static void wg_allocator_finalize(GObject *object)
 
     GST_LOG("allocator %p", allocator);
 
-    pthread_cond_destroy(&allocator->release_cond);
-    pthread_mutex_destroy(&allocator->mutex);
+    g_cond_clear(&allocator->release_cond);
 
     G_OBJECT_CLASS(wg_allocator_parent_class)->finalize(object);
 }
@@ -160,12 +157,12 @@ static GstMemory *wg_allocator_alloc(GstAllocator *gst_allocator, gsize size,
     memory->unix_memory = gst_allocator_alloc(NULL, size, params);
     gst_memory_map(memory->unix_memory, &memory->unix_map_info, GST_MAP_WRITE);
 
-    pthread_mutex_lock(&allocator->mutex);
+    GST_OBJECT_LOCK(allocator);
 
     memory->sample = allocator->request_sample(size, allocator->request_sample_context);
     list_add_tail(&allocator->memory_list, &memory->entry);
 
-    pthread_mutex_unlock(&allocator->mutex);
+    GST_OBJECT_UNLOCK(allocator);
 
     GST_INFO("Allocated memory %p, sample %p, unix_memory %p, data %p", memory,
             memory->sample, memory->unix_memory, memory->unix_map_info.data);
@@ -179,7 +176,7 @@ static void wg_allocator_free(GstAllocator *gst_allocator, GstMemory *gst_memory
 
     GST_LOG("allocator %p, memory %p", allocator, memory);
 
-    pthread_mutex_lock(&allocator->mutex);
+    GST_OBJECT_LOCK(allocator);
 
     if (memory->sample)
         InterlockedDecrement(&memory->sample->refcount);
@@ -187,7 +184,7 @@ static void wg_allocator_free(GstAllocator *gst_allocator, GstMemory *gst_memory
 
     list_remove(&memory->entry);
 
-    pthread_mutex_unlock(&allocator->mutex);
+    GST_OBJECT_UNLOCK(allocator);
 
     gst_memory_unmap(memory->unix_memory, &memory->unix_map_info);
     gst_memory_unref(memory->unix_memory);
@@ -228,7 +225,7 @@ static void release_memory_sample(WgAllocator *allocator, WgMemory *memory, bool
     while (sample->refcount > 1)
     {
         GST_WARNING("Waiting for sample %p to be unmapped", sample);
-        pthread_cond_wait(&allocator->release_cond, &allocator->mutex);
+        g_cond_wait(&allocator->release_cond, GST_OBJECT_GET_LOCK(allocator));
     }
     InterlockedDecrement(&sample->refcount);
 
@@ -249,10 +246,10 @@ void wg_allocator_destroy(GstAllocator *gst_allocator)
 
     GST_LOG("allocator %p", allocator);
 
-    pthread_mutex_lock(&allocator->mutex);
+    GST_OBJECT_LOCK(allocator);
     LIST_FOR_EACH_ENTRY(memory, &allocator->memory_list, WgMemory, entry)
         release_memory_sample(allocator, memory, true);
-    pthread_mutex_unlock(&allocator->mutex);
+    GST_OBJECT_UNLOCK(allocator);
 
     g_object_unref(allocator);
 
@@ -278,10 +275,10 @@ void wg_allocator_release_sample(GstAllocator *gst_allocator, struct wg_sample *
 
     GST_LOG("allocator %p, sample %p, discard_data %u", allocator, sample, discard_data);
 
-    pthread_mutex_lock(&allocator->mutex);
+    GST_OBJECT_LOCK(allocator);
     if ((memory = find_sample_memory(allocator, sample)))
         release_memory_sample(allocator, memory, discard_data);
     else if (sample->refcount)
         GST_ERROR("Couldn't find memory for sample %p", sample);
-    pthread_mutex_unlock(&allocator->mutex);
+    GST_OBJECT_UNLOCK(allocator);
 }
-- 
GitLab


https://gitlab.winehq.org/wine/wine/-/merge_requests/302



More information about the wine-devel mailing list