storage/nvm/pet_kv/shm_common.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | #include <functional> | ||
| 3 | |||
| 4 | #include "base/async_time.h" | ||
| 5 | #include "memory/malloc.h" | ||
| 6 | #include "storage/nvm/pet_kv/persistence.h" | ||
| 7 | namespace base { | ||
| 8 | |||
| 9 | typedef std::function<uint64()> TimestampGetter; | ||
| 10 | |||
| 11 | struct PetKVReadData { | ||
| 12 | uint32 expire_timet = 0; | ||
| 13 | const char* data = nullptr; | ||
| 14 | int size = 0; | ||
| 15 | }; | ||
| 16 | |||
| 17 | #pragma pack(push, 1) | ||
| 18 | struct PetKVData { | ||
| 19 | struct Config { | ||
| 20 | uint64_t kExpireReductBit; | ||
| 21 | uint64_t kExpireReductMark; | ||
| 22 | uint64_t kExpireBit; | ||
| 23 | uint64_t kExpireMark; | ||
| 24 | uint64_t kNoMallocOffset; | ||
| 25 | 10 | explicit Config(int offset_bit = 32) { | |
| 26 |
1/6✗ Branch 3 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
10 | CHECK_GE(offset_bit, 32); |
| 27 | 10 | kExpireBit = 64 - offset_bit; | |
| 28 | 10 | kExpireReductBit = 32 - kExpireBit; | |
| 29 | 10 | kExpireMark = (1LL << kExpireBit) - 1; | |
| 30 | 10 | kExpireReductMark = (1LL << kExpireReductBit) - 1; | |
| 31 | 10 | kNoMallocOffset = (1LL << offset_bit) - 1; | |
| 32 | 10 | } | |
| 33 | }; | ||
| 34 | static Config kConfig; | ||
| 35 | |||
| 36 | ✗ | PetKVData() = default; | |
| 37 | |||
| 38 | ✗ | explicit PetKVData(int64_t offset) { SetShmMallocOffset(offset); } | |
| 39 | |||
| 40 | ✗ | inline int64_t shm_malloc_offset() const { | |
| 41 | ✗ | auto offset = data_value >> kConfig.kExpireBit; | |
| 42 | ✗ | return offset == kConfig.kNoMallocOffset ? -1 : offset << 3; | |
| 43 | } | ||
| 44 | |||
| 45 | ✗ | inline void SetShmMallocOffset(int64_t shm_malloc_offset) { | |
| 46 | ✗ | shm_malloc_offset = shm_malloc_offset == -1 ? kConfig.kNoMallocOffset | |
| 47 | : shm_malloc_offset >> 3; | ||
| 48 | ✗ | data_value = (data_value & kConfig.kExpireMark) | | |
| 49 | ✗ | (shm_malloc_offset << kConfig.kExpireBit); | |
| 50 | ✗ | } | |
| 51 | |||
| 52 | ✗ | inline uint32 expire_timet() const { | |
| 53 | ✗ | return (data_value & kConfig.kExpireMark) << kConfig.kExpireReductBit; | |
| 54 | } | ||
| 55 | |||
| 56 | ✗ | inline void DoFlush() { clflushopt_range(&data_value, sizeof(uint64_t)); } | |
| 57 | |||
| 58 | uint64_t data_value = 0; | ||
| 59 | }; | ||
| 60 | #pragma pack(pop) | ||
| 61 | |||
| 62 | } // namespace base | ||
| 63 |