x

上级 e05913d5
......@@ -55,7 +55,7 @@ du(int fd)
int nfd = openat(fd, name, 0);
if (nfd >= 0)
size += du(nfd); // should go into work queue
;//size += du(nfd); // should go into work queue
free((void*)name);
});
}
......@@ -67,6 +67,16 @@ du(int fd)
int
main(int ac, char **av)
{
dirit di(open(".", 0));
wq_for<dirit>(di,
[](dirit &i)->bool { return !i.end(); },
[&](const char *name)->void
{
printf("no..\n");
});
//initwq();
printf("%d\n", du(open(".", 0)));
......
......@@ -8,17 +8,54 @@ struct work {
char data[];
};
struct run_work {
virtual void run() = 0;
};
void initwq(void);
struct work * allocwork(void);
void freework(struct work *w);
int wq_push(struct work *w);
template<typename IT, typename BODY>
struct for_work : public run_work {
for_work(IT &it, BODY body) : it_(it), body_(body) {}
virtual void run() { printf("hi %s\n", *it_); }
IT &it_;
bool (*cond_)(IT &it);
BODY &body_;
};
static inline void
wq_push_cpp(struct run_work *w)
{
w->run();
}
template <typename IT, typename BODY>
static void
wq_for_one(struct work *w, void *a0, void *a1, void *a2)
{
}
template <typename IT, typename BODY>
static inline void
wq_for(IT &init, bool (*cond)(IT &it), BODY body)
{
for_work<IT, BODY> goo(init, body);
wq_push_cpp(&goo);
#if 0
BODY foo = body;
// XXX(sbw) should be able to coarsen loop
for (IT &it = init; cond(it); ++it) {
foo(*it);
body(*it);
}
#endif
}
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论