ref: 2f99484b9dac562ce5faf8d9a652151a9a864b3e
parent: a034e629f7611166cae617b08b19667925fc4305
parent: 27d2955ccf58fb1c0631c497c094d793572f980f
author: cinap_lenrek <[email protected]>
date: Thu Oct 15 09:22:48 EDT 2015
merge
--- a/sys/include/9p.h
+++ b/sys/include/9p.h
@@ -287,3 +287,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);
}