| 215 |
{ |
{ |
| 216 |
thread_pool *p; |
thread_pool *p; |
| 217 |
UINT i; |
UINT i; |
| 218 |
bool bKillStatus = true; |
int t_count = 0; |
| 219 |
|
|
| 220 |
p = (thread_pool*)pParam; |
p = (thread_pool*)pParam; |
| 221 |
|
|
| 222 |
if (p->SetLock(true) != 0) |
while(!p->bTerminateThreadKiller) |
| 223 |
{ |
{ |
| 224 |
return p->uLastErrorCode; |
if (t_count>=100) |
|
} |
|
|
|
|
|
if (p->uThreadCount <= 0) |
|
|
{ |
|
|
p->SetLock(false); |
|
|
p->uLastErrorCode = E_THREAD_NOT_FOUND; |
|
|
return E_THREAD_NOT_FOUND; |
|
|
} |
|
|
|
|
|
for (i=0; i < p->uThreadMax; i++) |
|
|
{ |
|
|
if ((p->uThreadStatusList[i] == S_WORKING) && |
|
|
(clock() - p->time_status_set[i] > p->thread_timeout[i])) |
|
| 225 |
{ |
{ |
| 226 |
if (TerminateThread(p->hThreadList[i],-1)) |
t_count=0; |
| 227 |
{ |
|
| 228 |
bKillStatus &= true; |
if (p->SetLock(true) == 0) |
|
syslog << logfile::log_head << "Terminate dead thread ... OK" << endl; |
|
|
} |
|
|
else |
|
| 229 |
{ |
{ |
| 230 |
bKillStatus &= false; |
for (i=0; i < p->uThreadMax; i++) |
| 231 |
syslog << logfile::log_head << "Terminate dead thread ... Failed" << endl; |
{ |
| 232 |
|
if ((p->hThreadList[i] != NULL) && |
| 233 |
|
(p->uThreadStatusList[i] == S_WORKING) && |
| 234 |
|
(clock() - p->time_status_set[i] > p->thread_timeout[i])) |
| 235 |
|
{ |
| 236 |
|
if (TerminateThread(p->hThreadList[i],-1)) |
| 237 |
|
{ |
| 238 |
|
syslog << logfile::log_head << "Terminate dead thread ... OK" << endl; |
| 239 |
|
} |
| 240 |
|
else |
| 241 |
|
{ |
| 242 |
|
syslog << logfile::log_head << "Terminate dead thread ... Failed" << endl; |
| 243 |
|
} |
| 244 |
|
p->hThreadList[i] = NULL; |
| 245 |
|
p->uThreadStatusList[i] = S_UNUSED; |
| 246 |
|
p->time_status_set[i] = clock(); |
| 247 |
|
p->uThreadCount--; |
| 248 |
|
} |
| 249 |
|
} |
| 250 |
} |
} |
| 251 |
p->hThreadList[i] = NULL; |
|
| 252 |
p->uThreadStatusList[i] = S_UNUSED; |
p->SetLock(false); |
|
p->time_status_set[i] = clock(); |
|
|
p->uThreadCount--; |
|
| 253 |
} |
} |
| 254 |
|
|
| 255 |
|
Sleep(100); |
| 256 |
|
t_count++; |
| 257 |
} |
} |
| 258 |
|
|
| 259 |
p->SetLock(false); |
return (E_NOERROR); |
|
p->uLastErrorCode = (bKillStatus?E_NOERROR:E_KILL_THREAD_FAILED); |
|
|
return (bKillStatus?E_NOERROR:E_KILL_THREAD_FAILED); |
|
| 260 |
} |
} |
| 261 |
|
|
| 262 |
int thread_pool::GetThreadCount(void) const |
int thread_pool::GetThreadCount(void) const |
| 268 |
{ |
{ |
| 269 |
HANDLE hThreadCurrent; |
HANDLE hThreadCurrent; |
| 270 |
ULONG ulThreadId; |
ULONG ulThreadId; |
| 271 |
|
|
| 272 |
|
this->bTerminateThreadKiller = false; |
| 273 |
if (hThreadCurrent = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)thread_pool::KillDeadThread,(LPVOID)this,0,&ulThreadId)) |
if (hThreadCurrent = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)thread_pool::KillDeadThread,(LPVOID)this,0,&ulThreadId)) |
| 274 |
{ |
{ |
| 275 |
this->hThreadKiller = hThreadCurrent; |
this->hThreadKiller = hThreadCurrent; |
| 286 |
|
|
| 287 |
int thread_pool::DisableKillDeadThread(void) |
int thread_pool::DisableKillDeadThread(void) |
| 288 |
{ |
{ |
| 289 |
if (this->hThreadKiller) |
bTerminateThreadKiller = true; |
| 290 |
|
|
| 291 |
|
Sleep(1000); |
| 292 |
|
|
| 293 |
|
if (!bTerminateThreadKiller) |
| 294 |
|
{ |
| 295 |
|
syslog << logfile::log_head << "Terminate killer thread ... OK" << endl; |
| 296 |
|
} |
| 297 |
|
|
| 298 |
|
if (bTerminateThreadKiller && this->hThreadKiller) |
| 299 |
{ |
{ |
| 300 |
if (TerminateThread(this->hThreadKiller,0)) |
if (TerminateThread(this->hThreadKiller,0)) |
| 301 |
{ |
{ |