The open source OpenXR runtime
at prediction-2 26 lines 708 B view raw
1// Copyright 2023, Collabora, Ltd. 2// SPDX-License-Identifier: BSL-1.0 3/*! 4 * @file 5 * @brief A very simple generator to create process unique ids. 6 * @author Jakob Bornecrantz <jakob@collabora.com> 7 * @ingroup aux_util 8 */ 9 10#include "u_limited_unique_id.h" 11 12#include <atomic> 13 14 15/* 16 * This code is in C++ and not C because MSVC doesn't implement C atomics yet, 17 * but to make things even more fun the C++11 standard defines atomic_uint64_t 18 * as optional, but atomic_uint_fast64_t is listed as required, so here we are. 19 */ 20static std::atomic_uint_fast64_t generator; 21 22extern "C" xrt_limited_unique_id_t 23u_limited_unique_id_get(void) 24{ 25 return xrt_limited_unique_id_t{static_cast<uint64_t>(++generator)}; 26}