-
Notifications
You must be signed in to change notification settings - Fork 0
/
fine-lru.c
79 lines (66 loc) · 2.08 KB
/
fine-lru.c
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* -*- mode:c; c-file-style:"k&r"; c-basic-offset: 4; tab-width:4; indent-tabs-mode:nil; mode:auto-fill; fill-column:78; -*- */
/* vim: set ts=4 sw=4 et tw=78 fo=cqt wm=0: */
/* @* Place your name here, and any other comments *@
* @* that deanonymize your work inside this syntax *@
*/
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include "lru.h"
/* Define the simple, singly-linked list we are going to use for tracking lru */
struct list_node {
struct list_node* next;
int key;
int refcount;
// Protects this node's contents
pthread_mutex_t mutex;
};
static struct list_node* list_head = NULL;
/* A static mutex; protects the count and head.
* XXX: We will have to tolerate some lag in updating the count to avoid
* deadlock. */
static pthread_mutex_t mutex;
static int count = 0;
static pthread_cond_t cv_low, cv_high;
static volatile int done = 0;
/* Initialize the mutex. */
int init (int numthreads) {
/* Your code here */
/* Temporary code to suppress compiler warnings about unused variables.
* You should remove the following lines once this file is implemented.
*/
(void)list_head;
(void)mutex;
(void)count;
(void)cv_low;
(void)cv_high;
/* End temporary code */
return 0;
}
/* Return 1 on success, 0 on failure.
* Should set the reference count up by one if found; add if not.*/
int reference (int key) {
/* Your code here */
return 1;
}
/* Do a pass through all elements, either decrement the reference count,
* or remove if it hasn't been referenced since last cleaning pass.
*
* check_water_mark: If 1, block until there are more elements in the cache
* than the LOW_WATER_MARK. This should only be 0 during self-testing or in
* single-threaded mode.
*/
void clean(int check_water_mark) {
/* Your code here */
}
/* Optional shut-down routine to wake up blocked threads.
May not be required. */
void shutdown_threads (void) {
/* Your code here */
return;
}
/* Print the contents of the list. Mostly useful for debugging. */
void print (void) {
/* Your code here */
}