ref: 53fa826a8a695bcfade5c47f636f719c71e96b98
parent: 0d4b5b8a8a6e38faf3a07774f97dbf66797f8dea
author: cinap_lenrek <[email protected]>
date: Wed Aug 16 10:45:39 EDT 2023
zuke: make stack usage independent of Biobuf's Bsize. in mkplist: make Biobuf static so we can live with default 8k mainstacksize. move the qsort() call into metathread and give metathread some extra stackspace as qsort() is recursive. in zuke: use our own 1k buffer for parsing /dev/volume, the default 8k or future 32k for Biobuf is way overkill for it.
--- a/sys/src/cmd/audio/zuke/mkplist.c
+++ b/sys/src/cmd/audio/zuke/mkplist.c
@@ -24,8 +24,6 @@
int keepfirstartist;
};
-int mainstacksize = 32768;
-
static int simplesort;
static int moddec;
static Channel *cmeta;
@@ -47,8 +45,10 @@
[Fmod] = "mod",
};
+static int cmpmeta(void *, void *);
+
static void
-metathread(void *)
+metathread(void *cexit)
{
int max;
Meta *m;
@@ -63,6 +63,8 @@
}
tracks[ntracks++] = m;
}
+ qsort(tracks, ntracks, sizeof(Meta*), cmpmeta);
+ sendul(cexit, 0);
threadexits(nil);
}
@@ -362,7 +364,7 @@
char *dir, *s, wd[4096];
Channel *cexit;
int i, nproc;
- Biobuf out;
+ static Biobuf out;
Meta *m;
ARGBEGIN{
@@ -388,9 +390,10 @@
nproc = 1;
free(s);
for(i = 0; i < nproc; i++)
- proccreate(tagreadproc, cexit, 16384);
+ proccreate(tagreadproc, cexit, 8*1024);
- threadcreate(metathread, nil, 4096);
+ /* give metathread a large stack for qsort() */
+ threadcreate(metathread, cexit, 64*1024);
Binit(&out, 1, OWRITE);
@@ -422,8 +425,8 @@
for(i = 0; i < nproc; i++)
recvul(cexit);
chanclose(cmeta);
+ recvul(cexit);
- qsort(tracks, ntracks, sizeof(Meta*), cmpmeta);
for(i = 0; i < ntracks; i++){
if(tracks[i]->numartist < 1)
fprint(2, "no artists: %s\n", tracks[i]->path);
--- a/sys/src/cmd/audio/zuke/zuke.c
+++ b/sys/src/cmd/audio/zuke/zuke.c
@@ -77,8 +77,6 @@
int rawsz;
};
-int mainstacksize = 65536;
-
static int debug;
static int audio = -1;
static int volume, rg;
@@ -152,13 +150,13 @@
{
int f, x, ox, want, try;
char *s, *e;
- Biobuf b;
+ Biobufhdr b;
+ uchar buf[1024];
char *n;
if((f = open("/dev/volume", ORDWR|OCEXEC)) < 0)
return;
- Binit(&b, f, OREAD);
-
+ Binits(&b, f, OREAD, buf, sizeof(buf));
want = x = -1;
ox = 0;
for(try = 0; try < 10; try++){
@@ -181,9 +179,7 @@
while(Brdline(&b, '\n') != nil);
Bseek(&b, 0, 0);
}
-
volume = CLAMP(ox, 0, 100);
-
Bterm(&b);
close(f);
}