forked from EmpyreanKnight/OSLab-P4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.h
37 lines (30 loc) · 901 Bytes
/
list.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
#ifndef P4_LIST_H
#define P4_LIST_H
#include "lock.h"
#include <stdio.h>
#include <stdlib.h>
/**
* Node type in the list
*
*/
typedef struct _node_t {
unsigned int key; /**< the key field of this node */
struct _node_t *next; /**< pointer to the next node in the list */
} node_t;
/**
* A concurrent list definition
* All operations except initialization and destroy are thread-safe
* Maintain a head-insert linked-list
*/
typedef struct {
node_t *head; /**< a pointer to the head node */
lock_t lock; /**< guarantee sequential execution in list functions */
} list_t;
void list_init(list_t *list);
void list_insert(list_t *list, unsigned int key);
void list_delete(list_t *list, unsigned int key);
void *list_lookup(list_t *list, unsigned int key);
void list_destroy(list_t* list);
int list_count(list_t* list);
long long list_sum(list_t* list);
#endif //P4_LIST_H