ref: 3c761dea5de8d7b2bce06a39c51c7885f08910de
parent: 0ddab8b30464a21c79fe7fa43621afd3496bc1ee
author: henesy <[email protected]>
date: Tue Mar 15 09:42:27 EDT 2022
comment out alt(), using proccreate now successfully
--- a/main.c
+++ b/main.c
@@ -17,8 +17,8 @@
// Commands log ;; 4 entries, 1024 wide
char clog[Ncmd][Cmdwidth];
+int mainstacksize = 65536;
-
// Prototypes for 9p handler functions
static void fsattach(Req *r);
static int getdirent(int n, Dir *d, void *);
@@ -28,6 +28,7 @@
static char* fsclone(Fid *fid, Fid *newfid);
static void fsstat(Req *r);
+char *mnt, *srvd;
// Srv structure to handle incoming 9p communications
static Srv srvfs =
@@ -132,14 +133,30 @@
return str;
}
+// FS starter
+void
+initfs(void*)
+{
+
+ // Setup ctl file
+ File9 ctl = (File9) { (Ref){ 0 }, 0, "ctl" };
+ files[0] = &ctl;
+
+ // Setup log file
+ File9 log = (File9) { (Ref){ 0 }, 1, "screen" };
+ files[1] = &log;
+
+ threadpostmountsrv(&srvfs, srvd, mnt, MREPL|MCREATE);
+ threadexits(nil);
+}
+
/* A simple 9p fileserver to show a minimal set of operations */
void
threadmain(int argc, char *argv[])
{
- char *mnt, *srv;
- srv = nil;
+ srvd = nil;
mnt = "/mnt/simplefs";
ARGBEGIN{
@@ -147,7 +164,7 @@
chatty9p++;
break;
case 's':
- srv = EARGF(usage());
+ srvd = EARGF(usage());
break;
case 'm':
mnt = EARGF(usage());
@@ -159,19 +176,11 @@
if(argc != 0)
usage();
- // Setup ctl file
- File9 ctl = (File9) { (Ref){ 0 }, 0, "ctl" };
- files[0] = &ctl;
-
- // Setup log file
- File9 log = (File9) { (Ref){ 0 }, 1, "screen" };
- files[1] = &log;
-
- threadcreate(initscreen, nil, 4096);
-
- threadpostmountsrv(&srvfs, srv, mnt, MREPL|MCREATE);
+ proccreate(initfs, nil, mainstacksize);
+ proccreate(initscreen, nil, mainstacksize);
threadexits(nil);
}
+
// Handle 9p attach -- independent implementation
--- a/screen.c
+++ b/screen.c
@@ -17,6 +17,11 @@
Channel *mchan, *kbchan; // mouse and kb rcvr chans for fs
+
+int kbv;
+int mv;
+Alt alts[3];
+
/* Menus */
char *buttons[] = {"exit", 0}; // Maybe a refresh button?
Menu menu = { buttons };
@@ -127,7 +132,6 @@
initbuf(void)
{
int y, x;
- ourfont = openfont(display, "/lib/font/bit/vga/unicode.font");
p = runestringsize(ourfont, s);
@@ -155,8 +159,15 @@
int e, timer;
/* Initiate graphics and mouse */
- if(initdraw(nil, nil, "cursedfs") < 0)
- sysfatal("initdraw failed: %r");
+ //if(newwindow("-dx 100 -dy 100") < 0){
+ // fprint(2, "newwindow failed → %r");
+ // threadexitsall("newwindow failed → %r");
+ //}
+ if(initdraw(nil, "/lib/font/bit/vga/unicode.font", "cursedfs") < 0){
+ fprint(2, "initdraw failed → %r");
+ threadexitsall("initdraw failed → %r");
+ }
+ ourfont = openfont(display, "/lib/font/bit/vga/unicode.font");
einit(Emouse | Ekeyboard);
@@ -187,18 +198,18 @@
/* Main event loop */
- kbchan = chancreate(sizeof (int), 1);
- mchan = chancreate(sizeof (int), 1);
- int *kbv = calloc(1, sizeof (int));
- int *mv = calloc(1, sizeof (int));
- Alt kbalt[] = {
- {kbchan, kbv, CHANSND},
- {nil, nil, CHANEND},
- };
- Alt malt[] = {
- {mchan, mv, CHANSND},
- {nil, nil, CHANEND},
- };
+ kbchan = chancreate(sizeof (int), 10);
+ mchan = chancreate(sizeof (int), 10);
+ //kbv = calloc(1, sizeof (int));
+ //mv = calloc(1, sizeof (int));
+ //memset(&alts, 0, sizeof alts);
+ alts[0].c = mchan;
+ alts[0].v = &mv;
+ alts[0].op = CHANSND;
+ alts[1].c = kbchan;
+ alts[1].v = &kbv;
+ alts[1].op = CHANSND;
+ alts[2].op = CHANEND;
for(;;){
e = event(&ev);
@@ -216,12 +227,7 @@
}else if(e == Ekeyboard){
kbdc = ev.kbdc;
// Alt to optionally send if getch channel is listening
- switch(alt(kbalt)){
- case 0:
- *kbv = kbdc;
- send(kbchan, kbv);
- break;
- }
+ kbv = kbdc;
}else if(e == Emouse){
if((ev.mouse.buttons & 4)
@@ -230,13 +236,17 @@
threadexitsall(nil);
// Alt to optionally send if getm channel is listening
- switch(alt(malt)){
- case 0:
- // Send mouse buttons
- *mv = ev.mouse.buttons;
- send(mchan, mv);
- break;
- }
+ mv = ev.mouse.buttons;
}
+ /* « deadlocks »
+ switch(alt(alts)){
+ case 0:
+ break;
+ case 1:
+ break;
+ default:
+ break;
+ }
+ */
}
}