Enable generator tests on Windows CI

- Reduce included windows headers
- Reduce scope of time-generator dependencies
This commit is contained in:
Tushar Maheshwari 2021-06-16 01:17:56 +05:30
parent 297cd66004
commit 85c8e28973
3 changed files with 18 additions and 22 deletions

View File

@ -4,6 +4,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
option(UUID_BUILD_TESTS "Build the unit tests" ON)
option(UUID_SYSTEM_GENERATOR "Enable operating system uuid generator" OFF)
option(UUID_TIME_GENERATOR "Enable experimental time-based uuid generator" OFF)
option(UUID_USING_CXX20_SPAN "Using span from std instead of gsl" OFF)
# Library target
@ -29,6 +30,11 @@ if (UUID_SYSTEM_GENERATOR)
endif ()
endif ()
# Using time-based generator
if (UUID_TIME_GENERATOR)
target_compile_definitions(${PROJECT_NAME} INTERFACE UUID_TIME_GENERATOR)
endif()
# Using span from std
if (NOT UUID_USING_CXX20_SPAN)
target_include_directories(${PROJECT_NAME} INTERFACE

View File

@ -9,13 +9,14 @@ environment:
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
CMAKE_GENERATOR: Visual Studio 15 2017
CMAKE_GENERATOR_PLATFORM: x64
CMAKE_CLI_FLAGS: -DUUID_SYSTEM_GENERATOR=ON -DUUID_TIME_GENERATOR=ON
init:
- cmake --version
- msbuild /version
before_build:
- cmake -S . -B build
- cmake %CMAKE_CLI_FLAGS% -S . -B build
- cd build
build_script:

View File

@ -17,23 +17,16 @@
#include <atomic>
#include <span>
#if defined(UUID_TIME_GENERATOR) || defined(UUID_SYSTEM_GENERATOR)
#ifdef _WIN32
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#ifndef NOMINMAX
#define NOMINMAX
#endif
#ifdef UUID_SYSTEM_GENERATOR
#include <objbase.h>
#endif
#include <windows.h>
#include <intrin.h>
#ifdef UUID_TIME_GENERATOR
#include <iphlpapi.h>
#pragma comment(lib, "IPHLPAPI.lib")
#endif
#elif defined(__linux__) || defined(__unix__)
@ -47,7 +40,6 @@
#include <CoreFoundation/CFUUID.h>
#endif
#endif
#endif
namespace uuids
@ -278,10 +270,6 @@ namespace uuids
size_t m_blockByteIndex;
size_t m_byteCount;
};
static std::mt19937 clock_gen(std::random_device{}());
static std::uniform_int_distribution<short> clock_dis{ -32768, 32767 };
static std::atomic_short clock_sequence = clock_dis(clock_gen);
}
// --------------------------------------------------------------------------------------------------------------------------
@ -847,11 +835,15 @@ namespace uuids
return ns / 100;
}
public:
uuid_time_generator()
static short get_clock_sequence()
{
static std::mt19937 clock_gen(std::random_device{}());
static std::uniform_int_distribution<short> clock_dis{ -32768, 32767 };
static std::atomic_short clock_sequence = clock_dis(clock_gen);
return clock_sequence++;
}
public:
uuid operator()()
{
if (get_mac_address())
@ -860,12 +852,9 @@ namespace uuids
auto tm = get_time_intervals();
short clock_seq = detail::clock_sequence++;
clock_seq &= 0x3FFF;
short clock_seq = get_clock_sequence();
auto ptm = reinterpret_cast<uuids::uuid::value_type*>(&tm);
ptm[0] &= 0x0F;
memcpy(&data[0], ptm + 4, 4);
memcpy(&data[4], ptm + 2, 2);
@ -878,7 +867,7 @@ namespace uuids
data[8] |= 0x80;
// version must be 0b0001xxxx
data[6] &= 0x5F;
data[6] &= 0x1F;
data[6] |= 0x10;
memcpy(&data[10], &device_address.value()[0], 6);