From 91931196e255d259e3e2a24c28cd3a0d70334708 Mon Sep 17 00:00:00 2001 From: Hojun-Cho Date: Wed, 12 Aug 2026 17:26:55 +0900 Subject: [PATCH] refactor: simplify the Plan 9 runtime loop --- Makefile | 2 +- dict.c | 2 +- main.c | 20 ++------------------ tests/unit_test.c | 3 +-- 4 files changed, 5 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index 22f84b9..d633dbe 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ OBJS = $(SRCS:.c=.o) all: $(PROG) xim gtk $(PROG): $(OBJS) - $(LD) -o $@ $(OBJS) -lthread -lString -lbio -lxcb -lm $(PKG_LIBS) + $(LD) -o $@ $(OBJS) -lthread -lbio -lxcb -lm $(PKG_LIBS) $(OBJS): dat.h fn.h ipc.h # Avoid Arch's GLIBC_2.43 sqrtf optimization for older glibc runtimes. diff --git a/dict.c b/dict.c index 2e9f691..c4339ad 100644 --- a/dict.c +++ b/dict.c @@ -44,7 +44,7 @@ void dictthread(void*) { Dictreq req; - Dictres res; + static Dictres res; threadsetname("dict"); for(;;){ diff --git a/main.c b/main.c index 45fd1b9..e5719d6 100644 --- a/main.c +++ b/main.c @@ -7,13 +7,6 @@ Channel *dictreqc; Channel *dictresc; char *fontdir; -int -threadmaybackground(void) -{ - /* Keep the launcher PID stable so supervisors can own this daemon. */ - return 0; -} - void usage(void) { @@ -39,10 +32,9 @@ emalloc(ulong n) { void *p; - p = malloc(n); + p = mallocz(n, 1); if(p == nil) die("out of memory"); - memset(p, 0, n); return p; } @@ -58,9 +50,6 @@ erealloc(void *p, ulong n) void threadmain(int argc, char **argv) { - Channel *waitc; - uchar stop; - if(argc != 3) usage(); @@ -81,10 +70,5 @@ threadmain(int argc, char **argv) die("can't create Wayland worker"); if(threadcreate(dictthread, nil, 16384) < 0) die("can't create dictionary worker"); - if(threadcreate(imthread, nil, 16384) < 0) - die("can't create input worker"); - - /* Keep the supervising process and its externally visible PID alive. */ - waitc = chancreate(sizeof stop, 0); - chanrecv(waitc, &stop); + imthread(nil); } diff --git a/tests/unit_test.c b/tests/unit_test.c index 64e6fc8..624be50 100644 --- a/tests/unit_test.c +++ b/tests/unit_test.c @@ -27,10 +27,9 @@ emalloc(ulong n) { void *p; - p = malloc(n); + p = mallocz(n, 1); if(p == nil) die("out of memory"); - memset(p, 0, n); return p; }