forframe -> wframe

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