Commit 7853bcf2 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Ok fine, a vector of std::atomic is not safe.

parent 18f9e7e0
......@@ -22,7 +22,6 @@ namespace pyston {
#if !DISABLE_STATS
std::vector<long>* Stats::counts;
std::vector<std::atomic<long> >* Stats::threadsafe_counts;
std::unordered_map<int, std::string>* Stats::names;
StatCounter::StatCounter(const std::string& name) : id(Stats::getStatId(name)) {
}
......@@ -39,8 +38,6 @@ int Stats::getStatId(const std::string& name) {
Stats::names = &names;
static std::vector<long> counts;
Stats::counts = &counts;
static std::vector<std::atomic<long> > threadsafe_counts;
Stats::threadsafe_counts = &threadsafe_counts;
static std::unordered_map<std::string, int> made;
if (made.count(name))
......@@ -50,7 +47,6 @@ int Stats::getStatId(const std::string& name) {
names[rtn] = name;
made[name] = rtn;
counts.push_back(0);
threadsafe_counts.emplace_back(0);
return rtn;
}
......@@ -65,7 +61,7 @@ void Stats::dump() {
std::sort(pairs.begin(), pairs.end());
for (int i = 0; i < pairs.size(); i++) {
printf("%s: %ld\n", pairs[i].first.c_str(), (*counts)[pairs[i].second] + (*threadsafe_counts)[pairs[i].second]);
printf("%s: %ld\n", pairs[i].first.c_str(), (*counts)[pairs[i].second]);
}
}
......
......@@ -31,16 +31,12 @@ namespace pyston {
struct Stats {
private:
static std::vector<long>* counts;
static std::vector<std::atomic<long> >* threadsafe_counts;
static std::unordered_map<int, std::string>* names;
public:
static int getStatId(const std::string& name);
static void log(int id, int count = 1) { (*counts)[id] += count; }
static void threadsafe_log(int id, int count = 1) {
(*threadsafe_counts)[id].fetch_add(count, std::memory_order_relaxed);
}
static void dump();
};
......@@ -53,7 +49,6 @@ public:
StatCounter(const std::string& name);
void log(int count = 1) { Stats::log(id, count); }
void threadsafe_log(int count = 1) { Stats::threadsafe_log(id, count); }
};
struct StatPerThreadCounter {
......@@ -64,7 +59,6 @@ public:
StatPerThreadCounter(const std::string& name);
void log(int count = 1) { Stats::log(id, count); }
void threadsafe_log(int count = 1) { Stats::threadsafe_log(id, count); }
};
#else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment