-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThread_System.cpp
158 lines (155 loc) · 4.44 KB
/
Thread_System.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
//-----------------------------------------------------------------
#include "Global.h"
//#include "Fuzon_Mp3.h"
//-----------------------------------------------------------------
///*****************************************************************
//GAME - THREAD - CONSTRUCTORS
///*****************************************************************
Thread_System::Thread_System(void)
{
//-------------------------------------------------------------
for (int i = 0; i<MAX_THREADS; i++)
{
bActive[i] = false;
Thread_Handle[i] = NULL;
Thread_Id[i] = i + 1;
bStopRequest[i] = false;
}
//-------------------------------------------------------------
}
Thread_System::~Thread_System(void)
{
//-------------------------------------------------------------
//-------------------------------------------------------------
}
//*****************************************************************
//START
//*****************************************************************
void Thread_System::Start(int Id)
{
//-------------------------------------------------------------
if (!bActive[Id])
{
bStopRequest[Id] = false;
//
if (Id == 0)
{
Thread_Handle[Id] = (HANDLE)_beginthreadex(NULL, 0, &Thread_0, NULL, 0, &Thread_Id[Id]);
SetPriorityClass(Thread_Handle[Id], ABOVE_NORMAL_PRIORITY_CLASS);
}
//
else if (Id == 1)
{
Thread_Handle[Id] = (HANDLE)_beginthreadex(NULL, 0, &Thread_1, NULL, 0, &Thread_Id[Id]);
SetPriorityClass(Thread_Handle[Id], BELOW_NORMAL_PRIORITY_CLASS);
}
//
else if (Id == 2)
{
Thread_Handle[Id] = (HANDLE)_beginthreadex(NULL, 0, &Thread_2, NULL, 0, &Thread_Id[Id]);
SetPriorityClass(Thread_Handle[Id], NORMAL_PRIORITY_CLASS);
}
bActive[Id] = true;
}
//-------------------------------------------------------------
}
//*****************************************************************
//STOP
//*****************************************************************
void Thread_System::Stop(int Id)
{
//-------------------------------------------------------------
//Stop active
if (bActive[Id])
{
bStopRequest[Id] = true;
WaitForSingleObject(Thread_Handle[Id], INFINITE);
//WaitForSingleObject(Thread_Handle[Id], 1000);
bActive[Id] = false;
CloseHandle(Thread_Handle[Id]);
}
//-------------------------------------------------------------
}
//*****************************************************************
//EXIT
//*****************************************************************
void Thread_System::Exit(void)
{
//-------------------------------------------------------------
for (int i = 0; i < MAX_THREADS; i++)
{
Stop(i);
}
//-------------------------------------------------------------
}
//*****************************************************************
///Thread 0 - Scan Filesystem for music
//*****************************************************************
unsigned __stdcall Thread_0(void*)
{
//-------------------------------------------------------------
while (cThread.bActive[0])
{
//Find Files
for (int i = 0; i < MAX_PLAYLIST_DIRECTORY; i++)
{
//Stop request, break
if (cThread.bStopRequest[0])
{
break;
}
if (cFile.Playlist_Directory[i] != "")
{
cFile.Scan_Media(cFile.Playlist_Directory[i], "*.*", true);
}
}
cThread.bActive[0] = false;
}
return 0;
//-------------------------------------------------------------
}
//*****************************************************************
///Thread 1 - Tag Thread
//*****************************************************************
unsigned __stdcall Thread_1(void*)
{
//-------------------------------------------------------------
while (cThread.bActive[1])
{
//TagCompletionPercent = gTotalFiles - i
for (long i = 0; i < gTotalFiles; i++)
{
//Stop request, break
if (cThread.bStopRequest[1])
{
break;
}
if (gPlaylist_Entry[i].filepath != "")
{
cBass.ObtainTags(i, gPlaylist_Entry[i]);
}
}
cThread.bActive[1] = false;
}
return 0;
//-------------------------------------------------------------
}
//*****************************************************************
///Thread 2 -
//*****************************************************************
unsigned __stdcall Thread_2(void*)
{
//-------------------------------------------------------------
while (cThread.bActive[2])
{
//cupdate.()
//Stop request, break
//if (cThread.bStopRequest[2])
//{
// break;
//}
cThread.bActive[2] = false;
}
return 0;
//-------------------------------------------------------------
}