blob: 53ab661ec8f5f2d61966190422bae60c90e18850 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
// SPDX-License-Identifier: Apache-2.0
// Copyright 2024-2026, Amlal El Mahrouss (amlal@nekernel.org)
// Licensed under the Apache License, Version 2.0 (see LICENSE file)
// Official repository: https://github.com/ne-foss-org/nekernel
#ifndef NEKIT_ATOM_H
#define NEKIT_ATOM_H
#include <NeKit/Config.h>
namespace Kernel {
template <class AtomicType>
class Atom final {
public:
explicit Atom() = default;
~Atom() = default;
public:
Atom& operator=(const Atom&) = delete;
Atom(const Atom&) = delete;
public:
using Type = AtomicType;
using Ref = AtomicType&;
using ConstRef = const AtomicType&;
const AtomicType& operator[](const AtomicType& bit) {
return (fArrayOfAtoms & (AtomicType{} << bit));
}
void operator|(const AtomicType& bit) { fArrayOfAtoms |= (AtomicType{1} << bit); }
Atom& operator|=(const AtomicType& bit) {
this->operator|(bit);
return *this;
}
friend bool operator==(Atom<AtomicType>& atomic, const AtomicType& idx) {
return atomic[idx] == idx;
}
friend bool operator!=(Atom<AtomicType>& atomic, const AtomicType& idx) {
return atomic[idx] != idx;
}
private:
AtomicType fArrayOfAtoms;
};
} // namespace Kernel
#endif
|