|
|
|
@ -43,7 +43,7 @@
|
|
|
|
|
#define RET_TP_ERROR (-8)
|
|
|
|
|
#define RET_TP_SYSTEM_ERROR (-1)
|
|
|
|
|
|
|
|
|
|
#define MAX_THREAD_NUM (8)
|
|
|
|
|
#define MAX_THREAD_NUM (200)
|
|
|
|
|
#define DEFAULT_SPIN_COUNT (30000)
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
@ -84,7 +84,7 @@ typedef struct ThreadPool {
|
|
|
|
|
|
|
|
|
|
Thread *GetThread(struct ThreadPool *thread_pool, int thread_id) {
|
|
|
|
|
if (thread_pool == NULL) {
|
|
|
|
|
LOG_ERROR("get thread pool instane failed, thread_id: %d", thread_id);
|
|
|
|
|
LOG_ERROR("get thread pool instance failed, thread_id: %d", thread_id);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
ThreadList *thread_list = thread_pool->thread_list;
|
|
|
|
@ -482,7 +482,7 @@ int SetAffinity(pthread_t thread_id, cpu_set_t *cpuSet) {
|
|
|
|
|
|
|
|
|
|
int BindMasterThread(struct ThreadPool *thread_pool, bool is_bind) {
|
|
|
|
|
if (thread_pool == NULL) {
|
|
|
|
|
LOG_ERROR("get thread pool instane failed");
|
|
|
|
|
LOG_ERROR("get thread pool instance failed");
|
|
|
|
|
return RET_TP_ERROR;
|
|
|
|
|
}
|
|
|
|
|
cpu_set_t mask;
|
|
|
|
@ -564,7 +564,7 @@ int DoBindSalverThreads(struct ThreadPool *thread_pool) {
|
|
|
|
|
|
|
|
|
|
int BindSalverThreads(struct ThreadPool *thread_pool, bool is_bind) {
|
|
|
|
|
if (thread_pool == NULL) {
|
|
|
|
|
LOG_ERROR("get thread pool instane failed");
|
|
|
|
|
LOG_ERROR("get thread pool instance failed");
|
|
|
|
|
return RET_TP_ERROR;
|
|
|
|
|
}
|
|
|
|
|
int ret;
|
|
|
|
@ -586,7 +586,7 @@ int BindThreads(struct ThreadPool *thread_pool, bool is_bind, int mode) {
|
|
|
|
|
return RET_TP_OK;
|
|
|
|
|
}
|
|
|
|
|
if (thread_pool == NULL) {
|
|
|
|
|
LOG_ERROR("get thread pool instane failed");
|
|
|
|
|
LOG_ERROR("get thread pool instance failed");
|
|
|
|
|
return RET_TP_ERROR;
|
|
|
|
|
}
|
|
|
|
|
thread_pool->mode = mode;
|
|
|
|
@ -641,7 +641,7 @@ bool PopTaskFromQueue(Thread *thread, Task **task) {
|
|
|
|
|
|
|
|
|
|
void WaitAllThread(struct ThreadPool *thread_pool) {
|
|
|
|
|
if (thread_pool == NULL) {
|
|
|
|
|
LOG_ERROR("get thread pool instane failed");
|
|
|
|
|
LOG_ERROR("get thread pool instance failed");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
bool k_success_flag = false;
|
|
|
|
@ -663,7 +663,7 @@ void WaitAllThread(struct ThreadPool *thread_pool) {
|
|
|
|
|
|
|
|
|
|
int DistributeTask(struct ThreadPool *thread_pool, Task *task, int task_num) {
|
|
|
|
|
if (thread_pool == NULL) {
|
|
|
|
|
LOG_ERROR("get thread pool instane failed");
|
|
|
|
|
LOG_ERROR("get thread pool instance failed");
|
|
|
|
|
return RET_TP_ERROR;
|
|
|
|
|
}
|
|
|
|
|
if (task_num > thread_pool->thread_num || task_num <= 1) {
|
|
|
|
@ -705,7 +705,7 @@ int DistributeTask(struct ThreadPool *thread_pool, Task *task, int task_num) {
|
|
|
|
|
|
|
|
|
|
int AddTask(struct ThreadPool *thread_pool, int func(void *, int), void *content, int task_num) {
|
|
|
|
|
if (thread_pool == NULL) {
|
|
|
|
|
LOG_ERROR("get thread pool instane failed");
|
|
|
|
|
LOG_ERROR("get thread pool instance failed");
|
|
|
|
|
return RET_TP_ERROR;
|
|
|
|
|
}
|
|
|
|
|
// if single thread, run master thread
|
|
|
|
@ -741,7 +741,7 @@ void ThreadRun(Thread *thread) {
|
|
|
|
|
thread->is_running = true;
|
|
|
|
|
ThreadPool *thread_pool = (ThreadPool *)(thread->thread_pool);
|
|
|
|
|
if (thread_pool == NULL) {
|
|
|
|
|
LOG_ERROR("get thread pool instane failed");
|
|
|
|
|
LOG_ERROR("get thread pool instance failed");
|
|
|
|
|
thread->is_running = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -779,7 +779,7 @@ void ThreadRun(Thread *thread) {
|
|
|
|
|
|
|
|
|
|
void PushThreadToList(struct ThreadPool *thread_pool, Thread *thread) {
|
|
|
|
|
if (thread_pool == NULL) {
|
|
|
|
|
LOG_ERROR("get thread pool instane failed");
|
|
|
|
|
LOG_ERROR("get thread pool instance failed");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ThreadList *thread_list = thread_pool->thread_list;
|
|
|
|
@ -882,7 +882,7 @@ ThreadPool *CreateThreadPool(int thread_num, int mode) {
|
|
|
|
|
|
|
|
|
|
void ActivateThreadPool(struct ThreadPool *thread_pool) {
|
|
|
|
|
if (thread_pool == NULL) {
|
|
|
|
|
LOG_ERROR("get thread pool instane failed");
|
|
|
|
|
LOG_ERROR("get thread pool instance failed");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ThreadList *thread_list = thread_pool->thread_list;
|
|
|
|
@ -900,7 +900,7 @@ void ActivateThreadPool(struct ThreadPool *thread_pool) {
|
|
|
|
|
|
|
|
|
|
void DeactivateThreadPool(struct ThreadPool *thread_pool) {
|
|
|
|
|
if (thread_pool == NULL) {
|
|
|
|
|
LOG_ERROR("get thread pool instane failed");
|
|
|
|
|
LOG_ERROR("get thread pool instance failed");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ThreadList *thread_list = thread_pool->thread_list;
|
|
|
|
@ -917,7 +917,7 @@ void DeactivateThreadPool(struct ThreadPool *thread_pool) {
|
|
|
|
|
|
|
|
|
|
void DestroyThreadPool(struct ThreadPool *thread_pool) {
|
|
|
|
|
if (thread_pool == NULL) {
|
|
|
|
|
LOG_ERROR("get thread pool instane failed");
|
|
|
|
|
LOG_ERROR("get thread pool instance failed");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (thread_pool->thread_list == NULL) {
|
|
|
|
@ -940,7 +940,7 @@ void DestroyThreadPool(struct ThreadPool *thread_pool) {
|
|
|
|
|
|
|
|
|
|
int GetCurrentThreadNum(struct ThreadPool *thread_pool) {
|
|
|
|
|
if (thread_pool == NULL) {
|
|
|
|
|
LOG_ERROR("get thread pool instane failed");
|
|
|
|
|
LOG_ERROR("get thread pool instance failed");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return thread_pool->thread_num;
|
|
|
|
|