Add include/reducer.hh for reducer definitions

上级 c95b8ebf
...@@ -13,6 +13,7 @@ typedef uint64_t u64; ...@@ -13,6 +13,7 @@ typedef uint64_t u64;
#include "include/wq.hh" #include "include/wq.hh"
#include "user/dirit.hh" #include "user/dirit.hh"
#include "include/percpu.hh" #include "include/percpu.hh"
#include "include/reducer.hh"
#define ST_SIZE(st) (st).st_size #define ST_SIZE(st) (st).st_size
#define ST_ISDIR(st) S_ISDIR((st).st_mode) #define ST_ISDIR(st) S_ISDIR((st).st_mode)
#define BSIZ 256 #define BSIZ 256
...@@ -28,36 +29,13 @@ typedef uint64_t u64; ...@@ -28,36 +29,13 @@ typedef uint64_t u64;
#include "wq.hh" #include "wq.hh"
#include "dirit.hh" #include "dirit.hh"
#include "percpu.hh" #include "percpu.hh"
#include "reducer.hh"
#define ST_SIZE(st) (st).size #define ST_SIZE(st) (st).size
#define ST_ISDIR(st) ((st).type == T_DIR) #define ST_ISDIR(st) ((st).type == T_DIR)
#define stderr 2 #define stderr 2
#define BSIZ (DIRSIZ+1) #define BSIZ (DIRSIZ+1)
#endif #endif
template <typename T>
struct reducer_opadd
{
reducer_opadd(T v) {
for (int i = 0; i < NCPU; i++)
v_[i] = 0;
*v_ = v;
}
T operator+=(T i) {
(*v_) += i;
return *v_;
}
T get_value() {
T t = 0;
for (int i = 0; i < NCPU; i++)
t += v_[i];
return t;
}
percpu<T> v_;
};
static size_t static size_t
du(int fd) du(int fd)
{ {
......
template <typename T>
struct reducer_opadd
{
reducer_opadd(T v) {
for (int i = 0; i < NCPU; i++)
v_[i] = 0;
*v_ = v;
}
T operator+=(T i) {
(*v_) += i;
return *v_;
}
T get_value() {
T t = 0;
for (int i = 0; i < NCPU; i++)
t += v_[i];
return t;
}
percpu<T> v_;
};
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论