forframe -> wframe

上级 8f88035a
......@@ -15,7 +15,7 @@
}
struct testwork : public work {
testwork(forframe *b) : barrier_(b) {}
testwork(wframe *b) : barrier_(b) {}
virtual void run() {
barrier_->dec();
......@@ -23,14 +23,14 @@ struct testwork : public work {
}
NEW_DELETE_OPS(testwork);
struct forframe *barrier_;
struct wframe *barrier_;
};
static void
test0(void)
{
enum { pushes = 100 };
struct forframe wqbarrier(pushes);
struct wframe wqbarrier(pushes);
printf("test0...\n");
for (int i = 0; i < pushes; i++) {
......@@ -44,7 +44,7 @@ test0(void)
}
struct forkwork : public work {
forkwork(forframe *b) : barrier_(b) {}
forkwork(wframe *b) : barrier_(b) {}
virtual void run() {
int pid;
......@@ -61,14 +61,14 @@ struct forkwork : public work {
}
NEW_DELETE_OPS(forkwork);
struct forframe *barrier_;
struct wframe *barrier_;
};
static void
testfork(void)
{
enum { forks = 100 };
struct forframe wqbarrier(forks);
struct wframe wqbarrier(forks);
printf("testfork...\n");
for (int i = 0; i < forks; i++) {
......@@ -82,7 +82,7 @@ testfork(void)
}
struct execwork : public work {
execwork(forframe *b) : barrier_(b) {}
execwork(wframe *b) : barrier_(b) {}
virtual void run() {
int pid;
......@@ -103,7 +103,7 @@ struct execwork : public work {
static void test(void) {
enum { execs = 100 };
struct forframe wqbarrier(execs);
struct wframe wqbarrier(execs);
printf("testexec...\n");
for (int i = 0; i < execs; i++) {
......@@ -117,7 +117,7 @@ struct execwork : public work {
}
NEW_DELETE_OPS(execwork);
struct forframe *barrier_;
struct wframe *barrier_;
};
int
......
......@@ -29,6 +29,14 @@ struct cwork : public work {
void *arg4;
};
struct wframe {
wframe(int v) : v_(v) {}
int inc() { return __sync_add_and_fetch(&v_, 1); }
int dec() { return __sync_sub_and_fetch(&v_, 1); }
bool zero() volatile { return v_ == 0; };
volatile int v_;
};
#if defined(LINUX)
#include <stdlib.h>
#include <assert.h>
......
struct forframe
{
forframe(int v) : v_(v) {}
int inc() { return __sync_add_and_fetch(&v_, 1); }
int dec() { return __sync_sub_and_fetch(&v_, 1); }
bool zero() volatile { return v_ == 0; };
volatile int v_;
};
template <typename IT, typename BODY>
struct forwork : public work {
forwork(IT &it, bool (*cond)(IT &it), BODY &body, forframe &frame)
forwork(IT &it, bool (*cond)(IT &it), BODY &body, wframe &frame)
: it_(it), cond_(cond), body_(body), frame_(frame) {}
virtual void run() {
......@@ -38,14 +29,14 @@ struct forwork : public work {
IT &it_;
bool (*cond_)(IT&);
BODY &body_;
forframe &frame_;
wframe &frame_;
};
template <typename IT, typename BODY>
static inline void
wq_for(IT &init, bool (*cond)(IT &it), BODY body)
{
forframe frame(0);
wframe frame(0);
// XXX(sbw) should be able to coarsen loop
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论