summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2024-09-17 15:35:48 +0000
committerrodri <rgl@antares-labs.eu>2024-09-17 15:35:48 +0000
commit9f4d2e578fa2b874d65fd85d28f9b9f31e88dd0f (patch)
treeda036aee111e905d5245ac033faf99091f3641b7
parentbeca6100b73428b4b72973275d2989a4c6581f51 (diff)
downloadlibgraphics-9f4d2e578fa2b874d65fd85d28f9b9f31e88dd0f.tar.gz
libgraphics-9f4d2e578fa2b874d65fd85d28f9b9f31e88dd0f.tar.bz2
libgraphics-9f4d2e578fa2b874d65fd85d28f9b9f31e88dd0f.zip
forgot turbopool.c
-rw-r--r--turbopool.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/turbopool.c b/turbopool.c
new file mode 100644
index 0000000..8011c18
--- /dev/null
+++ b/turbopool.c
@@ -0,0 +1,60 @@
+#include <u.h>
+#include <libc.h>
+#include <thread.h>
+#include <draw.h>
+#include <memdraw.h>
+#include <geometry.h>
+#include "libobj/obj.h"
+#include "graphics.h"
+#include "internal.h"
+
+static void
+_turboproc(void *arg)
+{
+ Turbopool *p;
+ Turbotask *t;
+
+ threadsetname("turboproc");
+
+ p = arg;
+
+ while((t = recvp(p->subq)) != nil){
+ t->fn(t->arg);
+ free(t);
+ }
+}
+
+Turbopool *
+mkturbopool(ulong nprocs)
+{
+ Turbopool *p;
+
+ p = emalloc(sizeof *p);
+ memset(p, 0, sizeof *p);
+ p->nprocs = nprocs;
+ p->subq = chancreate(sizeof(void*), nprocs);
+ while(nprocs--)
+ proccreate(_turboproc, p, mainstacksize);
+ return p;
+}
+
+void
+turbopoolexec(Turbopool *p, void (*fn)(void*), void *arg)
+{
+ Turbotask *t;
+
+ t = emalloc(sizeof *t);
+ t->fn = fn;
+ t->arg = arg;
+
+ sendp(p->subq, t);
+}
+
+void
+rmturbopool(Turbopool *p)
+{
+ while(p->nprocs--)
+ sendp(p->subq, nil);
+ chanfree(p->subq);
+ free(p);
+}