Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
阿啄debugIT
libfastcommon
提交
35aa9963
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 搜索 >>
提交
35aa9963
编写于
1月 29, 2021
作者:
Y
YuQing
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add function common_blocked_queue_timedpop
上级
41a4ca78
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
98 addition
and
1 deletion
+98
-1
HISTORY
HISTORY
+2
-1
src/common_blocked_queue.c
src/common_blocked_queue.c
+79
-0
src/common_blocked_queue.h
src/common_blocked_queue.h
+12
-0
src/common_define.h
src/common_define.h
+5
-0
未找到文件。
HISTORY
浏览文件 @
35aa9963
Version 1.48 2021-01-2
7
Version 1.48 2021-01-2
9
* fast_buffer.[hc]: add function fast_buffer_append_binary
* fc_check_mkdir_ex return 0 when mkdir with errno EEXIST
* add function common_blocked_queue_timedpop
Version 1.47 2021-01-20
* fc_atomic.h: add FC_ATOMIC_GET and FC_ATOMIC_SET etc.
...
...
src/common_blocked_queue.c
浏览文件 @
35aa9963
...
...
@@ -185,6 +185,85 @@ void *common_blocked_queue_pop_ex(struct common_blocked_queue *queue,
return
data
;
}
void
*
common_blocked_queue_timedpop
(
struct
common_blocked_queue
*
queue
,
const
int
timeout
,
const
int
time_unit
)
{
struct
common_blocked_node
*
node
;
void
*
data
;
struct
timespec
ts
;
int
seconds
;
int
result
;
if
((
result
=
pthread_mutex_lock
(
&
(
queue
->
lc_pair
.
lock
)))
!=
0
)
{
logError
(
"file: "
__FILE__
", line: %d, "
"call pthread_mutex_lock fail, "
"errno: %d, error info: %s"
,
__LINE__
,
result
,
STRERROR
(
result
));
return
NULL
;
}
do
{
node
=
queue
->
head
;
if
(
node
==
NULL
)
{
switch
(
time_unit
)
{
case
FC_TIME_UNIT_SECOND
:
seconds
=
timeout
;
ts
.
tv_nsec
=
0
;
break
;
case
FC_TIME_UNIT_MSECOND
:
seconds
=
timeout
/
1000
;
ts
.
tv_nsec
=
(
timeout
%
1000
)
*
(
1000
*
1000
);
break
;
case
FC_TIME_UNIT_USECOND
:
seconds
=
timeout
/
(
1000
*
1000
);
ts
.
tv_nsec
=
(
timeout
%
(
1000
*
1000
))
*
1000
;
break
;
case
FC_TIME_UNIT_NSECOND
:
seconds
=
timeout
/
(
1000
*
1000
*
1000
);
ts
.
tv_nsec
=
timeout
%
(
1000
*
1000
*
1000
);
break
;
default:
seconds
=
timeout
;
ts
.
tv_nsec
=
0
;
break
;
}
ts
.
tv_sec
=
get_current_time
()
+
seconds
;
pthread_cond_timedwait
(
&
queue
->
lc_pair
.
cond
,
&
queue
->
lc_pair
.
lock
,
&
ts
);
node
=
queue
->
head
;
}
if
(
node
!=
NULL
)
{
queue
->
head
=
node
->
next
;
if
(
queue
->
head
==
NULL
)
{
queue
->
tail
=
NULL
;
}
data
=
node
->
data
;
fast_mblock_free_object
(
&
queue
->
mblock
,
node
);
}
else
{
data
=
NULL
;
}
}
while
(
0
);
if
((
result
=
pthread_mutex_unlock
(
&
(
queue
->
lc_pair
.
lock
)))
!=
0
)
{
logError
(
"file: "
__FILE__
", line: %d, "
"call pthread_mutex_unlock fail, "
"errno: %d, error info: %s"
,
__LINE__
,
result
,
STRERROR
(
result
));
}
return
data
;
}
struct
common_blocked_node
*
common_blocked_queue_pop_all_nodes_ex
(
struct
common_blocked_queue
*
queue
,
const
bool
blocked
)
{
...
...
src/common_blocked_queue.h
浏览文件 @
35aa9963
...
...
@@ -116,6 +116,18 @@ struct common_blocked_node *common_blocked_queue_pop_all_nodes_ex(
void
common_blocked_queue_free_all_nodes
(
struct
common_blocked_queue
*
queue
,
struct
common_blocked_node
*
node
);
void
*
common_blocked_queue_timedpop
(
struct
common_blocked_queue
*
queue
,
const
int
timeout
,
const
int
time_unit
);
#define common_blocked_queue_timedpop_sec(queue, timeout) \
common_blocked_queue_timedpop(queue, timeout, FC_TIME_UNIT_SECOND)
#define common_blocked_queue_timedpop_ms(queue, timeout) \
common_blocked_queue_timedpop(queue, timeout, FC_TIME_UNIT_MSECOND)
#define common_blocked_queue_timedpop_us(queue, timeout) \
common_blocked_queue_timedpop(queue, timeout, FC_TIME_UNIT_USECOND)
#ifdef __cplusplus
}
#endif
...
...
src/common_define.h
浏览文件 @
35aa9963
...
...
@@ -134,6 +134,11 @@ extern int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int kind);
#define FC_MIN(v1, v2) (v1 < v2 ? v1 : v2)
#define FC_MAX(v1, v2) (v1 > v2 ? v1 : v2)
#define FC_TIME_UNIT_SECOND 's' //second
#define FC_TIME_UNIT_MSECOND 'm' //millisecond
#define FC_TIME_UNIT_USECOND 'u' //microsecond
#define FC_TIME_UNIT_NSECOND 'n' //nanosecond
#define STRERROR(no) (strerror(no) != NULL ? strerror(no) : "Unkown error")
#if defined(OS_LINUX)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录