-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathqueue.h
75 lines (65 loc) · 1.38 KB
/
queue.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
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
#include "stdlib.h"
#include "stdio.h"
#include "pthread.h"
#include "assert.h"
#include "string.h"
#define ASSERT(x) assert(x)
#define PRI_MAX 10
#define BUF_POOL_SIZE 1024
#define uint32_t int
#define LOG //printf
#define LOG2 //printf
#define LOG3 //printf
#define LOCK(x) pthread_mutex_lock(&x)
#define UNLOCK(x) pthread_mutex_unlock(&x)
typedef enum bool_ {
false,
true
} bool;
typedef struct queue_stats_ {
int enqueue;
int dequeue;
int wait_time;
} queue_stats;
int priority[PRI_MAX];
/*
* List of nodes in a hash bucket
*/
typedef struct node_ {
int key;
int priority;
struct node_* next;
} node;
/*
* Define the hash table
* |p1| ->|a|->|b|->|c|
* |p2|->|e|->|f|
*/
typedef struct ptable_entry_ {
int priority;
node* n;
} ptable_entry;
typedef struct ptable_ {
ptable_entry entry[PRI_MAX];
node* last[PRI_MAX];
node* buf_pool;
node* free_bbuf_pool;
int ent_count;
pthread_mutex_t lock;
pthread_cond_t cv;
bool is_available;
queue_stats *stats;
} ptable;
void create(ptable*);
void get_data(ptable*, int*, int*);
void put_data(ptable*, int key, int priority);
void destroy(ptable*);
void display(ptable*);
void put_buf(ptable* p, void* buf);
void create_pool(ptable** p, uint32_t num);
void* get_buf(ptable* p);
void display_buf_pool(ptable* p);
/*
* Helper functions
*/
void add_a_node(ptable* p, node** last, node** m, int key, int priority);