Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
878a0471
提交
878a0471
authored
11月 18, 2014
作者:
Anthony Minessale
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
revert
上级
da6043f3
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
26 行增加
和
72 行删除
+26
-72
switch_time.c
src/switch_time.c
+26
-72
没有找到文件。
src/switch_time.c
浏览文件 @
878a0471
...
...
@@ -132,7 +132,7 @@ struct timer_private {
typedef
struct
timer_private
timer_private_t
;
struct
timer_matrix
{
uint64
_t
tick
;
switch_size
_t
tick
;
uint32_t
count
;
uint32_t
roll
;
switch_mutex_t
*
mutex
;
...
...
@@ -385,34 +385,23 @@ SWITCH_DECLARE(void) switch_time_set_cond_yield(switch_bool_t enable)
switch_time_sync
();
}
static
switch_status_t
timer_generic_sync
(
switch_timer_t
*
timer
)
{
switch_time_t
now
=
time_now
(
0
);
int64_t
elapsed
=
(
now
-
timer
->
start
);
timer
->
tick
=
(
elapsed
/
timer
->
interval
)
/
1000
;
timer
->
samplecount
=
timer
->
tick
*
timer
->
samples
;
return
SWITCH_STATUS_SUCCESS
;
}
/////////
#ifdef HAVE_TIMERFD_CREATE
#define MAX_INTERVAL 2000
/* ms */
struct
interval_timer
{
int
fd
;
int
fd
;
switch_size_t
tick
;
};
typedef
struct
interval_timer
interval_timer_t
;
static
switch_status_t
timerfd_start_interval
(
interval_timer_t
*
it
,
int
interval
)
{
struct
itimerspec
val
;
int
fd
,
r
;
uint64_t
exp
;
int
fd
;
it
->
tick
=
0
;
fd
=
timerfd_create
(
CLOCK_MONOTONIC
,
0
);
...
...
@@ -420,23 +409,17 @@ static switch_status_t timerfd_start_interval(interval_timer_t *it, int interval
return
SWITCH_STATUS_GENERR
;
}
val
.
it_interval
.
tv_sec
=
0
;
val
.
it_interval
.
tv_nsec
=
interval
*
1000000
;
val
.
it_interval
.
tv_sec
=
interval
/
100
0
;
val
.
it_interval
.
tv_nsec
=
(
interval
%
1000
)
*
1000000
;
val
.
it_value
.
tv_sec
=
0
;
val
.
it_value
.
tv_nsec
=
val
.
it_interval
.
tv_nsec
;
if
(
timerfd_settime
(
fd
,
TFD_TIMER_ABSTIME
,
&
val
,
NULL
)
<
0
)
{
close
(
fd
);
return
SWITCH_STATUS_GENERR
;
}
val
.
it_value
.
tv_nsec
=
100000
;
if
(
(
r
=
read
(
fd
,
&
exp
,
sizeof
(
exp
))
<
0
)
)
{
if
(
timerfd_settime
(
fd
,
0
,
&
val
,
NULL
)
<
0
)
{
close
(
fd
);
return
SWITCH_STATUS_GENERR
;
}
it
->
fd
=
fd
;
return
SWITCH_STATUS_SUCCESS
;
}
...
...
@@ -456,9 +439,7 @@ static switch_status_t _timerfd_init(switch_timer_t *timer)
return
SWITCH_STATUS_GENERR
;
it
=
switch_core_alloc
(
timer
->
memory_pool
,
sizeof
(
*
it
));
if
((
rc
=
timerfd_start_interval
(
it
,
timer
->
interval
))
==
SWITCH_STATUS_SUCCESS
)
{
timer
->
start
=
time_now
(
0
);
timer
->
private_info
=
it
;
}
...
...
@@ -476,27 +457,34 @@ static switch_status_t _timerfd_step(switch_timer_t *timer)
static
switch_status_t
_timerfd_next
(
switch_timer_t
*
timer
)
{
interval_timer_t
*
it
=
timer
->
private_info
;
uint64_t
u64
=
0
;
uint64_t
x
,
u64
=
0
;
if
(
read
(
it
->
fd
,
&
u64
,
sizeof
(
u64
))
<
0
)
{
return
SWITCH_STATUS_GENERR
;
}
else
{
timer
->
tick
+=
u64
;
timer
->
samplecount
=
timer
->
tick
*
timer
->
samples
;
for
(
x
=
0
;
x
<
u64
;
x
++
)
{
it
->
tick
++
;
_timerfd_step
(
timer
);
}
}
return
SWITCH_STATUS_SUCCESS
;
}
static
switch_status_t
_timerfd_sync
(
switch_timer_t
*
timer
)
{
interval_timer_t
*
it
=
timer
->
private_info
;
timer
->
tick
=
it
->
tick
;
return
SWITCH_STATUS_SUCCESS
;
}
static
switch_status_t
_timerfd_check
(
switch_timer_t
*
timer
,
switch_bool_t
step
)
{
interval_timer_t
*
it
=
timer
->
private_info
;
struct
itimerspec
val
;
int
diff
;
int
diff
=
(
int
)(
timer
->
tick
-
it
->
tick
);
timerfd_gettime
(
it
->
fd
,
&
val
);
diff
=
val
.
it_interval
.
tv_nsec
/
1000
;
if
(
diff
>
0
)
{
/* still pending */
timer
->
diff
=
diff
;
...
...
@@ -688,15 +676,6 @@ static switch_status_t timer_init(switch_timer_t *timer)
timer_private_t
*
private_info
;
int
sanity
=
0
;
timer
->
start
=
time_now
(
0
);
if
(
timer
->
interval
==
1
)
{
switch_mutex_lock
(
globals
.
mutex
);
globals
.
timer_count
++
;
switch_mutex_unlock
(
globals
.
mutex
);
return
SWITCH_STATUS_SUCCESS
;
}
#ifdef HAVE_TIMERFD_CREATE
if
(
TFD
==
2
)
{
return
_timerfd_init
(
timer
);
...
...
@@ -764,10 +743,6 @@ static switch_status_t timer_step(switch_timer_t *timer)
timer_private_t
*
private_info
;
uint64_t
samples
;
if
(
timer
->
interval
==
1
)
{
return
SWITCH_STATUS_FALSE
;
}
#ifdef HAVE_TIMERFD_CREATE
if
(
TFD
==
2
)
{
return
_timerfd_step
(
timer
);
...
...
@@ -798,13 +773,9 @@ static switch_status_t timer_sync(switch_timer_t *timer)
{
timer_private_t
*
private_info
;
if
(
timer
->
interval
==
1
)
{
return
timer_generic_sync
(
timer
);
}
#ifdef HAVE_TIMERFD_CREATE
if
(
TFD
==
2
)
{
return
timer_generic
_sync
(
timer
);
return
_timerfd
_sync
(
timer
);
}
#endif
...
...
@@ -835,10 +806,6 @@ static switch_status_t timer_next(switch_timer_t *timer)
#endif
int
delta
;
if
(
timer
->
interval
==
1
)
{
return
SWITCH_STATUS_FALSE
;
}
#ifdef HAVE_TIMERFD_CREATE
if
(
TFD
==
2
)
{
return
_timerfd_next
(
timer
);
...
...
@@ -892,10 +859,6 @@ static switch_status_t timer_check(switch_timer_t *timer, switch_bool_t step)
timer_private_t
*
private_info
;
switch_status_t
status
=
SWITCH_STATUS_SUCCESS
;
if
(
timer
->
interval
==
1
)
{
return
SWITCH_STATUS_FALSE
;
}
#ifdef HAVE_TIMERFD_CREATE
if
(
TFD
==
2
)
{
return
_timerfd_check
(
timer
,
step
);
...
...
@@ -932,15 +895,6 @@ static switch_status_t timer_destroy(switch_timer_t *timer)
{
timer_private_t
*
private_info
;
if
(
timer
->
interval
==
1
)
{
switch_mutex_lock
(
globals
.
mutex
);
if
(
globals
.
timer_count
)
{
globals
.
timer_count
--
;
}
switch_mutex_unlock
(
globals
.
mutex
);
return
SWITCH_STATUS_SUCCESS
;
}
#ifdef HAVE_TIMERFD_CREATE
if
(
TFD
==
2
)
{
return
_timerfd_destroy
(
timer
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论