- virtual void printValue(std::ostream &o) const { o << Value; }
- virtual bool hasSomeData() const { return Value != DataType(); }
-public:
- // Normal constructor, default initialize data item...
- Statistic(const char *name, const char *desc)
- : StatisticBase(name, desc), Value(DataType()) {}
-
- // Constructor to provide an initial value...
- Statistic(const DataType &Val, const char *name, const char *desc)
- : StatisticBase(name, desc), Value(Val) {}
-
- // Print information when destroyed, iff command line option is specified
- ~Statistic() { destroy(); }
-
- // Allow use of this class as the value itself...
- operator DataType() const { return Value; }
- const Statistic &operator=(DataType Val) { Value = Val; return *this; }
- const Statistic &operator++() { ++Value; return *this; }
- DataType operator++(int) { return Value++; }
- const Statistic &operator--() { --Value; return *this; }
- DataType operator--(int) { return Value--; }
- const Statistic &operator+=(const DataType &V) { Value += V; return *this; }
- const Statistic &operator-=(const DataType &V) { Value -= V; return *this; }
- const Statistic &operator*=(const DataType &V) { Value *= V; return *this; }
- const Statistic &operator/=(const DataType &V) { Value /= V; return *this; }
+ const Statistic &operator+=(const unsigned &V) {
+ if (!V) return *this;
+ sys::AtomicAdd(&Value, V);
+ return init();
+ }
+
+ const Statistic &operator-=(const unsigned &V) {
+ if (!V) return *this;
+ sys::AtomicAdd(&Value, -V);
+ return init();
+ }
+
+ const Statistic &operator*=(const unsigned &V) {
+ sys::AtomicMul(&Value, V);
+ return init();
+ }
+
+ const Statistic &operator/=(const unsigned &V) {
+ sys::AtomicDiv(&Value, V);
+ return init();
+ }
+
+protected:
+ Statistic &init() {
+ bool tmp = Initialized;
+ sys::MemoryFence();
+ if (!tmp) RegisterStatistic();
+ TsanHappensAfter(this);
+ return *this;
+ }
+ void RegisterStatistic();