-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache.h
More file actions
51 lines (44 loc) · 1.06 KB
/
cache.h
File metadata and controls
51 lines (44 loc) · 1.06 KB
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
#ifndef CACHE_H
#define CACHE_H
#include <stdint.h>
#include <stddef.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <pthread.h>
// Константы
#include "config.h"
#ifndef PAGE_SIZE
#define PAGE_SIZE BLOCK_SIZE
#endif
#ifndef HASH_SIZE
#define HASH_SIZE 2048
#endif
#ifndef MUTEX_GROUPS
#define MUTEX_GROUPS 16
#endif
#ifndef MAX_CACHE_ENTRIES
#define MAX_CACHE_ENTRIES 1024
#endif
typedef struct cache_entry {
uint64_t offset;
char data[PAGE_SIZE];
int dirty;
time_t last_access;
struct cache_entry *next;
struct cache_entry *prev;
} cache_entry_t;
typedef struct {
cache_entry_t *hash[HASH_SIZE];
pthread_mutex_t mutex[MUTEX_GROUPS];
pthread_mutex_t lru_mutex;
cache_entry_t *lru_head;
cache_entry_t *lru_tail;
size_t entry_count;
} cache_t;
void cache_init(cache_t *c);
char* cache_get(cache_t *c, int fd, uint64_t offset, int write);
void cache_evict(cache_t *c, int fd);
void cache_destroy(cache_t *c, int fd);
#endif // CACHE_H