From 3b96742cf41a1c7be6f80d507683553cfe37217b Mon Sep 17 00:00:00 2001 From: "ben.copley" Date: Tue, 11 Oct 2022 14:43:05 +0100 Subject: [PATCH] Making clock type definitions private (#66) --- src/c++/clock.cpp | 2 +- src/c++/clock.h | 18 ++++++++++-------- src/c++/hashtable.cpp | 10 +++++----- src/c++/hashtable.h | 10 +++++----- src/c++/profiler.cpp | 2 +- src/c++/profiler.h | 4 ++-- 6 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/c++/clock.cpp b/src/c++/clock.cpp index ab502a06..3b421f51 100644 --- a/src/c++/clock.cpp +++ b/src/c++/clock.cpp @@ -1,6 +1,6 @@ #include "clock.h" -Clock::time_point_t Clock::now() +Clock::timepoint_t Clock::now() { return std::chrono::steady_clock::now(); } \ No newline at end of file diff --git a/src/c++/clock.h b/src/c++/clock.h index 61c6575c..e27d1217 100644 --- a/src/c++/clock.h +++ b/src/c++/clock.h @@ -6,16 +6,18 @@ class Clock{ Clock() = delete; - // Type definitions for chrono steady clock time points and durations - using time_duration_t = std::chrono::duration; - using time_point_t = std::chrono::time_point; - private: + // Type definitions for chrono steady clock time points and durations + using duration_t = std::chrono::duration; + using timepoint_t = std::chrono::time_point; + // Member functions - static time_point_t now(); + static timepoint_t now(); - // Makes sure Clock::now() is only usable by Profiler and is otherwise - // private. - friend class Profiler; + // Makes sure Clock::now() and the type definitions are only usable by + // its friend classes + friend class Profiler; + friend class HashTable; + friend struct HashEntry; }; \ No newline at end of file diff --git a/src/c++/hashtable.cpp b/src/c++/hashtable.cpp index 9f8cd0b5..13d61d59 100644 --- a/src/c++/hashtable.cpp +++ b/src/c++/hashtable.cpp @@ -18,9 +18,9 @@ HashEntry::HashEntry(std::string_view region_name) : region_name_(region_name) - , total_walltime_(Clock::time_duration_t::zero()) - , self_walltime_(Clock::time_duration_t::zero()) - , child_walltime_(Clock::time_duration_t::zero()) + , total_walltime_(Clock::duration_t::zero()) + , self_walltime_(Clock::duration_t::zero()) + , child_walltime_(Clock::duration_t::zero()) , call_count_(0) {} @@ -55,7 +55,7 @@ size_t HashTable::query_insert(std::string_view region_name) noexcept * */ -void HashTable::update(size_t hash, Clock::time_duration_t time_delta) +void HashTable::update(size_t hash, Clock::duration_t time_delta) { // Assertions assert (table_.size() > 0); @@ -74,7 +74,7 @@ void HashTable::update(size_t hash, Clock::time_duration_t time_delta) * */ -void HashTable::add_child_time(size_t hash, Clock::time_duration_t time_delta) +void HashTable::add_child_time(size_t hash, Clock::duration_t time_delta) { // Assertions assert (table_.size() > 0); diff --git a/src/c++/hashtable.h b/src/c++/hashtable.h index 63bf1ec3..eec3e880 100644 --- a/src/c++/hashtable.h +++ b/src/c++/hashtable.h @@ -47,9 +47,9 @@ struct HashEntry{ // Data members std::string region_name_; - Clock::time_duration_t total_walltime_; - Clock::time_duration_t self_walltime_; - Clock::time_duration_t child_walltime_; + Clock::duration_t total_walltime_; + Clock::duration_t self_walltime_; + Clock::duration_t child_walltime_; unsigned long long int call_count_; }; @@ -80,12 +80,12 @@ class HashTable{ // Prototypes size_t query_insert(std::string_view) noexcept; - void update(size_t, Clock::time_duration_t); + void update(size_t, Clock::duration_t); void write(); // Member functions std::vector list_keys(); - void add_child_time(size_t, Clock::time_duration_t); + void add_child_time(size_t, Clock::duration_t); void compute_self_times(); // Getters diff --git a/src/c++/profiler.cpp b/src/c++/profiler.cpp index 46c5ee2c..6b5d5a1f 100644 --- a/src/c++/profiler.cpp +++ b/src/c++/profiler.cpp @@ -29,7 +29,7 @@ Profiler::Profiler(){ HashTable new_table(tid); thread_hashtables_.push_back(new_table); - std::vector> new_list; + std::vector> new_list; thread_traceback_.push_back(new_list); } diff --git a/src/c++/profiler.h b/src/c++/profiler.h index 96624d72..f095d4c7 100644 --- a/src/c++/profiler.h +++ b/src/c++/profiler.h @@ -39,11 +39,11 @@ class Profiler // Data members int max_threads_; std::vector thread_hashtables_; - std::vector>> thread_traceback_; + std::vector>> thread_traceback_; // Type definitions for vector array indexing. typedef std::vector::size_type hashtable_iterator_t_; - typedef std::vector>>::size_type pair_iterator_t_; + typedef std::vector>>::size_type pair_iterator_t_; public: