-
Notifications
You must be signed in to change notification settings - Fork 0
/
SequenceGroup.h
73 lines (59 loc) · 2.6 KB
/
SequenceGroup.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
61
62
63
64
65
66
67
68
69
70
71
72
73
//
// Created by ubuntu on 17-11-19.
//
#ifndef DISRUPTOR_PP_SEQUENCEGROUP_H
#define DISRUPTOR_PP_SEQUENCEGROUP_H
#include <cstdint>
#include <atomic>
#include <vector>
#include "Interfaces/ISequence.h"
#include "Interfaces/ICursored.h"
#include "Util/Utils.h"
#include "SequenceArrayWrapper.h"
#include "SequenceGroups.h"
#include "Sequence.h"
namespace Disruptor {
/// <summary>
/// A <see cref="Sequence"/> group that can dynamically have <see cref="Sequence"/>s added and removed while being
/// thread safe.
///
/// The <see cref="SequenceGroup.Value"/> get and set methods are lock free and can be
/// concurrently called with the <see cref="SequenceGroup.Add"/> and <see cref="SequenceGroup.Remove"/>.
/// </summary>
class SequenceGroup : public Interfaces::ISequence {
private:
//std::atomic
std::atomic<SequenceArrayWrapper> _seqArrWrpr;
public:
int64_t GetValue() override;
void SetValue(const int64_t& value) override;
bool CompareAndSet(int64_t& expectedSequence, int64_t& nextSequence) override;
int64_t IncrementAndGet() override;
int64_t AddAndGet(const int64_t& val) override;
/// <summary>
/// Add a <see cref="Sequence"/> into this aggregate. This should only be used during
/// initialisation. Use <see cref="SequenceGroup.AddWhileRunning"/>.
/// </summary>
/// <param name="sequence">sequence to be added to the aggregate.</param>
void Add(Interfaces::ISequence* sequence);
/// <summary>
/// Remove the first occurrence of the <see cref="Sequence"/> from this aggregate.
/// </summary>
/// <param name="sequence">sequence to be removed from this aggregate.</param>
/// <returns>true if the sequence was removed otherwise false.</returns>
bool Remove(Interfaces::ISequence* sequence);
/// <summary>
/// Get the size of the group.
/// </summary>
int Size();
/// <summary>
/// Adds a sequence to the sequence group after threads have started to publish to
/// the Disruptor.It will set the sequences to cursor value of the ringBuffer
/// just after adding them. This should prevent any nasty rewind/wrapping effects.
/// </summary>
/// <param name="cursored">The data structure that the owner of this sequence group will be pulling it's events from</param>
/// <param name="sequence">The sequence to add</param>
void AddWhileRunning(Interfaces::ICursored* cursored, Interfaces::ISequence* sequence);
};
}
#endif //DISRUPTOR_PP_SEQUENCEGROUP_H