]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/lib9p/queue.c
acme: fix border size, autoindent undo: imported from plan9port (thanks jxy)
[plan9front.git] / sys / src / lib9p / queue.c
index 307c385fcf79a26a692a4a49f9f3a27dd8d1c357..ff846cfd8ab95802c84d8a5ea8c63b67fdfc4a9e 100644 (file)
@@ -4,34 +4,27 @@
 #include <fcall.h>
 #include <9p.h>
 
-static int
-_reqqueuenote(void *uregs, char *note)
-{
-       Reqqueue *q;
-
-       if(strcmp(note, "flush") != 0)
-               return 0;
-       q = *threaddata();
-       if(q != nil){
-               q->cur = nil;
-               notejmp(uregs, q->flush, 1);
-       }
-       return 1;
-}
-
 static void
 _reqqueueproc(void *v)
 {
        Reqqueue *q;
        Req *r;
        void (*f)(Req *);
-       
+       int fd;
+       char *buf;
+
        q = v;
-       *threaddata() = q;
        rfork(RFNOTEG);
-       threadnotify(_reqqueuenote, 1);
+
+       buf = smprint("/proc/%lud/ctl", (ulong)getpid());
+       fd = open(buf, OWRITE|OCEXEC);
+       free(buf);
+       
        for(;;){
                qlock(q);
+               q->flush = 0;
+               if(fd >= 0)
+                       write(fd, "nointerrupt", 11);
                q->cur = nil;
                while(q->next == q)
                        rsleep(q);
@@ -39,17 +32,19 @@ _reqqueueproc(void *v)
                r->qu.next->prev = r->qu.prev;
                r->qu.prev->next = r->qu.next;
                f = r->qu.f;
-               qlock(&r->lk);
                memset(&r->qu, 0, sizeof(r->qu));
-               qunlock(&r->lk);
                q->cur = r;
-               if(setjmp(q->flush)){
-                       respond(r, "interrupted");
-                       continue;
-               }
                qunlock(q);
+               if(f == nil)
+                       break;
                f(r);
        }
+
+       if(fd >= 0)
+               close(fd);
+       free(r);
+       free(q);
+       threadexits(nil);
 }
 
 Reqqueue *
@@ -61,8 +56,7 @@ reqqueuecreate(void)
        memset(q, 0, sizeof(*q));
        q->l = q;
        q->next = q->prev = q;
-       q->pid = threadpid(proccreate(_reqqueueproc, q, mainstacksize));
-       print("%d\n", q->pid);
+       q->pid = proccreate(_reqqueueproc, q, mainstacksize);
        return q;
 }
 
@@ -75,7 +69,7 @@ reqqueuepush(Reqqueue *q, Req *r, void (*f)(Req *))
        r->qu.prev = q->prev;
        q->prev->next = &r->qu;
        q->prev = &r->qu;
-       rwakeupall(q);
+       rwakeup(q);
        qunlock(q);
 }
 
@@ -84,30 +78,27 @@ reqqueueflush(Reqqueue *q, Req *r)
 {
        qlock(q);
        if(q->cur == r){
-               postnote(PNPROC, q->pid, "flush");
+               threadint(q->pid);
+               q->flush++;
                qunlock(q);
        }else{
                if(r->qu.next != nil){
                        r->qu.next->prev = r->qu.prev;
                        r->qu.prev->next = r->qu.next;
                }
-               qlock(&r->lk);
                memset(&r->qu, 0, sizeof(r->qu));
-               qunlock(&r->lk);
                qunlock(q);
                respond(r, "interrupted");
        }
 }
 
-int
-reqqueueflushed(void)
+void
+reqqueuefree(Reqqueue *q)
 {
-       Reqqueue *q;
-       
-       q = *threaddata();
-       qlock(q);
-       if(setjmp(q->flush))
-               return 1;
-       qunlock(q);
-       return 0;
+       Req *r;
+
+       if(q == nil)
+               return;
+       r = emalloc9p(sizeof(Req));
+       reqqueuepush(q, r, nil);
 }