-
Notifications
You must be signed in to change notification settings - Fork 0
/
synchronization.h
60 lines (55 loc) · 2.28 KB
/
synchronization.h
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
52
53
54
55
56
57
58
59
60
#pragma once
#include <cstdint>
namespace mx::synchronization {
/**
* Desired isolation level of a resource.
*/
enum class isolation_level : std::uint8_t
{
ExclusiveWriter = 0U, // Reads can be parallel, writes will be synchronized
Exclusive = 1U, // All accesses will be synchronized
None = 2U, // Nothing will be synchronized
};
/**
* Desired protocol of synchronization.
*/
enum class protocol : std::uint8_t
{
None = 0U, // System is free to choose
Queue = 1U, // Choose primitive with queues with respect to isolation level
Latch = 2U, // Choose primitive with latches with respect to isolation level
OLFIT = 3U, // Try to choose olfit
RestrictedTransactionalMemory = 4U, // Try to choose transactional memory
Batched = 5U, // Tasks are batched
};
/**
* Real method, based on the isolation level
* and decision by the tasking layer.
*
* Attention: Even if the primitive is 8bit long,
* it is stored within the tagged_ptr as
* using only 4bit! Therefore, the max.
* value can be 15.
*/
enum class primitive : std::uint8_t
{
None = 0U, // Nothing will be synchronized
ExclusiveLatch = 1U, // All accesses will use a spinlock
ScheduleAll = 2U, // All accesses will be scheduled to the mapped channel
ReaderWriterLatch = 3U, // Use a reader/writer latch to enable parallel reads
ScheduleWriter = 4U, // Reads can perform anywhere, writes are scheduled to the mapped channel
OLFIT = 5U, // Read/write anywhere but use a latch for writers
RestrictedTransactionalMemory = 6U, /// Read/write transactional
Batched = 7U // Tasks are batched by using task squads
};
/**
* Checks whether the given primitive is kind of optimistic synchronization
* or not.
* @param primitive_ Primitive to check.
* @return True, if the given primitive is optimistic.
*/
static inline bool is_optimistic(const primitive primitive_) noexcept
{
return primitive_ == primitive::ScheduleWriter || primitive_ == primitive::OLFIT;
}
} // namespace mx::synchronization