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 */