-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue.h
85 lines (60 loc) · 2.25 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
76
77
78
79
80
81
82
83
84
85
/*
* Module for creating and manipulating queues of arbitrary data types
* created for COMP20007 Design of Algorithms 2017
* by Matt Farrugia <matt.farrugia@unimelb.edu.au> and modified by
* Shreyash Patodia <spatodia@student.unimelb.edu.au> to allow for
* arbitraty data types and also to have certain function required for
* COMP30023, Project-1.
*/
#ifndef QUEUE_H
#define QUEUE_H
#include "list.h"
#include "pthread.h"
/********************** Typedefing structures ***************************/
typedef struct queue Queue;
/*********************** Structure Definitions **************************/
// a Queue is just a wrapper for a list of its items
// we will use the back of the list as the entry point, and the front as the
// exit point (to take advantage of O(1) insert and remove operations)
struct queue {
List *items;
pthread_mutex_t mutex;
};
/*********************** Function Declarations ****************************/
/********************* Shreyash's Functions ****************************/
/*
* Gets the next node in the queue
*/
Node *queue_get_next(Node *node);
/*
* Get the data from a node in the queue
*/
void *queue_get_data(Node *node);
/*
* Gets the head of the queue.
*/
Node *queue_get_head(Queue *queue);
/*
* Calls the appropriate list function to remove a process
* from anywhere in the queue (list);
*/
void *queue_remove_from_middle(Queue *queue, Node *node);
/********************** Matt's Functions ********************************/
// create a new queue and return its pointer
Queue *new_queue();
// destroy a queue and its associated memory
void free_queue(Queue *queue);
// insert a new item of data at the back of a queue. O(1).
void queue_enqueue(Queue *queue, void *data);
// remove and return the item of data at the front of a queue. O(1).
// error if the queue is empty (so first ensure queue_size() > 0
void *queue_dequeue(Queue *queue);
// return the number of items currently in a queue
int queue_size(Queue *queue);
// Removes items from the middle of the queue, useful for scheduling.
//void queue_remove(Queue *queue, void *data);
Node *queue_get_next(Node *node);
void *queue_get_data(Node *node);
Node *queue_get_head(Queue *queue);
void *queue_remove_from_middle(Queue *queue, Node *node);
#endif