Shamrock
2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
shambase
include
shambase
WithUUID.hpp
Go to the documentation of this file.
1
// -------------------------------------------------------//
2
//
3
// SHAMROCK code for hydrodynamics
4
// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5
// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6
// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7
//
8
// -------------------------------------------------------//
9
10
#pragma once
11
17
18
#include <atomic>
19
20
namespace
shambase
{
21
36
template
<
typename
T,
class
T
int
,
bool
thread_safe = true>
37
class
WithUUID
{
38
39
protected
:
43
Tint
uuid
;
44
45
public
:
51
inline
Tint
get_uuid
()
const
{
return
uuid
; }
52
58
inline
WithUUID
() {
59
if
constexpr
(thread_safe) {
60
// local atomic static storage for the UUID
61
static
std::atomic<Tint> _uuid = 0;
62
// increment and store the UUID (atomic)
63
uuid
= _uuid.fetch_add(1, std::memory_order_relaxed);
64
}
else
{
65
// we need to redo the static storage in this case otherwise
66
// some lock xadd would be emitted as std::atomic is thread safe.
67
static
Tint _uuid = 0;
68
uuid
= _uuid++;
69
}
70
}
71
};
72
73
}
// namespace shambase
shambase::WithUUID::WithUUID
WithUUID()
Constructor of the class.
Definition
WithUUID.hpp:58
shambase::WithUUID::get_uuid
Tint get_uuid() const
Get the uuid of the class.
Definition
WithUUID.hpp:51
shambase::WithUUID::uuid
Tint uuid
The unique identifier of the class.
Definition
WithUUID.hpp:43
shambase
namespace for basic c++ utilities
Definition
sycl_builtins.hpp:25
Generated on
for Shamrock by
1.15.0