forked from raphaelsc/ghostfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache.h
48 lines (33 loc) · 927 Bytes
/
cache.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
/*
Ghost File System, or simply GhostFS
Copyright (C) 2016 Raphael S. Carvalho
This program can be distributed under the terms of the GNU GPL.
See the file COPYING.
*/
#ifndef CACHE_H
#define CACHE_H
#include <mutex>
#include "block_info.h"
struct cache {
private:
bi::list<block, bi::member_hook<block, bi::list_member_hook<>,
&block::_lru_link>> _lru;
size_t _blocks_used = 0;
size_t _blocks_available;
size_t _block_size;
size_t blocks_used();
public:
std::mutex _mtx;
size_t _hits = 0;
size_t _misses = 0;
cache(size_t blocks, size_t block_size);
~cache();
// Return a block which isn't inserted to lru yet, i.e. the block is locked.
block* allocate_block(block_info* info);
void lock_block(block* blk);
void unlock_block(block* blk);
size_t block_size();
float get_hit_ratio();
friend struct ghost_fs;
};
#endif // CACHE_H