[PATCH v4 11/11] hw/display/apple-gfx: Replace QemuSemaphore with QemuEvent

Akihiko Odaki posted 11 patches 5 months, 3 weeks ago
Maintainers: Phil Dennis-Jordan <phil@philjordan.eu>, Paolo Bonzini <pbonzini@redhat.com>, Stefan Weil <sw@weilnetz.de>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Hailiang Zhang <zhanghailiang@xfusion.com>, Peter Xu <peterx@redhat.com>, Fabiano Rosas <farosas@suse.de>
There is a newer version of this series
[PATCH v4 11/11] hw/display/apple-gfx: Replace QemuSemaphore with QemuEvent
Posted by Akihiko Odaki 5 months, 3 weeks ago
sem in AppleGFXReadMemoryJob is an one-shot event so it can be converted
into QemuEvent, which is more specialized for such a use case.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
 hw/display/apple-gfx.m | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/hw/display/apple-gfx.m b/hw/display/apple-gfx.m
index 8dde1f138dce..174d56ae05bc 100644
--- a/hw/display/apple-gfx.m
+++ b/hw/display/apple-gfx.m
@@ -454,7 +454,7 @@ static void set_cursor_glyph(void *opaque)
 /* ------ DMA (device reading system memory) ------ */
 
 typedef struct AppleGFXReadMemoryJob {
-    QemuSemaphore sem;
+    QemuEvent event;
     hwaddr physical_address;
     uint64_t length;
     void *dst;
@@ -470,7 +470,7 @@ static void apple_gfx_do_read_memory(void *opaque)
                         job->dst, job->length, MEMTXATTRS_UNSPECIFIED);
     job->success = (r == MEMTX_OK);
 
-    qemu_sem_post(&job->sem);
+    qemu_event_set(&job->event);
 }
 
 static bool apple_gfx_read_memory(AppleGFXState *s, hwaddr physical_address,
@@ -483,11 +483,11 @@ static bool apple_gfx_read_memory(AppleGFXState *s, hwaddr physical_address,
     trace_apple_gfx_read_memory(physical_address, length, dst);
 
     /* Performing DMA requires BQL, so do it in a BH. */
-    qemu_sem_init(&job.sem, 0);
+    qemu_event_init(&job.event, 0);
     aio_bh_schedule_oneshot(qemu_get_aio_context(),
                             apple_gfx_do_read_memory, &job);
-    qemu_sem_wait(&job.sem);
-    qemu_sem_destroy(&job.sem);
+    qemu_event_wait(&job.event);
+    qemu_event_destroy(&job.event);
     return job.success;
 }
 

-- 
2.49.0
Re: [PATCH v4 11/11] hw/display/apple-gfx: Replace QemuSemaphore with QemuEvent
Posted by Philippe Mathieu-Daudé 5 months, 3 weeks ago
On 26/5/25 07:29, Akihiko Odaki wrote:
> sem in AppleGFXReadMemoryJob is an one-shot event so it can be converted
> into QemuEvent, which is more specialized for such a use case.
> 
> Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
> ---
>   hw/display/apple-gfx.m | 10 +++++-----
>   1 file changed, 5 insertions(+), 5 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>


Re: [PATCH v4 11/11] hw/display/apple-gfx: Replace QemuSemaphore with QemuEvent
Posted by Philippe Mathieu-Daudé 5 months, 3 weeks ago
On 26/5/25 11:27, Philippe Mathieu-Daudé wrote:
> On 26/5/25 07:29, Akihiko Odaki wrote:
>> sem in AppleGFXReadMemoryJob is an one-shot event so it can be converted
>> into QemuEvent, which is more specialized for such a use case.

BTW it would be nice to document that in "qemu/thread.h" API.

>>
>> Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
>> ---
>>   hw/display/apple-gfx.m | 10 +++++-----
>>   1 file changed, 5 insertions(+), 5 deletions(-)
> 
> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> 


Re: [PATCH v4 11/11] hw/display/apple-gfx: Replace QemuSemaphore with QemuEvent
Posted by Akihiko Odaki 5 months, 2 weeks ago
On 2025/05/26 18:29, Philippe Mathieu-Daudé wrote:
> On 26/5/25 11:27, Philippe Mathieu-Daudé wrote:
>> On 26/5/25 07:29, Akihiko Odaki wrote:
>>> sem in AppleGFXReadMemoryJob is an one-shot event so it can be converted
>>> into QemuEvent, which is more specialized for such a use case.
> 
> BTW it would be nice to document that in "qemu/thread.h" API.

I will add a documentation with the next version.