1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
---|---|
2 | // Licensed under the MIT license. |
3 | |
4 | #pragma once |
5 | |
6 | #include <atomic> |
7 | #include <cassert> |
8 | #include <cstdint> |
9 | |
10 | namespace FASTER { |
11 | namespace core { |
12 | |
13 | /// State of the active grow-index call. |
14 | class GrowState { |
15 | public: |
16 | typedef void(*callback_t)(uint64_t new_size); |
17 | |
18 | GrowState() |
19 | : callback{ nullptr } |
20 | , num_pending_chunks{ 0 } |
21 | , old_version{ UINT8_MAX } |
22 | , new_version{ UINT8_MAX } { |
23 | } |
24 | |
25 | void Initialize(callback_t callback_, uint8_t current_version, uint64_t num_chunks_) { |
26 | callback = callback_; |
27 | assert(current_version == 0 || current_version == 1); |
28 | old_version = current_version; |
29 | new_version = 1 - current_version; |
30 | num_chunks = num_chunks_; |
31 | num_pending_chunks = num_chunks_; |
32 | next_chunk = 0; |
33 | } |
34 | |
35 | callback_t callback; |
36 | uint8_t old_version; |
37 | uint8_t new_version; |
38 | uint64_t num_chunks; |
39 | std::atomic<uint64_t> num_pending_chunks; |
40 | std::atomic<uint64_t> next_chunk; |
41 | }; |
42 | |
43 | } |
44 | } // namespace FASTER::core |
45 |