Skip to content

Commit 4d9431d

Browse files
committed
加强线程调试机制。
1 parent 32b746e commit 4d9431d

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

kbe/src/lib/thread/threadpool.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,9 @@ void* TPThread::threadFunc(void* arg)
590590
{
591591
TPThread * tptd = static_cast<TPThread*>(arg);
592592
ThreadPool* pThreadPool = tptd->threadPool();
593+
593594
bool isRun = true;
595+
tptd->reset_done_tasks();
594596

595597
#if KBE_PLATFORM == PLATFORM_WIN32
596598
#else
@@ -607,6 +609,7 @@ void* TPThread::threadFunc(void* arg)
607609
}
608610
else
609611
{
612+
tptd->reset_done_tasks();
610613
isRun = tptd->onWaitCondSignal();
611614
}
612615

@@ -626,6 +629,7 @@ void* TPThread::threadFunc(void* arg)
626629

627630
while(task && !tptd->threadPool()->isDestroyed())
628631
{
632+
tptd->inc_done_tasks();
629633
tptd->onProcessTaskStart(task);
630634
tptd->processTask(task); // 处理该任务
631635
tptd->onProcessTaskEnd(task);
@@ -660,6 +664,7 @@ void* TPThread::threadFunc(void* arg)
660664

661665
tptd->onEnd();
662666
tptd->state_ = THREAD_STATE_END;
667+
tptd->reset_done_tasks();
663668
}
664669

665670
#if KBE_PLATFORM == PLATFORM_WIN32

kbe/src/lib/thread/threadpool.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,17 @@ class TPThread
199199
{
200200
char buf[128];
201201
lock();
202-
sprintf(buf, "%p", currTask_);
202+
sprintf(buf, "%p,%u", currTask_, done_tasks_);
203203
unlock();
204204
return buf;
205205
}
206+
207+
/**
208+
线程启动一次在未改变到闲置状态下连续执行的任务计数
209+
*/
210+
void reset_done_tasks(){ done_tasks_ = 0; }
211+
void inc_done_tasks(){ ++done_tasks_; }
212+
206213
protected:
207214
THREAD_SINGNAL cond_; // 线程信号量
208215
THREAD_MUTEX mutex_; // 线程互诉体
@@ -211,6 +218,7 @@ class TPThread
211218
THREAD_ID tidp_; // 本线程的ID
212219
ThreadPool* threadPool_; // 线程池指针
213220
THREAD_STATE state_; // 线程状态: -1还未启动, 0睡眠, 1繁忙中
221+
uint32 done_tasks_; // 线程启动一次在未改变到闲置状态下连续执行的任务计数
214222
};
215223

216224

0 commit comments

Comments
 (0)