Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
88660290
提交
88660290
authored
3月 29, 2017
作者:
Shane Bryldt
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FS-10167: Fix to make everything work right with linux again
上级
b41a847b
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
27 行增加
和
25 行删除
+27
-25
ks.h
libs/libks/src/include/ks.h
+1
-0
ks_time.c
libs/libks/src/ks_time.c
+26
-25
没有找到文件。
libs/libks/src/include/ks.h
浏览文件 @
88660290
...
@@ -137,6 +137,7 @@ KS_DECLARE(void) ks_random_string(char *buf, uint16_t len, char *set);
...
@@ -137,6 +137,7 @@ KS_DECLARE(void) ks_random_string(char *buf, uint16_t len, char *set);
#include "ks_rng.h"
#include "ks_rng.h"
#include "ks_acl.h"
#include "ks_acl.h"
#include "ks_base64.h"
#include "ks_base64.h"
#include "ks_time.h"
KS_END_EXTERN_C
KS_END_EXTERN_C
...
...
libs/libks/src/ks_time.c
浏览文件 @
88660290
/*
/*
* Copyright (c) 2007-2014, Anthony Minessale II
* Copyright (c) 2007-2014, Anthony Minessale II
* All rights reserved.
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* modification, are permitted provided that the following conditions
* are met:
* are met:
*
*
* * Redistributions of source code must retain the above copyright
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* notice, this list of conditions and the following disclaimer.
*
*
* * Redistributions in binary form must reproduce the above copyright
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* documentation and/or other materials provided with the distribution.
*
*
* * Neither the name of the original author; nor the names of any contributors
* * Neither the name of the original author; nor the names of any contributors
* may be used to endorse or promote products derived from this software
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* without specific prior written permission.
*
*
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
...
@@ -88,15 +88,10 @@ static inline void win32_init_timers(void)
...
@@ -88,15 +88,10 @@ static inline void win32_init_timers(void)
LeaveCriticalSection
(
&
timer_section
);
LeaveCriticalSection
(
&
timer_section
);
}
}
KS_DECLARE
(
void
)
ks_time_init
(
void
)
{
win32_init_timers
();
}
KS_DECLARE
(
ks_time_t
)
ks_time_now
(
void
)
KS_DECLARE
(
ks_time_t
)
ks_time_now
(
void
)
{
{
ks_time_t
now
;
ks_time_t
now
;
if
(
win32_use_qpc
)
{
if
(
win32_use_qpc
)
{
/* Use QueryPerformanceCounter */
/* Use QueryPerformanceCounter */
uint64_t
count
=
0
;
uint64_t
count
=
0
;
...
@@ -106,14 +101,14 @@ KS_DECLARE(ks_time_t) ks_time_now(void)
...
@@ -106,14 +101,14 @@ KS_DECLARE(ks_time_t) ks_time_now(void)
/* Use good old timeGetTime() */
/* Use good old timeGetTime() */
DWORD
tick_now
;
DWORD
tick_now
;
DWORD
tick_diff
;
DWORD
tick_diff
;
tick_now
=
timeGetTime
();
tick_now
=
timeGetTime
();
if
(
win32_tick_time_since_start
!=
-
1
)
{
if
(
win32_tick_time_since_start
!=
-
1
)
{
EnterCriticalSection
(
&
timer_section
);
EnterCriticalSection
(
&
timer_section
);
/* just add diff (to make it work more than 50 days). */
/* just add diff (to make it work more than 50 days). */
tick_diff
=
tick_now
-
win32_last_get_time_tick
;
tick_diff
=
tick_now
-
win32_last_get_time_tick
;
win32_tick_time_since_start
+=
tick_diff
;
win32_tick_time_since_start
+=
tick_diff
;
win32_last_get_time_tick
=
tick_now
;
win32_last_get_time_tick
=
tick_now
;
now
=
(
win32_tick_time_since_start
*
1000
);
now
=
(
win32_tick_time_since_start
*
1000
);
LeaveCriticalSection
(
&
timer_section
);
LeaveCriticalSection
(
&
timer_section
);
...
@@ -131,7 +126,7 @@ KS_DECLARE(ks_time_t) ks_time_now(void)
...
@@ -131,7 +126,7 @@ KS_DECLARE(ks_time_t) ks_time_now(void)
KS_DECLARE
(
ks_time_t
)
ks_time_now_sec
(
void
)
KS_DECLARE
(
ks_time_t
)
ks_time_now_sec
(
void
)
{
{
ks_time_t
now
;
ks_time_t
now
;
if
(
win32_use_qpc
)
{
if
(
win32_use_qpc
)
{
/* Use QueryPerformanceCounter */
/* Use QueryPerformanceCounter */
uint64_t
count
=
0
;
uint64_t
count
=
0
;
...
@@ -141,14 +136,14 @@ KS_DECLARE(ks_time_t) ks_time_now_sec(void)
...
@@ -141,14 +136,14 @@ KS_DECLARE(ks_time_t) ks_time_now_sec(void)
/* Use good old timeGetTime() */
/* Use good old timeGetTime() */
DWORD
tick_now
;
DWORD
tick_now
;
DWORD
tick_diff
;
DWORD
tick_diff
;
tick_now
=
timeGetTime
();
tick_now
=
timeGetTime
();
if
(
win32_tick_time_since_start
!=
-
1
)
{
if
(
win32_tick_time_since_start
!=
-
1
)
{
EnterCriticalSection
(
&
timer_section
);
EnterCriticalSection
(
&
timer_section
);
/* just add diff (to make it work more than 50 days). */
/* just add diff (to make it work more than 50 days). */
tick_diff
=
tick_now
-
win32_last_get_time_tick
;
tick_diff
=
tick_now
-
win32_last_get_time_tick
;
win32_tick_time_since_start
+=
tick_diff
;
win32_tick_time_since_start
+=
tick_diff
;
win32_last_get_time_tick
=
tick_now
;
win32_last_get_time_tick
=
tick_now
;
now
=
(
win32_tick_time_since_start
/
1000
);
now
=
(
win32_tick_time_since_start
/
1000
);
LeaveCriticalSection
(
&
timer_section
);
LeaveCriticalSection
(
&
timer_section
);
...
@@ -167,15 +162,15 @@ KS_DECLARE(void) ks_sleep(ks_time_t microsec)
...
@@ -167,15 +162,15 @@ KS_DECLARE(void) ks_sleep(ks_time_t microsec)
{
{
LARGE_INTEGER
perfCnt
,
start
,
now
;
LARGE_INTEGER
perfCnt
,
start
,
now
;
QueryPerformanceFrequency
(
&
perfCnt
);
QueryPerformanceFrequency
(
&
perfCnt
);
QueryPerformanceCounter
(
&
start
);
QueryPerformanceCounter
(
&
start
);
do
{
do
{
QueryPerformanceCounter
((
LARGE_INTEGER
*
)
&
now
);
QueryPerformanceCounter
((
LARGE_INTEGER
*
)
&
now
);
SwitchToThread
();
SwitchToThread
();
}
while
((
now
.
QuadPart
-
start
.
QuadPart
)
/
(
float
)(
perfCnt
.
QuadPart
)
*
1000
*
1000
<
(
DWORD
)
microsec
);
}
while
((
now
.
QuadPart
-
start
.
QuadPart
)
/
(
float
)(
perfCnt
.
QuadPart
)
*
1000
*
1000
<
(
DWORD
)
microsec
);
}
}
#else //!WINDOWS, UNIX ETC
#else //!WINDOWS, UNIX ETC
...
@@ -187,7 +182,7 @@ KS_DECLARE(ks_time_t) ks_time_now(void)
...
@@ -187,7 +182,7 @@ KS_DECLARE(ks_time_t) ks_time_now(void)
struct
timespec
ts
;
struct
timespec
ts
;
clock_gettime
(
CLOCK_REALTIME
,
&
ts
);
clock_gettime
(
CLOCK_REALTIME
,
&
ts
);
now
=
(
int64_t
)
ts
.
tv_sec
*
1000000
+
((
int64_t
)
ts
.
tv_nsec
/
1000
);
now
=
(
int64_t
)
ts
.
tv_sec
*
1000000
+
((
int64_t
)
ts
.
tv_nsec
/
1000
);
#else
#else
struct
timeval
tv
;
struct
timeval
tv
;
gettimeofday
(
&
tv
,
NULL
);
gettimeofday
(
&
tv
,
NULL
);
now
=
tv
.
tv_sec
*
1000000
+
tv
.
tv_usec
;
now
=
tv
.
tv_sec
*
1000000
+
tv
.
tv_usec
;
...
@@ -204,7 +199,7 @@ KS_DECLARE(ks_time_t) ks_time_now_sec(void)
...
@@ -204,7 +199,7 @@ KS_DECLARE(ks_time_t) ks_time_now_sec(void)
struct
timespec
ts
;
struct
timespec
ts
;
clock_gettime
(
CLOCK_REALTIME
,
&
ts
);
clock_gettime
(
CLOCK_REALTIME
,
&
ts
);
now
=
(
int64_t
)
ts
.
tv_sec
;
now
=
(
int64_t
)
ts
.
tv_sec
;
#else
#else
struct
timeval
tv
;
struct
timeval
tv
;
gettimeofday
(
&
tv
,
NULL
);
gettimeofday
(
&
tv
,
NULL
);
now
=
tv
.
tv_sec
;
now
=
tv
.
tv_sec
;
...
@@ -232,7 +227,7 @@ KS_DECLARE(void) ks_sleep(ks_time_t microsec)
...
@@ -232,7 +227,7 @@ KS_DECLARE(void) ks_sleep(ks_time_t microsec)
#if defined(HAVE_CLOCK_NANOSLEEP) || defined(__APPLE__)
#if defined(HAVE_CLOCK_NANOSLEEP) || defined(__APPLE__)
struct
timespec
ts
;
struct
timespec
ts
;
#endif
#endif
#if defined(HAVE_CLOCK_NANOSLEEP)
#if defined(HAVE_CLOCK_NANOSLEEP)
ts
.
tv_sec
=
ks_time_sec
(
microsec
);
ts
.
tv_sec
=
ks_time_sec
(
microsec
);
ts
.
tv_nsec
=
ks_time_nsec
(
microsec
);
ts
.
tv_nsec
=
ks_time_nsec
(
microsec
);
...
@@ -244,15 +239,21 @@ KS_DECLARE(void) ks_sleep(ks_time_t microsec)
...
@@ -244,15 +239,21 @@ KS_DECLARE(void) ks_sleep(ks_time_t microsec)
#else
#else
generic_sleep
(
microsec
);
generic_sleep
(
microsec
);
#endif
#endif
#if defined(__APPLE__)
#if defined(__APPLE__)
sched_yield
();
sched_yield
();
#endif
#endif
}
}
#endif
#endif
KS_DECLARE
(
void
)
ks_time_init
(
void
)
{
#ifdef _WINDOWS_
win32_init_timers
();
#endif
}
/* For Emacs:
/* For Emacs:
* Local Variables:
* Local Variables:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论