mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-10-29 05:40:25 -04:00
pcm: Add thread-safety to PCM API
Traditionally, many of ALSA library functions are supposed to be thread-unsafe, and applications are required to take care of thread safety by themselves. However, people never be careful enough, and almost all applications fail in this regard. This patch is an attempt to harden the thread safety in exported PCM functions in a simplistic way: just wrap some of exported functions with the pthread mutex of each PCM object. Not all API functions are wrapped by the mutex since it doesn't make sense. Instead, the patchset covers only the functions that may be likely called concurrently. The supposedly thread-safe API functions are marked in the document. For achieving the feature, two new fields are added snd_pcm_t when the option is enabled: thread_safe and lock. The former indicates that the plugin is thread-safe that doesn't need this workaround and the latter is the pthread mutex. Currently only hw plugin have thread_safe=1. So, the most of real-time sensitive apps won't be influenced by this patchset. Although the patch covers most of PCM ops, a few snd_pcm_fast_ops are left without the extra mutex locking: namely, the ones that may have blocking behavior, i.e. resume, drain, readi, writei, readn and writen. These are supposed to handle own locking in the callbacks. Also, if anyone wants to disable this new thread-safe API feature, it can be still turned off via --disable-thread-safety configure option. Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
16eb412043
commit
54931e5a54
16 changed files with 607 additions and 148 deletions
|
|
@ -124,19 +124,19 @@ struct snd_pcm_ioplug {
|
|||
/** Callback table of ioplug */
|
||||
struct snd_pcm_ioplug_callback {
|
||||
/**
|
||||
* start the PCM; required
|
||||
* start the PCM; required, called inside mutex lock
|
||||
*/
|
||||
int (*start)(snd_pcm_ioplug_t *io);
|
||||
/**
|
||||
* stop the PCM; required
|
||||
* stop the PCM; required, called inside mutex lock
|
||||
*/
|
||||
int (*stop)(snd_pcm_ioplug_t *io);
|
||||
/**
|
||||
* get the current DMA position; required
|
||||
* get the current DMA position; required, called inside mutex lock
|
||||
*/
|
||||
snd_pcm_sframes_t (*pointer)(snd_pcm_ioplug_t *io);
|
||||
/**
|
||||
* transfer the data; optional
|
||||
* transfer the data; optional, called inside mutex lock
|
||||
*/
|
||||
snd_pcm_sframes_t (*transfer)(snd_pcm_ioplug_t *io,
|
||||
const snd_pcm_channel_area_t *areas,
|
||||
|
|
@ -167,7 +167,7 @@ struct snd_pcm_ioplug_callback {
|
|||
*/
|
||||
int (*drain)(snd_pcm_ioplug_t *io);
|
||||
/**
|
||||
* toggle pause; optional
|
||||
* toggle pause; optional, called inside mutex lock
|
||||
*/
|
||||
int (*pause)(snd_pcm_ioplug_t *io, int enable);
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue