ref: 27d2955ccf58fb1c0631c497c094d793572f980f
parent: 9112daa7641d64bf5b662e9afb391fd267d96ad2
author: aiju <[email protected]>
date: Mon Oct 12 06:41:40 EDT 2015
lib9p: add reqqueuefree
--- a/sys/include/9p.h
+++ b/sys/include/9p.h
@@ -285,3 +285,4 @@
Reqqueue* reqqueuecreate(void);
void reqqueuepush(Reqqueue*, Req*, void (*)(Req *));
void reqqueueflush(Reqqueue*, Req*);
+void reqqueuefree(Reqqueue*);
--- a/sys/man/2/9pqueue
+++ b/sys/man/2/9pqueue
@@ -29,6 +29,7 @@
Reqqueue* reqqueuecreate(void);
void reqqueuepush(Reqqueue *q, Req *r, void (*f)(Req *));
void reqqueueflush(Reqqueue *q, Req *r);
+void reqqueuefree(Reqqueue *q);
.fi
.SH DESCRIPTION
.I Reqqueue
@@ -55,6 +56,10 @@
which will remove the request immediately if processing has
not started. If processing has been started, the process
will be interrupted.
+.PP
+.I Reqqueuefree
+frees a queue.
+No new requests should be send to the queue and it will be freed once all requests in it have been processed.
.SH SOURCE
.B /sys/src/lib9p/queue.c
.SH SEE ALSO
--- a/sys/src/lib9p/queue.c
+++ b/sys/src/lib9p/queue.c
@@ -35,8 +35,14 @@
memset(&r->qu, 0, sizeof(r->qu));
q->cur = r;
qunlock(q);
+ if(f == nil)
+ break;
f(r);
}
+
+ free(r);
+ free(q);
+ threadexits(nil);
}
Reqqueue *
@@ -82,4 +88,15 @@
qunlock(q);
respond(r, "interrupted");
}
+}
+
+void
+reqqueuefree(Reqqueue *q)
+{
+ Req *r;
+
+ if(q == nil)
+ return;
+ r = emalloc9p(sizeof(Req));
+ reqqueuepush(q, r, nil);
}