much work on the player and hunting for a bug, which first seemed to be in ffmpeg-decoder, but eventually was found in a race condition in audio-placed-player.rkt and an allocation problem in libao-async-ffi-racket.rkt

This commit is contained in:
2026-05-15 22:11:25 +02:00
parent 3c18e75cf6
commit c9a91bf2be
11 changed files with 534 additions and 340 deletions
+36 -8
View File
@@ -38,23 +38,51 @@
;; Mutex definitions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (make-mutex)
(make-semaphore 1))
(define-struct mutex
(thread count mut own) #:mutable)
(define make-mutex-struct make-mutex)
(set! make-mutex (λ ()
(make-mutex-struct #f 0 (make-semaphore 1) (make-semaphore 1))))
(define (mutex-lock m)
(semaphore-wait m))
(semaphore-wait (mutex-own m))
(if (eq? (mutex-thread m) (current-thread))
(begin
(set-mutex-count! m (+ (mutex-count m) 1))
(semaphore-post (mutex-own m))
)
(begin
(semaphore-post (mutex-own m))
(semaphore-wait (mutex-mut m))
(set-mutex-count! m 1)
(set-mutex-thread! m (current-thread)))
)
)
(define (mutex-unlock m)
(semaphore-post m))
(semaphore-wait (mutex-own m))
(let ((count (mutex-count m)))
(set! count (- count 1))
(set-mutex-count! m count)
(if (= count 0)
(begin
(set-mutex-thread! m #f)
(semaphore-post (mutex-own m))
(semaphore-post (mutex-mut m)))
(semaphore-post (mutex-own m)))
)
)
(define-syntax with-mutex
(syntax-rules ()
((_ m b1 ...)
(begin
(semaphore-wait m)
(let ((r (begin b1 ...)))
(semaphore-post m)
r)))))
(dynamic-wind
(λ () (mutex-lock m))
(λ () b1 ...)
(λ () (mutex-unlock m)))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;