forked from haguvenir/Turkish_TTS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTTSQueue.cpp
113 lines (93 loc) · 1.6 KB
/
TTSQueue.cpp
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "TextStruct.h"
TTSQueue::TTSQueue()
{
isBusy = false;
header = NULL;
last = NULL;
size = 0;
mutex = CreateSemaphore(NULL, 1, 1, "mutex");
full = CreateSemaphore(NULL, 0, QUEUE_SIZE, "full");
empty = CreateSemaphore(NULL, QUEUE_SIZE, QUEUE_SIZE, "empty");
}
TTSQueue::~TTSQueue()
{
CloseHandle(mutex);
CloseHandle(empty);
CloseHandle(full);
EmptyQueue();
}
void TTSQueue::EmptyQueue()
{
WaitForSingleObject(mutex, INFINITE);
//this->header = NULL;
Word *todel = header;
while(header != NULL)
{
header = header->next;
delete todel;
todel = header;
}
header = NULL;
last = NULL;
size = 0;
ReleaseSemaphore(mutex, 1, NULL);
}
void TTSQueue::Enqueue(Word * word)
{
WaitForSingleObject(empty, INFINITE);
WaitForSingleObject(mutex, INFINITE);
size++;
if(header == NULL)
{
header = word;
last = word;
}
else
{
last->next = word;
last = word;
}
ReleaseSemaphore(mutex, 1, NULL);
ReleaseSemaphore(full, 1, NULL);
}
Word * TTSQueue::Dequeue()
{
if(header == NULL)
return NULL;
WaitForSingleObject(full, INFINITE);
WaitForSingleObject(mutex, INFINITE);
Word * rt = NULL;
size--;
rt = header;
header = header->next;
ReleaseSemaphore(mutex, 1, NULL);
ReleaseSemaphore(empty, 1, NULL);
return rt;
}
void TTSQueue::Display()
{
Word * word = header;
while(word != NULL)
{
word->Display();
word = word->next;
}
}
void TTSQueue::DisplayS()
{
Word * word = header;
while(word != NULL)
{
word->DisplayS();
word = word->next;
}
}
void TTSQueue::DisplayP()
{
Word * word = header;
while(word != NULL)
{
word->DisplayP();
word = word->next;
}
}