Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add globalCounter class #1116

Draft
wants to merge 1 commit into
base: devel
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/sst/core/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ nobase_dist_sst_HEADERS = \
exit.h \
factory.h \
from_string.h \
globalCounter.h \
heartbeat.h \
initQueue.h \
link.h \
Expand Down
53 changes: 53 additions & 0 deletions src/sst/core/globalCounter.h
Original file line number Diff line number Diff line change
@@ -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 <limits>
#include <sys/types.h>
#include <type_traits>

namespace SST {

template <typename T = u_int64_t>
class GlobalCounter
{
T counter;
const T min;
const T max;

public:
static_assert(std::is_integral<T>::value, "integral required");

GlobalCounter(T initial = 0) : min(std::numeric_limits<T>::lowest()), max(std::numeric_limits<T>::max())
{
counter = initial;
}

void increment()
{
if ( counter == max ) { return; }
++counter;
}

void decrement()
{
if ( counter == min ) { return; }
--counter;
}

friend bool operator<(const GlobalCounter<T>& l, const GlobalCounter<T>& r) { return l.counter < r.counter; }
};

} // namespace SST

#endif /* SST_GLOBAL_COUNTER_H */
Loading