-
Notifications
You must be signed in to change notification settings - Fork 4
/
list.h
34 lines (27 loc) · 857 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
#ifndef LIST_H_INCLUDED
#define LIST_H_INCLUDED
#include <pthread.h>
#include <semaphore.h>
#include <stdint.h>
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
struct singly_linked {
struct singly_linked * next;
};
typedef struct singly_linked sl;
struct singly_linked_list {
sl * head; //guarded by head_lock (RW)
sl ** tail; //guarded by tail_lock (RW)
bool closed; //guarded by head_lock (RW)
pthread_cond_t cond; //guarded by head_lock (waits)
pthread_mutex_t head_lock;
pthread_mutex_t tail_lock;
};
typedef struct singly_linked_list sll;
void list_init(sll * list);
sl * list_pop_head(sll * list);
void list_push_head(sll * list, sl * item);
void list_push_tail(sll * list, sl * l);
void list_close(sll * list);
#endif