提交 4b085fbc 编写于 作者: Y YuQing

add functions: get thread counters

上级 29586005
......@@ -81,6 +81,17 @@ int test(FCThreadPool *pool)
return 0;
}
static void output(FCThreadPool *pool, const int64_t start_time)
{
printf("thread pool dealing count: %d, avail count: %d, "
"counter: %d, total: %"PRId64", time used: %"PRId64" ms\n",
fc_thread_pool_dealing_count(pool),
fc_thread_pool_avail_count(pool),
__sync_add_and_fetch(&counter, 0),
__sync_add_and_fetch(&total, 0),
get_current_time_ms() - start_time);
}
int main(int argc, char *argv[])
{
FCThreadPool pool;
......@@ -104,12 +115,10 @@ int main(int argc, char *argv[])
}
result = test(&pool);
output(&pool, start_time);
sleep(10);
printf("counter: %d, total: %"PRId64", time used: %"PRId64" ms\n",
__sync_add_and_fetch(&counter, 0),
__sync_add_and_fetch(&total, 0),
get_current_time_ms() - start_time);
output(&pool, start_time);
result = test(&pool);
sleep(5);
......@@ -117,10 +126,7 @@ int main(int argc, char *argv[])
continue_flag = false;
sleep(2);
printf("counter: %d, total: %"PRId64", time used: %"PRId64" ms\n",
__sync_add_and_fetch(&counter, 0),
__sync_add_and_fetch(&total, 0),
get_current_time_ms() - start_time);
output(&pool, start_time);
fc_thread_pool_destroy(&pool);
logInfo("exit");
......
......@@ -3,7 +3,6 @@
#include <pthread.h>
#include <unistd.h>
#include <string.h>
#include "pthread_func.h"
#include "sched_thread.h"
#include "fc_memory.h"
#include "thread_pool.h"
......@@ -204,10 +203,6 @@ int fc_thread_pool_run(FCThreadPool *pool, fc_thread_pool_callback func,
struct timespec ts;
int result;
if (func == NULL) {
return EINVAL;
}
thread = NULL;
ts.tv_nsec = 0;
PTHREAD_MUTEX_LOCK(&pool->lock);
......
......@@ -4,6 +4,7 @@
#include <time.h>
#include <pthread.h>
#include "fast_mblock.h"
#include "pthread_func.h"
typedef void (*fc_thread_pool_callback)(void *arg);
......@@ -52,6 +53,28 @@ void fc_thread_pool_destroy(FCThreadPool *pool);
int fc_thread_pool_run(FCThreadPool *pool, fc_thread_pool_callback func,
void *arg);
static inline int fc_thread_pool_dealing_count(FCThreadPool *pool)
{
return __sync_add_and_fetch(&pool->thread_counts.dealing, 0);
}
static inline int fc_thread_pool_avail_count(FCThreadPool *pool)
{
return pool->thread_counts.limit -
__sync_add_and_fetch(&pool->thread_counts.dealing, 0);
}
static inline int fc_thread_pool_running_count(FCThreadPool *pool)
{
int running_count;
PTHREAD_MUTEX_LOCK(&pool->lock);
running_count = pool->thread_counts.running;
PTHREAD_MUTEX_UNLOCK(&pool->lock);
return running_count;
}
#ifdef __cplusplus
}
#endif
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册