提交 119872d2 创建 作者: Frans Kaashoek's avatar Frans Kaashoek

If there is a user-level wq library, maybe ls could use it like this

du with wq is more interesting
上级 c3171cdc
...@@ -21,6 +21,7 @@ UPROGS= \ ...@@ -21,6 +21,7 @@ UPROGS= \
scripttest \ scripttest \
ftest \ ftest \
perf perf
# pls
ifeq ($(HAVE_LWIP),y) ifeq ($(HAVE_LWIP),y)
UPROGS += \ UPROGS += \
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include "stat.h" #include "stat.h"
#include "user.h" #include "user.h"
#include "fs.h" #include "fs.h"
#include "wq.hh"
const char* const char*
fmtname(const char *path) fmtname(const char *path)
...@@ -76,6 +77,8 @@ work(void *arg) ...@@ -76,6 +77,8 @@ work(void *arg)
u64 tid = (u64)arg; u64 tid = (u64)arg;
// grab and push work (may divide into blocks? and call ls on a block)? // grab and push work (may divide into blocks? and call ls on a block)?
// maybe implement getdirent sys call that gives you some unread dir entry // maybe implement getdirent sys call that gives you some unread dir entry
printf("%d\n", tid);
while (wq_trywork()) ;
} }
int int
...@@ -84,24 +87,27 @@ main(int argc, char *argv[]) ...@@ -84,24 +87,27 @@ main(int argc, char *argv[])
int i; int i;
int nthread = 4; int nthread = 4;
for(int i = 0; i < nthread; i++) { wq_init(nthread); // create a workqueue instance with nthread workers
sbrk(8192);
void *tstack = sbrk(0);
// fprintf(1, "tstack %lx\n", tstack);
int tid = forkt(tstack, (void*) thr, (void *)(u64)i);
if (0) fprintf(1, "pls[%d]: child %d\n", getpid(), tid);
}
// push work wq.cc // create some intial work
if(argc < 2){ if(argc < 2){
ls("."); // ls(".");
exit(); struct work *w = (struct work *) malloc(sizeof(struct work));
w->rip = (void*) ls;
w->arg0 = (void *) ".";
wq_push(w);
} else {
for(i=1; i<argc; i++) {
// ls(argv[i]);
struct work *w = (struct work *) malloc(sizeof(struct work));
w->rip = (void*) ls;
w->arg0 = (void *) argv[i];
wq_push(w);
}
} }
for(i=1; i<argc; i++)
ls(argv[i]);
for(int i = 0; i < nthread; i++) // start workers; terminate when all workers have no work
wait(); wq_start();
exit(); exit();
} }
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论