-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexpiry_collector.cpp
49 lines (38 loc) · 1.03 KB
/
expiry_collector.cpp
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
static void sweep(node_t *node){
//std::cout<<"In sweeper";
std::lock_guard<std::mutex> guard(map_mutex);
if(node->prev != NULL)
node->prev->next = node->next;
else
head = node->next;
if(node->next != NULL)
node->next->prev = node->prev;
else
tail = node->prev;
int cleared = node->entry->bytes + sizeof(cache_entry);
memory_counter -= cleared;
printf("memory counter after collection %d\n", memory_counter);
map->erase(node->entry->key);
process_stats->curr_items--;
free(node);
//return cleared;
}
static void collect(){
node_t *temp = head;
//std::cout<<"In collector1";
while(temp != NULL){
//std::cout<<"In collector2";
node_t *next_node = temp->next;
time_t current_time = std::time(NULL);
if(temp->entry->expiry <= current_time && temp->entry->expiry != 0)
sweep(temp);
temp = next_node;
}
//return cleared;
}
static void trigger_collection(){
while(1){
std::this_thread::sleep_for (std::chrono::seconds(5));
collect();
}
}