xref: /openbmc/linux/sound/core/seq/seq_lock.c (revision 6e29225a)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  *  Do sleep inside a spin-lock
4  *  Copyright (c) 1999 by Takashi Iwai <tiwai@suse.de>
5  */
6 
7 #include <linux/export.h>
8 #include <sound/core.h>
9 #include "seq_lock.h"
10 
11 /* wait until all locks are released */
12 void snd_use_lock_sync_helper(snd_use_lock_t *lockp, const char *file, int line)
13 {
14 	int warn_count = 5 * HZ;
15 
16 	if (atomic_read(lockp) < 0) {
17 		pr_warn("ALSA: seq_lock: lock trouble [counter = %d] in %s:%d\n", atomic_read(lockp), file, line);
18 		return;
19 	}
20 	while (atomic_read(lockp) > 0) {
21 		if (warn_count-- == 0)
22 			pr_warn("ALSA: seq_lock: waiting [%d left] in %s:%d\n", atomic_read(lockp), file, line);
23 		schedule_timeout_uninterruptible(1);
24 	}
25 }
26 EXPORT_SYMBOL(snd_use_lock_sync_helper);
27