Commit 0f034e2e authored by Sergey Vojtovich's avatar Sergey Vojtovich

time_collector transition to std::atomic

parent 1e7df0e5
...@@ -147,42 +147,36 @@ void print_time(char* buffer, std::size_t buffer_size, const char* format, ...@@ -147,42 +147,36 @@ void print_time(char* buffer, std::size_t buffer_size, const char* format,
class time_collector class time_collector
{ {
utility *m_utility;
Atomic_counter<uint32_t> m_count[OVERALL_POWER_COUNT + 1];
Atomic_counter<uint64_t> m_total[OVERALL_POWER_COUNT + 1];
public: public:
time_collector(utility& u) : m_utility(&u) time_collector(utility& u): m_utility(&u) { flush(); }
{ } ~time_collector() { }
~time_collector() uint32_t count(uint index) { return m_count[index]; }
{ } uint64_t total(uint index) { return m_total[index]; }
uint32 count(uint index)
{
return my_atomic_load32((int32*)&m_count[index]);
}
uint64 total(uint index)
{
return my_atomic_load64((int64*)&m_total[index]);
}
public:
void flush() void flush()
{ {
memset((void*)&m_count,0,sizeof(m_count)); for (auto i= 0; i < OVERALL_POWER_COUNT + 1; i++)
memset((void*)&m_total,0,sizeof(m_total)); {
m_count[i]= 0;
m_total[i]= 0;
}
} }
void collect(uint64 time) void collect(uint64_t time)
{ {
int i= 0; int i= 0;
for(int count= m_utility->bound_count(); count > i; ++i) for(int count= m_utility->bound_count(); count > i; ++i)
{ {
if(m_utility->bound(i) > time) if(m_utility->bound(i) > time)
{ {
my_atomic_add32((int32*)(&m_count[i]), 1); m_count[i]++;
my_atomic_add64((int64*)(&m_total[i]), time); m_total[i]+= time;
break; break;
} }
} }
} }
private:
utility* m_utility;
uint32 m_count[OVERALL_POWER_COUNT + 1];
uint64 m_total[OVERALL_POWER_COUNT + 1];
}; };
class collector class collector
...@@ -191,7 +185,6 @@ class collector ...@@ -191,7 +185,6 @@ class collector
collector() : m_time(m_utility) collector() : m_time(m_utility)
{ {
m_utility.setup(DEFAULT_BASE); m_utility.setup(DEFAULT_BASE);
m_time.flush();
} }
public: public:
void flush() void flush()
......
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