diff --git a/include/boost/interprocess/detail/os_thread_functions.hpp b/include/boost/interprocess/detail/os_thread_functions.hpp index 46c47f18..22bb788a 100644 --- a/include/boost/interprocess/detail/os_thread_functions.hpp +++ b/include/boost/interprocess/detail/os_thread_functions.hpp @@ -161,6 +161,12 @@ inline OS_highres_count_t get_current_system_highres_count() return (OS_highres_count_t)count; } +inline unsigned get_current_system_highres_rand() +{ + unsigned __int64 count = (unsigned __int64) get_current_system_highres_count(); + return static_cast(count + (count >> 32u)); +} + inline void zero_highres_count(OS_highres_count_t &count) { count = 0; } @@ -354,6 +360,16 @@ inline OS_highres_count_t get_current_system_highres_count() #endif } +inline unsigned get_current_system_highres_rand() +{ + OS_highres_count_t count = get_current_system_highres_count(); + #if defined(BOOST_INTERPROCESS_CLOCK_MONOTONIC) + return static_cast(count.tv_sec + count.tv_nsec); + #elif defined(BOOST_INTERPROCESS_MATCH_ABSOLUTE_TIME) + return static_cast(count); + #endif +} + #ifndef BOOST_INTERPROCESS_MATCH_ABSOLUTE_TIME inline void zero_highres_count(OS_highres_count_t &count) diff --git a/test/managed_xsi_shared_memory_test.cpp b/test/managed_xsi_shared_memory_test.cpp index e5560743..4b2221dd 100644 --- a/test/managed_xsi_shared_memory_test.cpp +++ b/test/managed_xsi_shared_memory_test.cpp @@ -56,7 +56,8 @@ int main () file_mapping::remove(ShmemName); { ipcdetail::file_wrapper(create_only, ShmemName, read_write); } - xsi_key key(ShmemName, 1); + + xsi_key key(ShmemName, static_cast(boost::interprocess::ipcdetail::get_current_system_highres_rand())); file_mapping::remove(ShmemName); int shmid; diff --git a/test/xsi_shared_memory_mapping_test.cpp b/test/xsi_shared_memory_mapping_test.cpp index e18812c5..1521ab55 100644 --- a/test/xsi_shared_memory_mapping_test.cpp +++ b/test/xsi_shared_memory_mapping_test.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include "get_process_id_name.hpp" @@ -57,7 +58,7 @@ int main () file_mapping::remove(names[0]); { ipcdetail::file_wrapper(create_only, names[0], read_write); } - xsi_key key(names[0], 1); + xsi_key key(names[0], static_cast(boost::interprocess::ipcdetail::get_current_system_highres_rand())); file_mapping::remove(names[0]); remove_shared_memory(key);