-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueue.h
98 lines (86 loc) · 2.42 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
86
87
88
89
90
91
92
93
94
95
96
////////////////////////////////////////////////////////////////////////////////
// Main File: main.c
// This File: Queue.h
// Other Files: inputreader.c inputreader.h munch1.c munch1.h munch2.c
// munch2.h outputwriter.c outputwriter.h Queue.c
// Semester: CS 537 Fall 2018
//
// Author: Youmin Han
// Email: [email protected]
// CS Login: youmin
//
// Author: Xianjie Zheng
// Email: [email protected]
// CS Login: xianjie
//
/////////////////////////// OTHER SOURCES OF HELP //////////////////////////////
// fully acknowledge and credit all sources of help,
// other than Instructors and TAs.
//
// Persons: NULL
//
// Online sources: NULL
//
//////////////////////////// 80 columns wide ///////////////////////////////////
#ifndef __Queue_h__
#define __Queue_h__
#include <pthread.h>
typedef struct Queue{
char **array;
int qsize;
int enqcount;
int deqcount;
int enqblcount;
int deqblcount;
int front; //not sure
int end;
pthread_cond_t full;
pthread_cond_t empty;
pthread_mutex_t mutex;
}Queue;
typedef struct queuelist {
Queue *qreader;
Queue *qmunch1;
Queue *qmunch2;
}queuelist;
/*
* Dynamically allocate a new Queue structure and initialize it with an array of
* character points of length size.
* The function returns a pointer to the new queue structure.
*
* @param size : size of the queue
*/
Queue *CreateStringQueue(int qsize);
/*
* This function places the pointer to the string at the end of queue q.
* If the queue is full, then this function blocks until there is space
* available.
* @param q : A queue that stores strings
* string : a ptr stores a string
*/
void EnqueueString(Queue *q, char *string);
/*
* This function removes a pointer to a string from the beginning of queue q.
* If the queue is empty, then this function blocks until there is a string
* placed into the queue.
* Returns the pointer that was removed from the queue.
*
* @param q
* A queue that stores strings
*/
char * DequeueString(Queue *q);
/*
* This function prints the statistics for this queue.
*
* @param q
* A queue that stores strings
*/
void PrintQueueStats(Queue *q);
/*
* This function frees all the memory that a que has allocated
*
* @param q
* A queue that stores strings
*/
void DestoryQueue(Queue *q);
#endif