Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
d0b65a9f
提交
d0b65a9f
authored
4月 06, 2012
作者:
Christopher Rienzo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add test driver for mod_posix_timer
上级
c41a16d4
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
243 行增加
和
0 行删除
+243
-0
Makefile
src/mod/timers/mod_posix_timer/test/Makefile
+6
-0
README
src/mod/timers/mod_posix_timer/test/README
+2
-0
main.c
src/mod/timers/mod_posix_timer/test/main.c
+44
-0
switch.c
src/mod/timers/mod_posix_timer/test/switch.c
+69
-0
switch.h
src/mod/timers/mod_posix_timer/test/switch.h
+122
-0
没有找到文件。
src/mod/timers/mod_posix_timer/test/Makefile
0 → 100644
浏览文件 @
d0b65a9f
all
:
gcc ../mod_posix_timer.c main.c switch.c
-I
.
-o
timer_test
-lpthread
-lrt
-g
-DLOG_LEVEL
=
-1
clean
:
-
rm
timer_test
src/mod/timers/mod_posix_timer/test/README
0 → 100644
浏览文件 @
d0b65a9f
Stress test for mod_posix_timer. Runs without FreeSWITCH.
src/mod/timers/mod_posix_timer/test/main.c
0 → 100644
浏览文件 @
d0b65a9f
#include <switch.h>
#include <stdlib.h>
extern
SWITCH_MODULE_LOAD_FUNCTION
(
mod_posix_timer_load
);
extern
SWITCH_MODULE_SHUTDOWN_FUNCTION
(
mod_posix_timer_shutdown
);
switch_loadable_module_interface_t
*
mod
=
NULL
;
switch_memory_pool_t
pool
=
{
0
};
int
main
(
int
argc
,
char
**
argv
)
{
int
i
;
switch_timer_interface_t
*
timer_if
;
switch_timer_t
*
timer
[
1000
];
mod_posix_timer_load
(
&
mod
,
&
pool
);
timer_if
=
mod
->
timer
;
// TODO create multi-threaded test
// create 10 ms timers
for
(
i
=
0
;
i
<
1000
;
i
++
)
{
timer
[
i
]
=
malloc
(
sizeof
(
switch_timer_t
));
memset
(
timer
[
i
],
0
,
sizeof
(
switch_timer_t
));
timer
[
i
]
->
interval
=
1
;
timer
[
i
]
->
samples
=
8
;
timer_if
->
timer_init
(
timer
[
i
]);
}
for
(
i
=
0
;
i
<
50000
;
i
++
)
{
timer_if
->
timer_next
(
timer
[
0
]);
}
// destroy timers
for
(
i
=
0
;
i
<
1000
;
i
++
)
{
timer_if
->
timer_destroy
(
timer
[
i
]);
free
(
timer
[
i
]);
}
mod_posix_timer_shutdown
();
return
0
;
}
src/mod/timers/mod_posix_timer/test/switch.c
0 → 100644
浏览文件 @
d0b65a9f
#include <switch.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
switch_loadable_module_interface_t
*
switch_loadable_module_create_module_interface
(
switch_memory_pool_t
*
pool
,
const
char
*
name
)
{
return
malloc
(
sizeof
(
switch_loadable_module_interface_t
));
}
void
*
switch_loadable_module_create_interface
(
switch_loadable_module_interface_t
*
mod
,
int
iname
)
{
mod
->
timer
=
malloc
(
sizeof
(
switch_timer_interface_t
));
return
mod
->
timer
;
}
switch_status_t
switch_mutex_lock
(
switch_mutex_t
*
mutex
)
{
return
pthread_mutex_lock
(
mutex
);
}
switch_status_t
switch_mutex_unlock
(
switch_mutex_t
*
mutex
)
{
return
pthread_mutex_unlock
(
mutex
);
}
switch_status_t
switch_mutex_init
(
switch_mutex_t
**
mutex
,
int
flags
,
switch_memory_pool_t
*
pool
)
{
pthread_mutexattr_t
atts
=
{
0
};
pthread_mutexattr_init
(
&
atts
);
if
(
flags
==
SWITCH_MUTEX_NESTED
)
{
pthread_mutexattr_settype
(
&
atts
,
PTHREAD_MUTEX_RECURSIVE_NP
);
}
*
mutex
=
malloc
(
sizeof
(
switch_mutex_t
));
return
pthread_mutex_init
(
*
mutex
,
&
atts
);
}
switch_status_t
switch_thread_cond_create
(
switch_thread_cond_t
**
cond
,
switch_memory_pool_t
*
pool
)
{
*
cond
=
malloc
(
sizeof
(
switch_thread_cond_t
));
return
pthread_cond_init
(
*
cond
,
NULL
);
}
switch_status_t
switch_thread_cond_timedwait
(
switch_thread_cond_t
*
cond
,
switch_mutex_t
*
mutex
,
int
wait
)
{
struct
timespec
dur
=
{
0
,
0
};
clock_gettime
(
CLOCK_REALTIME
,
&
dur
);
dur
.
tv_sec
=
wait
/
1000000000
;
dur
.
tv_nsec
=
wait
%
1000000000
;
return
pthread_cond_timedwait
(
cond
,
mutex
,
&
dur
);
}
switch_status_t
switch_thread_cond_broadcast
(
switch_thread_cond_t
*
cond
)
{
return
pthread_cond_broadcast
(
cond
);
}
void
switch_log_printf
(
int
dummy
,
int
level
,
char
*
format
,
...)
{
va_list
vl
;
va_start
(
vl
,
format
);
if
(
level
>
LOG_LEVEL
)
{
vprintf
(
format
,
vl
);
}
va_end
(
vl
);
}
src/mod/timers/mod_posix_timer/test/switch.h
0 → 100644
浏览文件 @
d0b65a9f
#ifndef SWITCH_H
#define SWITCH_H
#include <pthread.h>
#include <time.h>
#include <signal.h>
#include <string.h>
#define SWITCH_STATUS_SUCCESS 0
#define SWITCH_STATUS_GENERR 1
#define SWITCH_STATUS_FALSE 2
#define SWITCH_MUTEX_NESTED 1
#define SWITCH_CHANNEL_LOG 0
#define SWITCH_LOG_INFO 0
typedef
int
switch_status_t
;
typedef
size_t
switch_size_t
;
typedef
pthread_mutex_t
switch_mutex_t
;
typedef
pthread_cond_t
switch_thread_cond_t
;
typedef
int
switch_memory_pool_t
;
typedef
int
switch_bool_t
;
#define SWITCH_TIMER_INTERFACE 0
typedef
struct
switch_loadable_module_interface
switch_loadable_module_interface_t
;
typedef
struct
switch_timer_interface
switch_timer_interface_t
;
typedef
int
switch_module_flag_t
;
#define SWITCH_API_VERSION 0
#define SWITCH_MOD_DECLARE_DATA
#define SMODF_NONE 0
#define SWITCH_MODULE_LOAD_ARGS (switch_loadable_module_interface_t **module_interface, switch_memory_pool_t *pool)
#define SWITCH_MODULE_RUNTIME_ARGS (void)
#define SWITCH_MODULE_SHUTDOWN_ARGS (void)
typedef
switch_status_t
(
*
switch_module_load_t
)
SWITCH_MODULE_LOAD_ARGS
;
typedef
switch_status_t
(
*
switch_module_runtime_t
)
SWITCH_MODULE_RUNTIME_ARGS
;
typedef
switch_status_t
(
*
switch_module_shutdown_t
)
SWITCH_MODULE_SHUTDOWN_ARGS
;
#define SWITCH_MODULE_LOAD_FUNCTION(name) switch_status_t name SWITCH_MODULE_LOAD_ARGS
#define SWITCH_MODULE_RUNTIME_FUNCTION(name) switch_status_t name SWITCH_MODULE_RUNTIME_ARGS
#define SWITCH_MODULE_SHUTDOWN_FUNCTION(name) switch_status_t name SWITCH_MODULE_SHUTDOWN_ARGS
typedef
struct
switch_loadable_module_function_table
{
int
switch_api_version
;
switch_module_load_t
load
;
switch_module_shutdown_t
shutdown
;
switch_module_runtime_t
runtime
;
switch_module_flag_t
flags
;
}
switch_loadable_module_function_table_t
;
#define SWITCH_MODULE_DEFINITION_EX(name, load, shutdown, runtime, flags) \
static const char modname[] = #name ; \
SWITCH_MOD_DECLARE_DATA switch_loadable_module_function_table_t name##_module_interface = { \
SWITCH_API_VERSION, \
load, \
shutdown, \
runtime, \
flags \
}
#define SWITCH_MODULE_DEFINITION(name, load, shutdown, runtime) \
SWITCH_MODULE_DEFINITION_EX(name, load, shutdown, runtime, SMODF_NONE)
switch_loadable_module_interface_t
*
switch_loadable_module_create_module_interface
(
switch_memory_pool_t
*
pool
,
const
char
*
name
);
typedef
struct
{
int
id
;
int
interval
;
int
tick
;
int
samplecount
;
int
samples
;
int
diff
;
void
*
private_info
;
}
switch_timer_t
;
/*! \brief A table of functions that a timer module implements */
struct
switch_timer_interface
{
/*! the name of the interface */
const
char
*
interface_name
;
/*! function to allocate the timer */
switch_status_t
(
*
timer_init
)
(
switch_timer_t
*
);
/*! function to wait for one cycle to pass */
switch_status_t
(
*
timer_next
)
(
switch_timer_t
*
);
/*! function to step the timer one step */
switch_status_t
(
*
timer_step
)
(
switch_timer_t
*
);
/*! function to reset the timer */
switch_status_t
(
*
timer_sync
)
(
switch_timer_t
*
);
/*! function to check if the current step has expired */
switch_status_t
(
*
timer_check
)
(
switch_timer_t
*
,
switch_bool_t
);
/*! function to deallocate the timer */
switch_status_t
(
*
timer_destroy
)
(
switch_timer_t
*
);
int
refs
;
switch_mutex_t
*
reflock
;
switch_loadable_module_interface_t
*
parent
;
struct
switch_timer_interface
*
next
;
};
struct
switch_loadable_module_interface
{
switch_timer_interface_t
*
timer
;
};
void
*
switch_loadable_module_create_interface
(
switch_loadable_module_interface_t
*
mod
,
int
iname
);
switch_status_t
switch_mutex_lock
(
switch_mutex_t
*
mutex
);
switch_status_t
switch_mutex_unlock
(
switch_mutex_t
*
mutex
);
switch_status_t
switch_mutex_init
(
switch_mutex_t
**
mutex
,
int
flags
,
switch_memory_pool_t
*
pool
);
switch_status_t
switch_thread_cond_create
(
switch_thread_cond_t
**
cond
,
switch_memory_pool_t
*
pool
);
switch_status_t
switch_thread_cond_timedwait
(
switch_thread_cond_t
*
cond
,
switch_mutex_t
*
mutex
,
int
wait
);
switch_status_t
switch_thread_cond_broadcast
(
switch_thread_cond_t
*
cond
);
void
switch_log_printf
(
int
dummy
,
int
level
,
char
*
format
,
...);
#endif
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论