Browse Source

[2836] Update Id generation

Use bigger type, check it never overflows.
Michal 'vorner' Vaner 12 years ago
parent
commit
61e6c39d6f

+ 8 - 2
src/lib/datasrc/memory/segment_object_holder.cc

@@ -16,6 +16,8 @@
 
 #include <boost/lexical_cast.hpp>
 
+#include <cassert>
+
 namespace isc {
 namespace datasrc {
 namespace memory {
@@ -23,9 +25,13 @@ namespace detail {
 
 std::string
 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 " +
-            boost::lexical_cast<std::string>(index ++));
+            boost::lexical_cast<std::string>(index));
 }
 
 }

+ 4 - 3
src/lib/datasrc/memory/segment_object_holder.h

@@ -27,9 +27,10 @@ namespace detail {
 // 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
 // momemnt. This just keeps incrementing number after a prefix with
-// each call, it should be enough (the holder should no longer be
-// alive when the counter wraps around, if that ever happens with
-// presumably 64bit counters).
+// each call, it should be enough (we assert it does not wrap around,
+// but 64bits should be enough).
+//
+// Also, it is not thread safe.
 std::string
 getNextHolderName();