Commit 61e6c39d authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

[2836] Update Id generation

Use bigger type, check it never overflows.
parent 598d81ec
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <cassert>
namespace isc { namespace isc {
namespace datasrc { namespace datasrc {
namespace memory { namespace memory {
...@@ -23,9 +25,13 @@ namespace detail { ...@@ -23,9 +25,13 @@ namespace detail {
std::string std::string
getNextHolderName() { getNextHolderName() {
static size_t index = 0; static uint64_t index = 0;
++index;
// in practice we should be able to assume this, uint64 is large
// and should not overflow
assert(index != 0);
return ("Segment object holder auto name " + return ("Segment object holder auto name " +
boost::lexical_cast<std::string>(index ++)); boost::lexical_cast<std::string>(index));
} }
} }
......
...@@ -27,9 +27,10 @@ namespace detail { ...@@ -27,9 +27,10 @@ namespace detail {
// Internal function to get next yet unused name of segment holder. // Internal function to get next yet unused name of segment holder.
// We need the names of holders to be unique per segment at any given // We need the names of holders to be unique per segment at any given
// momemnt. This just keeps incrementing number after a prefix with // momemnt. This just keeps incrementing number after a prefix with
// each call, it should be enough (the holder should no longer be // each call, it should be enough (we assert it does not wrap around,
// alive when the counter wraps around, if that ever happens with // but 64bits should be enough).
// presumably 64bit counters). //
// Also, it is not thread safe.
std::string std::string
getNextHolderName(); getNextHolderName();
......
Supports Markdown
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