Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
0ec9ffe6
提交
0ec9ffe6
authored
8月 04, 2010
作者:
Andrew Thompson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Tony said I should use a rwlock for this, so now I do
上级
7b5803f7
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
28 行增加
和
20 行删除
+28
-20
mod_erlang_event.c
src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c
+27
-19
mod_erlang_event.h
src/mod/event_handlers/mod_erlang_event/mod_erlang_event.h
+1
-1
没有找到文件。
src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c
浏览文件 @
0ec9ffe6
...
@@ -148,7 +148,11 @@ static void send_event_to_attached_sessions(listener_t *listener, switch_event_t
...
@@ -148,7 +148,11 @@ static void send_event_to_attached_sessions(listener_t *listener, switch_event_t
return
;
return
;
}
}
if
((
s
=
(
session_elem_t
*
)
switch_core_hash_find
(
listener
->
sessions
,
uuid
)))
{
switch_thread_rwlock_rdlock
(
listener
->
session_rwlock
);
s
=
(
session_elem_t
*
)
switch_core_hash_find
(
listener
->
sessions
,
uuid
);
switch_thread_rwlock_unlock
(
listener
->
session_rwlock
);
if
(
s
)
{
int
send
=
0
;
int
send
=
0
;
if
(
s
->
event_list
[
SWITCH_EVENT_ALL
])
{
if
(
s
->
event_list
[
SWITCH_EVENT_ALL
])
{
send
=
1
;
send
=
1
;
...
@@ -315,7 +319,9 @@ static listener_t *find_listener(char *nodename)
...
@@ -315,7 +319,9 @@ static listener_t *find_listener(char *nodename)
static
void
add_session_elem_to_listener
(
listener_t
*
listener
,
session_elem_t
*
session_element
)
static
void
add_session_elem_to_listener
(
listener_t
*
listener
,
session_elem_t
*
session_element
)
{
{
switch_core_hash_insert_locked
(
listener
->
sessions
,
session_element
->
uuid_str
,
(
void
*
)
session_element
,
listener
->
session_mutex
);
switch_thread_rwlock_wrlock
(
listener
->
session_rwlock
);
switch_core_hash_insert
(
listener
->
sessions
,
session_element
->
uuid_str
,
(
void
*
)
session_element
);
switch_thread_rwlock_unlock
(
listener
->
session_rwlock
);
}
}
...
@@ -340,9 +346,9 @@ static void destroy_session_elem(session_elem_t *session_element)
...
@@ -340,9 +346,9 @@ static void destroy_session_elem(session_elem_t *session_element)
static
void
remove_session_elem_from_listener_locked
(
listener_t
*
listener
,
session_elem_t
*
session_element
)
static
void
remove_session_elem_from_listener_locked
(
listener_t
*
listener
,
session_elem_t
*
session_element
)
{
{
switch_
mutex_lock
(
listener
->
session_mutex
);
switch_
thread_rwlock_wrlock
(
listener
->
session_rwlock
);
remove_session_elem_from_listener
(
listener
,
session_element
);
remove_session_elem_from_listener
(
listener
,
session_element
);
switch_
mutex_unlock
(
listener
->
session_mutex
);
switch_
thread_rwlock_unlock
(
listener
->
session_rwlock
);
}
}
...
@@ -353,16 +359,16 @@ session_elem_t *find_session_elem_by_pid(listener_t *listener, erlang_pid *pid)
...
@@ -353,16 +359,16 @@ session_elem_t *find_session_elem_by_pid(listener_t *listener, erlang_pid *pid)
void
*
val
=
NULL
;
void
*
val
=
NULL
;
session_elem_t
*
session
=
NULL
;
session_elem_t
*
session
=
NULL
;
switch_
mutex_lock
(
listener
->
session_mutex
);
switch_
thread_rwlock_rdlock
(
listener
->
session_rwlock
);
for
(
iter
=
switch_hash_first
(
NULL
,
listener
->
sessions
);
iter
;
iter
=
switch_hash_next
(
iter
))
{
for
(
iter
=
switch_hash_first
(
NULL
,
listener
->
sessions
);
iter
;
iter
=
switch_hash_next
(
iter
))
{
switch_hash_this
(
iter
,
&
key
,
NULL
,
&
val
);
switch_hash_this
(
iter
,
&
key
,
NULL
,
&
val
);
session
=
(
session_elem_t
*
)
val
;
session
=
(
session_elem_t
*
)
val
;
if
(
session
->
process
.
type
==
ERLANG_PID
&&
!
ei_compare_pids
(
pid
,
&
session
->
process
.
pid
))
{
if
(
session
->
process
.
type
==
ERLANG_PID
&&
!
ei_compare_pids
(
pid
,
&
session
->
process
.
pid
))
{
switch_
mutex_unlock
(
listener
->
session_mutex
);
switch_
thread_rwlock_unlock
(
listener
->
session_rwlock
);
return
session
;
return
session
;
}
}
}
}
switch_
mutex_unlock
(
listener
->
session_mutex
);
switch_
thread_rwlock_unlock
(
listener
->
session_rwlock
);
return
NULL
;
return
NULL
;
}
}
...
@@ -579,7 +585,7 @@ static switch_status_t check_attached_sessions(listener_t *listener)
...
@@ -579,7 +585,7 @@ static switch_status_t check_attached_sessions(listener_t *listener)
if they have pending events in their queues then send them
if they have pending events in their queues then send them
if the session has finished then clean it up
if the session has finished then clean it up
*/
*/
switch_
mutex_lock
(
listener
->
session_mutex
);
switch_
thread_rwlock_rdlock
(
listener
->
session_rwlock
);
for
(
iter
=
switch_hash_first
(
NULL
,
listener
->
sessions
);
iter
;
iter
=
switch_hash_next
(
iter
))
{
for
(
iter
=
switch_hash_first
(
NULL
,
listener
->
sessions
);
iter
;
iter
=
switch_hash_next
(
iter
))
{
switch_hash_this
(
iter
,
&
key
,
NULL
,
&
value
);
switch_hash_this
(
iter
,
&
key
,
NULL
,
&
value
);
sp
=
(
session_elem_t
*
)
value
;
sp
=
(
session_elem_t
*
)
value
;
...
@@ -659,6 +665,9 @@ static switch_status_t check_attached_sessions(listener_t *listener)
...
@@ -659,6 +665,9 @@ static switch_status_t check_attached_sessions(listener_t *listener)
switch_event_destroy
(
&
pevent
);
switch_event_destroy
(
&
pevent
);
}
}
}
}
switch_thread_rwlock_unlock
(
listener
->
session_rwlock
);
/* release the read lock and get a write lock */
switch_thread_rwlock_wrlock
(
listener
->
session_rwlock
);
/* do the deferred remove */
/* do the deferred remove */
for
(
header
=
event
->
headers
;
header
;
header
=
header
->
next
)
{
for
(
header
=
event
->
headers
;
header
;
header
=
header
->
next
)
{
if
((
sp
=
(
session_elem_t
*
)
switch_core_hash_find
(
listener
->
sessions
,
header
->
value
)))
{
if
((
sp
=
(
session_elem_t
*
)
switch_core_hash_find
(
listener
->
sessions
,
header
->
value
)))
{
...
@@ -667,7 +676,7 @@ static switch_status_t check_attached_sessions(listener_t *listener)
...
@@ -667,7 +676,7 @@ static switch_status_t check_attached_sessions(listener_t *listener)
}
}
}
}
switch_
mutex_unlock
(
listener
->
session_mutex
);
switch_
thread_rwlock_unlock
(
listener
->
session_rwlock
);
if
(
prefs
.
done
)
{
if
(
prefs
.
done
)
{
return
SWITCH_STATUS_FALSE
;
/* we're shutting down */
return
SWITCH_STATUS_FALSE
;
/* we're shutting down */
}
else
{
}
else
{
...
@@ -996,14 +1005,13 @@ static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t *thread, void *obj)
...
@@ -996,14 +1005,13 @@ static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t *thread, void *obj)
remove_binding
(
listener
,
NULL
);
remove_binding
(
listener
,
NULL
);
/* clean up all the attached sessions */
/* clean up all the attached sessions */
switch_mutex_lock
(
listener
->
session_mutex
);
// TODO is iterating thread safe?
switch_thread_rwlock_wrlock
(
listener
->
session_rwlock
);
/* TODO destroy memory pools since they're not children of the listener's pool */
for
(
iter
=
switch_hash_first
(
NULL
,
listener
->
sessions
);
iter
;
iter
=
switch_hash_next
(
iter
))
{
for
(
iter
=
switch_hash_first
(
NULL
,
listener
->
sessions
);
iter
;
iter
=
switch_hash_next
(
iter
))
{
switch_hash_this
(
iter
,
&
key
,
NULL
,
&
value
);
switch_hash_this
(
iter
,
&
key
,
NULL
,
&
value
);
s
=
(
session_elem_t
*
)
value
;
s
=
(
session_elem_t
*
)
value
;
destroy_session_elem
(
s
);
destroy_session_elem
(
s
);
}
}
switch_
mutex_unlock
(
listener
->
session_mutex
);
switch_
thread_rwlock_unlock
(
listener
->
session_rwlock
);
if
(
listener
->
pool
)
{
if
(
listener
->
pool
)
{
switch_memory_pool_t
*
pool
=
listener
->
pool
;
switch_memory_pool_t
*
pool
=
listener
->
pool
;
...
@@ -1134,7 +1142,7 @@ static listener_t *new_listener(struct ei_cnode_s *ec, int clientfd)
...
@@ -1134,7 +1142,7 @@ static listener_t *new_listener(struct ei_cnode_s *ec, int clientfd)
listener
->
level
=
SWITCH_LOG_DEBUG
;
listener
->
level
=
SWITCH_LOG_DEBUG
;
switch_mutex_init
(
&
listener
->
flag_mutex
,
SWITCH_MUTEX_NESTED
,
listener
->
pool
);
switch_mutex_init
(
&
listener
->
flag_mutex
,
SWITCH_MUTEX_NESTED
,
listener
->
pool
);
switch_mutex_init
(
&
listener
->
sock_mutex
,
SWITCH_MUTEX_NESTED
,
listener
->
pool
);
switch_mutex_init
(
&
listener
->
sock_mutex
,
SWITCH_MUTEX_NESTED
,
listener
->
pool
);
switch_
mutex_init
(
&
listener
->
session_mutex
,
SWITCH_MUTEX_NESTED
,
listener
->
pool
);
switch_
thread_rwlock_create
(
&
listener
->
session_rwlock
,
listener
->
pool
);
switch_core_hash_init
(
&
listener
->
event_hash
,
listener
->
pool
);
switch_core_hash_init
(
&
listener
->
event_hash
,
listener
->
pool
);
switch_core_hash_init
(
&
listener
->
sessions
,
listener
->
pool
);
switch_core_hash_init
(
&
listener
->
sessions
,
listener
->
pool
);
...
@@ -1349,12 +1357,11 @@ int count_listener_sessions(listener_t *listener)
...
@@ -1349,12 +1357,11 @@ int count_listener_sessions(listener_t *listener)
int
count
=
0
;
int
count
=
0
;
switch_hash_index_t
*
iter
;
switch_hash_index_t
*
iter
;
switch_
mutex_lock
(
listener
->
session_mutex
);
switch_
thread_rwlock_rdlock
(
listener
->
session_rwlock
);
for
(
iter
=
switch_hash_first
(
NULL
,
listener
->
sessions
);
iter
;
iter
=
switch_hash_next
(
iter
))
{
for
(
iter
=
switch_hash_first
(
NULL
,
listener
->
sessions
);
iter
;
iter
=
switch_hash_next
(
iter
))
{
count
++
;
count
++
;
}
}
switch_thread_rwlock_unlock
(
listener
->
session_rwlock
);
switch_mutex_unlock
(
listener
->
session_mutex
);
return
count
;
return
count
;
}
}
...
@@ -1559,7 +1566,7 @@ SWITCH_STANDARD_API(erlang_cmd)
...
@@ -1559,7 +1566,7 @@ SWITCH_STANDARD_API(erlang_cmd)
void
*
value
;
void
*
value
;
found
=
1
;
found
=
1
;
switch_
mutex_lock
(
l
->
session_mutex
);
switch_
thread_rwlock_rdlock
(
l
->
session_rwlock
);
for
(
iter
=
switch_hash_first
(
NULL
,
l
->
sessions
);
iter
;
iter
=
switch_hash_next
(
iter
))
{
for
(
iter
=
switch_hash_first
(
NULL
,
l
->
sessions
);
iter
;
iter
=
switch_hash_next
(
iter
))
{
empty
=
0
;
empty
=
0
;
switch_hash_this
(
iter
,
&
key
,
NULL
,
&
value
);
switch_hash_this
(
iter
,
&
key
,
NULL
,
&
value
);
...
@@ -1571,7 +1578,7 @@ SWITCH_STANDARD_API(erlang_cmd)
...
@@ -1571,7 +1578,7 @@ SWITCH_STANDARD_API(erlang_cmd)
if
(
empty
)
{
if
(
empty
)
{
stream
->
write_function
(
stream
,
"No active sessions for %s
\n
"
,
argv
[
1
]);
stream
->
write_function
(
stream
,
"No active sessions for %s
\n
"
,
argv
[
1
]);
}
}
switch_
mutex_unlock
(
l
->
session_mutex
);
switch_
thread_rwlock_unlock
(
l
->
session_rwlock
);
break
;
break
;
}
}
}
}
...
@@ -1581,7 +1588,8 @@ SWITCH_STANDARD_API(erlang_cmd)
...
@@ -1581,7 +1588,8 @@ SWITCH_STANDARD_API(erlang_cmd)
stream
->
write_function
(
stream
,
"Could not find a listener for %s
\n
"
,
argv
[
1
]);
stream
->
write_function
(
stream
,
"Could not find a listener for %s
\n
"
,
argv
[
1
]);
}
else
{
}
else
{
stream
->
write_function
(
stream
,
"USAGE: erlang sessions <nodename>
\n
"
);
stream
->
write_function
(
stream
,
"USAGE: erlang sessions <nodename>
\n
"
" erlang listeners
\n
"
);
goto
done
;
goto
done
;
}
}
...
...
src/mod/event_handlers/mod_erlang_event/mod_erlang_event.h
浏览文件 @
0ec9ffe6
...
@@ -107,7 +107,7 @@ struct listener {
...
@@ -107,7 +107,7 @@ struct listener {
switch_hash_t
*
event_hash
;
switch_hash_t
*
event_hash
;
switch_hash_t
*
spawn_pid_hash
;
switch_hash_t
*
spawn_pid_hash
;
switch_thread_rwlock_t
*
rwlock
;
switch_thread_rwlock_t
*
rwlock
;
switch_
mutex_t
*
session_mutex
;
switch_
thread_rwlock_t
*
session_rwlock
;
//session_elem_t *session_list;
//session_elem_t *session_list;
switch_hash_t
*
sessions
;
switch_hash_t
*
sessions
;
int
lost_events
;
int
lost_events
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论