Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
阿啄debugIT
libfastcommon
提交
4b085fbc
L
libfastcommon
项目概览
阿啄debugIT
/
libfastcommon
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
libfastcommon
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
4b085fbc
编写于
7月 22, 2020
作者:
Y
YuQing
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add functions: get thread counters
上级
29586005
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
37 addition
and
13 deletion
+37
-13
src/tests/test_thread_pool.c
src/tests/test_thread_pool.c
+14
-8
src/thread_pool.c
src/thread_pool.c
+0
-5
src/thread_pool.h
src/thread_pool.h
+23
-0
未找到文件。
src/tests/test_thread_pool.c
浏览文件 @
4b085fbc
...
...
@@ -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"
);
...
...
src/thread_pool.c
浏览文件 @
4b085fbc
...
...
@@ -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
);
...
...
src/thread_pool.h
浏览文件 @
4b085fbc
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录