From eba52d720ca6c8c786ea46a2251584a948dd58a0 Mon Sep 17 00:00:00 2001 From: "Justin M. LaPre" Date: Mon, 5 Aug 2024 18:09:31 +0000 Subject: [PATCH] add globalCounter header --- src/sst/core/Makefile.am | 1 + src/sst/core/globalCounter.h | 53 ++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 src/sst/core/globalCounter.h diff --git a/src/sst/core/Makefile.am b/src/sst/core/Makefile.am index 3114200af..504618912 100644 --- a/src/sst/core/Makefile.am +++ b/src/sst/core/Makefile.am @@ -42,6 +42,7 @@ nobase_dist_sst_HEADERS = \ exit.h \ factory.h \ from_string.h \ + globalCounter.h \ heartbeat.h \ initQueue.h \ link.h \ diff --git a/src/sst/core/globalCounter.h b/src/sst/core/globalCounter.h new file mode 100644 index 000000000..a3a7890a6 --- /dev/null +++ b/src/sst/core/globalCounter.h @@ -0,0 +1,53 @@ +// Copyright 2009-2024 NTESS. Under the terms +// of Contract DE-NA0003525 with NTESS, the U.S. +// Government retains certain rights in this software. +// +// Copyright (c) 2009-2024, NTESS +// All rights reserved. +// +// This file is part of the SST software package. For license +// information, see the LICENSE file in the top level directory of the +// distribution. + +#ifndef SST_GLOBAL_COUNTER_H +#define SST_GLOBAL_COUNTER_H + +#include +#include +#include + +namespace SST { + +template +class GlobalCounter +{ + T counter; + const T min; + const T max; + +public: + static_assert(std::is_integral::value, "integral required"); + + GlobalCounter(T initial = 0) : min(std::numeric_limits::lowest()), max(std::numeric_limits::max()) + { + counter = initial; + } + + void increment() + { + if ( counter == max ) { return; } + ++counter; + } + + void decrement() + { + if ( counter == min ) { return; } + --counter; + } + + friend bool operator<(const GlobalCounter& l, const GlobalCounter& r) { return l.counter < r.counter; } +}; + +} // namespace SST + +#endif /* SST_GLOBAL_COUNTER_H */