Introduction
Introduction Statistics Contact Development Disclaimer Help
tReuse the mixer handle if possible to reduce CPU usage - spoon - dwm status ut…
git clone git://src.adamsgaard.dk/spoon
Log
Files
Refs
LICENSE
---
commit a722598c8613433000b5d3fae11e776ff9f438c2
parent 3cf78be48fa1328e4f0d8e36c8a1576aa90b8388
Author: lostd <[email protected]>
Date: Mon, 7 Nov 2016 12:13:47 +0000
Reuse the mixer handle if possible to reduce CPU usage
Diffstat:
M mix.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
---
diff --git a/mix.c b/mix.c
t@@ -71,15 +71,18 @@ mixread(void *arg, char *buf, size_t len)
{
snd_mixer_selem_id_t *id;
snd_mixer_elem_t *elem;
- snd_mixer_t *mixerp;
+ static snd_mixer_t *mixerp;
long min, max, vol;
- int ret = -1, r;
+ int r;
int master;
snd_mixer_selem_id_alloca(&id);
snd_mixer_selem_id_set_name(id, "Master");
snd_mixer_selem_id_set_index(id, 0);
+ if (mixerp != NULL)
+ goto readvol;
+
r = snd_mixer_open(&mixerp, O_RDONLY);
if (r < 0) {
warnx("snd_mixer_open: %s", snd_strerror(r));
t@@ -100,6 +103,7 @@ mixread(void *arg, char *buf, size_t len)
warnx("snd_mixer_load: %s", snd_strerror(r));
goto out;
}
+readvol:
elem = snd_mixer_find_selem(mixerp, id);
if (elem == NULL) {
warnx("could not find mixer element");
t@@ -126,9 +130,10 @@ mixread(void *arg, char *buf, size_t len)
else
master = 100 * vol / max;
snprintf(buf, len, "%d%%", master);
- ret = 0;
+ return 0;
out:
snd_mixer_close(mixerp);
- return ret;
+ mixerp = NULL;
+ return -1;
}
#endif
You are viewing proxied material from mx1.adamsgaard.dk. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.