mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2026-02-18 22:05:17 -05:00
pcm: Better understandable locking code
The newly added locking code seems to have confused quite a few people, as "thread_safe=1" may be considered as if the thread-safety lock has to be turned on. (It meant that the plugin _is_ thread-safe, i.e. it needs no extra locking.) For avoiding such a misunderstanding, this commit renames the relevant pcm fields and give more comments to explain what is for what. The former single pcm->thread_safe flag is now split to two boolean flags, pcm->need_lock and pcm->lock_enabled. It consumes a few more bytes, but this would be (hopefully) better understandable. No functional change by this commit. Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
3b08152f68
commit
0fc4b4d17b
3 changed files with 34 additions and 11 deletions
|
|
@ -2545,14 +2545,20 @@ int snd_pcm_new(snd_pcm_t **pcmp, snd_pcm_type_t type, const char *name,
|
|||
INIT_LIST_HEAD(&pcm->async_handlers);
|
||||
#ifdef THREAD_SAFE_API
|
||||
pthread_mutex_init(&pcm->lock, NULL);
|
||||
/* use locking as default;
|
||||
* each plugin may suppress this in its open call
|
||||
*/
|
||||
pcm->need_lock = 1;
|
||||
{
|
||||
static int default_thread_safe = -1;
|
||||
if (default_thread_safe < 0) {
|
||||
/* set lock_enabled field depending on $LIBASOUND_THREAD_SAFE */
|
||||
static int do_lock_enable = -1; /* uninitialized */
|
||||
|
||||
/* evaluate env var only once at the first open for consistency */
|
||||
if (do_lock_enable == -1) {
|
||||
char *p = getenv("LIBASOUND_THREAD_SAFE");
|
||||
default_thread_safe = !p || *p != '0';
|
||||
do_lock_enable = !p || *p != '0';
|
||||
}
|
||||
if (!default_thread_safe)
|
||||
pcm->thread_safe = -1; /* force to disable */
|
||||
pcm->lock_enabled = do_lock_enable;
|
||||
}
|
||||
#endif
|
||||
*pcmp = pcm;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue