Commit 89d448ea authored by Martin Marinov's avatar Martin Marinov

Add tick number counter in Progress::Node. Add Progress::Node track function...

Add tick number counter in Progress::Node. Add Progress::Node track function pointer type. Define the thread-local track function and active node pointers.
parent 15901e26
......@@ -5,3 +5,11 @@
#include "ProgressNode.hh"
#ifdef PROGRESS_ON
namespace Progress {
thread_local TrackFunction trck_fnct = nullptr;
thread_local Node* actv_node; // active node
} //namespace Progress
#endif//PROGRESS_ON
......@@ -6,6 +6,13 @@
#ifdef PROGRESS_ON
namespace Progress {
typedef unsigned long long TickNumber;
class Node;
typedef void (*TrackFunction)(Node* _node);
extern thread_local TrackFunction trck_fnct;
//! Represent an operational node in the progress graph
class Node
{
......@@ -14,12 +21,28 @@ public:
Node(const char* const _name,
Node* _next = nullptr, Node* _chld = nullptr)
: name(_name), next_(_next), chld_(_chld)
: name(_name), next_(_next), chld_(_chld),
tick_nmbr_max_(1000000000)
{}
void tick()
{
++tick_nmbr_;
if (trck_fnct != nullptr)
(*trck_fnct)(this);
}
TickNumber tick_number() const { return tick_nmbr_; }
TickNumber tick_number_max() const { return tick_nmbr_max_; }
double tick_percentage() const { return 100. * tick_nmbr_ / tick_nmbr_max_; }
protected:
Node* next_; //!< next node on the same level, last if nullptr
Node* chld_; //!< first child node, leaf if nullptr
private:
TickNumber tick_nmbr_;
TickNumber tick_nmbr_max_;
};
extern thread_local Node* actv_node; // active node
......@@ -58,6 +81,15 @@ inline Node* make_children_list(MakeNodeFunction _make_node_fnct,
Node* PROGRESS_MAKE_NODE_NAME(OPRT)(Node* _next = nullptr); \
} //namespace Progress {
#define PROGRESS_TICK(NODE) { if ((NODE) != nullptr) (NODE)->tick(); }
#define PROGRESS_ACTIVE_TICK PROGRESS_TICK(Progress::actv_node)
#else
#define PROGRESS_DECLARE_NODE(OPRT)
#define PROGRESS_DEFINE_NODE(OPRT, ...)
#endif// PROGRESS_ON
#endif//BASE_PROGRESS_NODE_HH_INCLUDED
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