Skip to content

Commit d18b2b0

Browse files
committed
Reorder declarations
1 parent ff0fad2 commit d18b2b0

4 files changed

Lines changed: 60 additions & 63 deletions

File tree

service.hpp

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ struct PageEntry
6969

7070
class PageLock : public SRWLockBase<PageLock>
7171
{
72+
PageEntry* entry_;
73+
7274
public:
7375
PageLock() : SRWLockBase(), entry_(nullptr) {}
7476

@@ -90,9 +92,6 @@ class PageLock : public SRWLockBase<PageLock>
9092
{
9193
if (is_exclusive) entry_->clear_owner();
9294
}
93-
94-
private:
95-
PageEntry* entry_;
9695
};
9796

9897
// operation result, only for current thread
@@ -108,6 +107,26 @@ struct PageResult
108107

109108
class ChunkDiskService
110109
{
110+
std::vector<FileHandle> part_lock_; // part index -> .lock
111+
112+
std::unique_ptr<std::shared_mutex> mutex_parts_;
113+
std::vector<u64> part_current_; // part index -> # of chunks
114+
size_t part_current_new_ = 0; // part index for new chunks
115+
std::unordered_map<u64, size_t> chunk_parts_; // chunk index -> part index
116+
117+
std::unique_ptr<std::shared_mutex> mutex_pages_;
118+
// BLOCK_SIZE -> PAGE_SIZE access
119+
// read cache, write through
120+
// add to back, evict from front
121+
Map<u64, PageEntry> cached_pages_;
122+
123+
std::unique_ptr<std::shared_mutex> mutex_unmapped_;
124+
// chunk index -> [start_off, end_off)
125+
std::unordered_map<u64, std::map<u64, u64>> chunk_unmapped_;
126+
127+
// not movable
128+
std::atomic<u64> post_ft_ = 0;
129+
111130
public:
112131
const ChunkDiskParams params;
113132

@@ -184,26 +203,6 @@ class ChunkDiskService
184203
void SetPostFileTime(u64 ft) { post_ft_.store(ft, std::memory_order_release); }
185204

186205
private:
187-
std::vector<FileHandle> part_lock_; // part index -> .lock
188-
189-
std::unique_ptr<std::shared_mutex> mutex_parts_;
190-
std::vector<u64> part_current_; // part index -> # of chunks
191-
size_t part_current_new_ = 0; // part index for new chunks
192-
std::unordered_map<u64, size_t> chunk_parts_; // chunk index -> part index
193-
194-
std::unique_ptr<std::shared_mutex> mutex_pages_;
195-
// BLOCK_SIZE -> PAGE_SIZE access
196-
// read cache, write through
197-
// add to back, evict from front
198-
Map<u64, PageEntry> cached_pages_;
199-
200-
std::unique_ptr<std::shared_mutex> mutex_unmapped_;
201-
// chunk index -> [start_off, end_off)
202-
std::unordered_map<u64, std::map<u64, u64>> chunk_unmapped_;
203-
204-
// not movable
205-
std::atomic<u64> post_ft_ = 0;
206-
207206
// lk: mutex_pages_, shared
208207
// it: from cached_pages_ while holding lk
209208
// return ERROR_LOCK_FAILED if it is locked by the current thread

types.hpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,27 @@ struct pair_hash
4747
template <class KT, class VT>
4848
class Map
4949
{
50-
public:
5150
struct VIt
5251
{
5352
VT val;
5453
typename std::list<const KT*>::iterator it; // iterator in key_order_
5554
};
5655

56+
std::unordered_map<KT, VIt> map_;
57+
std::list<const KT*> key_order_;
58+
59+
public:
5760
// iterate in the insertion order
5861
// invalidated if invalidated in map_
59-
struct iterator
62+
class iterator
6063
{
64+
friend class Map;
65+
66+
std::unordered_map<KT, VIt>* map_ = nullptr;
67+
typename std::unordered_map<KT, VIt>::iterator it_;
68+
typename std::list<const KT*>::iterator end_it_; // key_order_.end()
69+
70+
public:
6171
iterator() = default;
6272

6373
explicit iterator(std::unordered_map<KT, VIt>* map,
@@ -83,13 +93,6 @@ class Map
8393
{
8494
return map_ == other.map_ && it_ == other.it_ && end_it_ == other.end_it_;
8595
}
86-
87-
private:
88-
friend class Map;
89-
90-
std::unordered_map<KT, VIt>* map_ = nullptr;
91-
typename std::unordered_map<KT, VIt>::iterator it_;
92-
typename std::list<const KT*>::iterator end_it_; // key_order_.end()
9396
};
9497

9598
auto front() { return *find(*key_order_.front()); }
@@ -189,10 +192,6 @@ class Map
189192
}
190193

191194
void reserve(size_t count) { map_.reserve(count); }
192-
193-
private:
194-
std::unordered_map<KT, VIt> map_;
195-
std::list<const KT*> key_order_;
196195
};
197196

198197
}

utils.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ namespace chunkdisk
2323
template <class Derived>
2424
class SRWLockBase
2525
{
26+
std::unique_lock<std::shared_mutex> ulock_;
27+
std::shared_lock<std::shared_mutex> slock_;
28+
2629
public:
2730
SRWLockBase() = default;
2831

@@ -176,10 +179,6 @@ class SRWLockBase
176179
void on_locked(bool is_exclusive);
177180

178181
void on_unlock(bool is_exclusive);
179-
180-
private:
181-
std::unique_lock<std::shared_mutex> ulock_;
182-
std::shared_lock<std::shared_mutex> slock_;
183182
};
184183

185184
class SRWLock : public SRWLockBase<SRWLock>

worker.hpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,29 @@ struct ChunkFileHandle
111111
// can't be shared with other dispatchers
112112
class ChunkDiskWorker
113113
{
114+
enum IOCPKey
115+
{
116+
CK_IO = 0, // completed file I/O
117+
CK_POST, // disk I/O request from PostWork()
118+
CK_STOP // cancel pending I/O ops and stop DoWorks()
119+
};
120+
121+
ChunkDiskService& service_;
122+
std::thread thread_;
123+
GenericHandle iocp_;
124+
GenericHandle wait_event_;
125+
GenericHandle spd_ovl_event_;
126+
OVERLAPPED spd_ovl_ = {};
127+
128+
std::unique_ptr<std::shared_mutex> mutex_working_;
129+
std::list<ChunkWork> working_;
130+
131+
std::unique_ptr<std::shared_mutex> mutex_buffers_;
132+
std::deque<Pages> buffers_;
133+
134+
std::unique_ptr<std::shared_mutex> mutex_handles_;
135+
Map<u64, ChunkFileHandle> chunk_handles_; // add to back, evict from front
136+
114137
public:
115138
explicit ChunkDiskWorker(ChunkDiskService& service) : service_(service) {}
116139

@@ -158,29 +181,6 @@ class ChunkDiskWorker
158181
DWORD PostWork(SPD_STORAGE_UNIT_OPERATION_CONTEXT* context, ChunkOpKind op_kind, u64 block_addr, u32 count);
159182

160183
private:
161-
enum IOCPKey
162-
{
163-
CK_IO = 0, // completed file I/O
164-
CK_POST, // disk I/O request from PostWork()
165-
CK_STOP // cancel pending I/O ops and stop DoWorks()
166-
};
167-
168-
ChunkDiskService& service_;
169-
std::thread thread_;
170-
GenericHandle iocp_;
171-
GenericHandle wait_event_;
172-
GenericHandle spd_ovl_event_;
173-
OVERLAPPED spd_ovl_ = {};
174-
175-
std::unique_ptr<std::shared_mutex> mutex_working_;
176-
std::list<ChunkWork> working_;
177-
178-
std::unique_ptr<std::shared_mutex> mutex_buffers_;
179-
std::deque<Pages> buffers_;
180-
181-
std::unique_ptr<std::shared_mutex> mutex_handles_;
182-
Map<u64, ChunkFileHandle> chunk_handles_; // add to back, evict from front
183-
184184
// get zero-filled, page aligned buffer from the pool
185185
DWORD GetBuffer(Pages& buffer);
186186

0 commit comments

Comments
 (0)