| 1 |
|
|
1 |
|
|
| 2 |
|
// Copyright (c) 2026 Michael Vandeberg
|
2 |
|
// Copyright (c) 2026 Michael Vandeberg
|
| 3 |
|
|
3 |
|
|
| 4 |
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
4 |
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
| 5 |
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
5 |
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
| 6 |
|
|
6 |
|
|
| 7 |
|
// Official repository: https://github.com/cppalliance/capy
|
7 |
|
// Official repository: https://github.com/cppalliance/capy
|
| 8 |
|
|
8 |
|
|
| 9 |
|
|
9 |
|
|
| 10 |
|
#ifndef BOOST_CAPY_DETAIL_SERVICE_SLOT_HPP
|
10 |
|
#ifndef BOOST_CAPY_DETAIL_SERVICE_SLOT_HPP
|
| 11 |
|
#define BOOST_CAPY_DETAIL_SERVICE_SLOT_HPP
|
11 |
|
#define BOOST_CAPY_DETAIL_SERVICE_SLOT_HPP
|
| 12 |
|
|
12 |
|
|
| 13 |
|
|
13 |
|
|
| 14 |
|
|
14 |
|
|
| 15 |
|
|
15 |
|
|
| 16 |
|
|
16 |
|
|
| 17 |
|
|
17 |
|
|
| 18 |
|
|
18 |
|
|
| 19 |
|
|
19 |
|
|
| 20 |
|
/* Slot ID infrastructure for O(1) service lookup.
|
20 |
|
/* Slot ID infrastructure for O(1) service lookup.
|
| 21 |
|
|
21 |
|
|
| 22 |
|
Each distinct service type T gets a unique integer index via
|
22 |
|
Each distinct service type T gets a unique integer index via
|
| 23 |
|
service_slot<T>(). The index is assigned on first call from a
|
23 |
|
service_slot<T>(). The index is assigned on first call from a
|
| 24 |
|
global atomic counter and cached in a function-local static.
|
24 |
|
global atomic counter and cached in a function-local static.
|
| 25 |
|
Cross-DLL safety relies on COMDAT deduplication (same mechanism
|
25 |
|
Cross-DLL safety relies on COMDAT deduplication (same mechanism
|
| 26 |
|
as type_id_impl<T>::tag).
|
26 |
|
as type_id_impl<T>::tag).
|
| 27 |
|
|
27 |
|
|
| 28 |
|
|
28 |
|
|
| 29 |
|
inline std::atomic<std::size_t> next_service_slot{0};
|
29 |
|
inline std::atomic<std::size_t> next_service_slot{0};
|
| 30 |
|
|
30 |
|
|
| 31 |
|
|
31 |
|
|
| 32 |
|
|
32 |
|
|
| 33 |
|
|
33 |
|
|
| 34 |
|
|
34 |
|
|
| 35 |
|
static const std::size_t id =
|
35 |
|
static const std::size_t id =
|
| 36 |
|
next_service_slot.fetch_add(1, std::memory_order_relaxed);
|
36 |
|
next_service_slot.fetch_add(1, std::memory_order_relaxed);
|
| 37 |
|
|
37 |
|
|
| 38 |
|
|
38 |
|
|
| 39 |
|
|
39 |
|
|
| 40 |
|
|
40 |
|
|
| 41 |
|
|
41 |
|
|
| 42 |
|
|
42 |
|
|
| 43 |
|
|
43 |
|
|
| 44 |
|
|
44 |
|
|