mirror of
https://github.com/libretro/RetroArch.git
synced 2026-11-23 09:49:34 -10:00
Investigating #19561 - libwilhelm's AudioTrack thread crashing in pthread_mutex_lock on 0x55-poisoned memory, every stack frame inside libwilhelm itself - and answering whether the driver's locks can be atomics instead. They can, entirely: the shared state already was. Both counters the callback and writer exchange are atomics from earlier work; the mutex survived only as the condition variable's mandatory companion, guarding nothing but the wait. Both waits - sl_write's throttle and sl_wait_writable - become bounded millisecond polls on the atomic block counter, keeping the exact stall semantics the condition path had (same timeout, same partial-write bail; the bound exists because a dead device sends no callback and an unbounded wait parked the core's thread for good). A millisecond of wake grain is noise against a block period of tens of milliseconds. The callback loses its one remaining syscall and runs pure atomics on libwilhelm's thread; the lock, the condition variable, their creation and their frees all go. The driver now owns no mutex any thread could touch after free, which settles the issue's accusation structurally: the poisoned mutex is libwilhelm's own object lock, freed by Destroy while its AudioTrack thread was still in flight. For that actual race, teardown is hardened to the spec-clean recipe: stop the player, Clear the buffer queue, and confirm the STOPPED transition with a bounded GetPlayState poll before any Destroy runs, so the AudioTrack thread has nothing left to execute when the objects go. The spec makes Destroy synchronize with callbacks; Android's implementation has raced that when torn down from PLAYING with buffers queued, which is exactly the reported signature. The driver compiles nowhere in the existing lanes, so a stub SLES header set lands in tools/platform_stubs/android and a matrix lane compiles the driver with declaration-after-statement strictness; the matrix's standing count becomes seventy-seven. Verified: the new lane green (strict flags included), the full 77-lane matrix, and the standing thread-read gate at its numbers.
20 lines
999 B
C
20 lines
999 B
C
#ifndef OPENSLES_ANDROID_STUB_H
|
|
#define OPENSLES_ANDROID_STUB_H
|
|
#include <SLES/OpenSLES.h>
|
|
#define SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE 0x800007BD
|
|
#define SL_ANDROID_DATAFORMAT_PCM_EX 0x00000004
|
|
#define SL_ANDROID_PCM_REPRESENTATION_FLOAT 3
|
|
typedef struct { SLuint32 locatorType, numBuffers; } SLDataLocator_AndroidSimpleBufferQueue;
|
|
typedef struct { SLuint32 formatType, numChannels, sampleRate, bitsPerSample,
|
|
containerSize, channelMask, endianness, representation; } SLAndroidDataFormat_PCM_EX;
|
|
struct SLAndroidSimpleBufferQueueItf_;
|
|
typedef const struct SLAndroidSimpleBufferQueueItf_ * const * SLAndroidSimpleBufferQueueItf;
|
|
struct SLAndroidSimpleBufferQueueItf_ {
|
|
SLresult (*Enqueue)(SLAndroidSimpleBufferQueueItf, const void*, SLuint32);
|
|
SLresult (*Clear)(SLAndroidSimpleBufferQueueItf);
|
|
SLresult (*RegisterCallback)(SLAndroidSimpleBufferQueueItf,
|
|
void (*)(SLAndroidSimpleBufferQueueItf, void*), void*);
|
|
};
|
|
extern SLInterfaceID SL_IID_ANDROIDSIMPLEBUFFERQUEUE;
|
|
#endif
|