diff --git a/typeidx.cpp b/typeidx.cpp index 03b0fd59..6bb861f1 100644 --- a/typeidx.cpp +++ b/typeidx.cpp @@ -16,11 +16,12 @@ #include "typeidx.hpp" +#include /////////////////////////////////////////////////////////////////////////////// -std::uintptr_t +int util::detail::typeidx_next () { - static std::uintptr_t counter = 0; + static std::atomic counter = 0; return counter++; } diff --git a/typeidx.hpp b/typeidx.hpp index 31a5c849..21a162f1 100644 --- a/typeidx.hpp +++ b/typeidx.hpp @@ -20,7 +20,7 @@ #include namespace util { - namespace detail { std::uintptr_t typeidx_next (void); } + namespace detail { int typeidx_next (void); } /// return a globally unique runtime ID for a given type. /// @@ -29,13 +29,13 @@ namespace util { /// /// the identifier is constructed at runtime and is not guaranteed to be /// stable across executions (particularly in the case of threads and - /// other non-determinism). + /// other non-determinism). however it _is_ threadsafe to call this. /// /// the range of identifiers is _probably_ contiguous starting from zero. /// this should not be relied upon for correctness, but may be used for /// performance concerns. template - std::uintptr_t + int typeidx (void) { static auto id = detail::typeidx_next ();