Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
asterisk
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Voice
asterisk
Commits
0056f260
Commit
0056f260
authored
6 years ago
by
George Joseph
Committed by
Gerrit Code Review
6 years ago
Browse files
Options
Downloads
Plain Diff
Merge "res_smdi.c: Fix module ref counting and inverted test."
parents
95495117
3601329c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
res/res_smdi.c
+18
-12
18 additions, 12 deletions
res/res_smdi.c
with
18 additions
and
12 deletions
res/res_smdi.c
+
18
−
12
View file @
0056f260
...
@@ -223,10 +223,12 @@ static struct {
...
@@ -223,10 +223,12 @@ static struct {
static
void
smdi_interface_destroy
(
void
*
obj
)
static
void
smdi_interface_destroy
(
void
*
obj
)
{
{
struct
ast_smdi_interface
*
iface
=
obj
;
struct
ast_smdi_interface
*
iface
=
obj
;
int
mod_unref_defer
=
0
;
if
(
iface
->
thread
!=
AST_PTHREADT_NULL
&&
iface
->
thread
!=
AST_PTHREADT_STOP
)
{
if
(
iface
->
thread
!=
AST_PTHREADT_NULL
&&
iface
->
thread
!=
AST_PTHREADT_STOP
)
{
pthread_cancel
(
iface
->
thread
);
pthread_cancel
(
iface
->
thread
);
pthread_join
(
iface
->
thread
,
NULL
);
pthread_join
(
iface
->
thread
,
NULL
);
mod_unref_defer
=
1
;
}
}
iface
->
thread
=
AST_PTHREADT_STOP
;
iface
->
thread
=
AST_PTHREADT_STOP
;
...
@@ -243,9 +245,9 @@ static void smdi_interface_destroy(void *obj)
...
@@ -243,9 +245,9 @@ static void smdi_interface_destroy(void *obj)
ast_mutex_destroy
(
&
iface
->
mwi_q_lock
);
ast_mutex_destroy
(
&
iface
->
mwi_q_lock
);
ast_cond_destroy
(
&
iface
->
mwi_q_cond
);
ast_cond_destroy
(
&
iface
->
mwi_q_cond
);
ast_free
(
iface
);
if
(
mod_unref_defer
)
{
ast_module_unref
(
ast_module_info
->
self
);
ast_module_unref
(
ast_module_info
->
self
);
}
}
}
/*!
/*!
...
@@ -608,7 +610,6 @@ static void *smdi_read(void *iface_p)
...
@@ -608,7 +610,6 @@ static void *smdi_read(void *iface_p)
md_msg
=
ao2_alloc
(
sizeof
(
*
md_msg
),
NULL
);
md_msg
=
ao2_alloc
(
sizeof
(
*
md_msg
),
NULL
);
if
(
!
md_msg
)
{
if
(
!
md_msg
)
{
ao2_ref
(
iface
,
-
1
);
return
NULL
;
return
NULL
;
}
}
...
@@ -618,7 +619,6 @@ static void *smdi_read(void *iface_p)
...
@@ -618,7 +619,6 @@ static void *smdi_read(void *iface_p)
if
(
c
==
EOF
)
{
if
(
c
==
EOF
)
{
ast_log
(
LOG_ERROR
,
"Unexpected EOF while reading MD message
\n
"
);
ast_log
(
LOG_ERROR
,
"Unexpected EOF while reading MD message
\n
"
);
ao2_ref
(
md_msg
,
-
1
);
ao2_ref
(
md_msg
,
-
1
);
ao2_ref
(
iface
,
-
1
);
return
NULL
;
return
NULL
;
}
}
md_msg
->
mesg_desk_num
[
i
]
=
(
char
)
c
;
md_msg
->
mesg_desk_num
[
i
]
=
(
char
)
c
;
...
@@ -635,7 +635,6 @@ static void *smdi_read(void *iface_p)
...
@@ -635,7 +635,6 @@ static void *smdi_read(void *iface_p)
if
(
c
==
EOF
)
{
if
(
c
==
EOF
)
{
ast_log
(
LOG_ERROR
,
"Unexpected EOF while reading SMDI message
\n
"
);
ast_log
(
LOG_ERROR
,
"Unexpected EOF while reading SMDI message
\n
"
);
ao2_ref
(
md_msg
,
-
1
);
ao2_ref
(
md_msg
,
-
1
);
ao2_ref
(
iface
,
-
1
);
return
NULL
;
return
NULL
;
}
}
md_msg
->
mesg_desk_term
[
i
]
=
(
char
)
c
;
md_msg
->
mesg_desk_term
[
i
]
=
(
char
)
c
;
...
@@ -651,7 +650,6 @@ static void *smdi_read(void *iface_p)
...
@@ -651,7 +650,6 @@ static void *smdi_read(void *iface_p)
if
(
c
==
EOF
)
{
if
(
c
==
EOF
)
{
ast_log
(
LOG_ERROR
,
"Unexpected EOF while reading SMDI message
\n
"
);
ast_log
(
LOG_ERROR
,
"Unexpected EOF while reading SMDI message
\n
"
);
ao2_ref
(
md_msg
,
-
1
);
ao2_ref
(
md_msg
,
-
1
);
ao2_ref
(
iface
,
-
1
);
return
NULL
;
return
NULL
;
}
}
md_msg
->
type
=
(
char
)
c
;
md_msg
->
type
=
(
char
)
c
;
...
@@ -730,7 +728,6 @@ static void *smdi_read(void *iface_p)
...
@@ -730,7 +728,6 @@ static void *smdi_read(void *iface_p)
mwi_msg
=
ao2_alloc
(
sizeof
(
*
mwi_msg
),
NULL
);
mwi_msg
=
ao2_alloc
(
sizeof
(
*
mwi_msg
),
NULL
);
if
(
!
mwi_msg
)
{
if
(
!
mwi_msg
)
{
ao2_ref
(
iface
,
-
1
);
return
NULL
;
return
NULL
;
}
}
...
@@ -764,7 +761,6 @@ static void *smdi_read(void *iface_p)
...
@@ -764,7 +761,6 @@ static void *smdi_read(void *iface_p)
if
(
c
==
EOF
)
{
if
(
c
==
EOF
)
{
ast_log
(
LOG_ERROR
,
"Unexpected EOF while reading MWI message
\n
"
);
ast_log
(
LOG_ERROR
,
"Unexpected EOF while reading MWI message
\n
"
);
ao2_ref
(
mwi_msg
,
-
1
);
ao2_ref
(
mwi_msg
,
-
1
);
ao2_ref
(
iface
,
-
1
);
return
NULL
;
return
NULL
;
}
}
mwi_msg
->
cause
[
i
]
=
(
char
)
c
;
mwi_msg
->
cause
[
i
]
=
(
char
)
c
;
...
@@ -785,7 +781,6 @@ static void *smdi_read(void *iface_p)
...
@@ -785,7 +781,6 @@ static void *smdi_read(void *iface_p)
}
}
ast_log
(
LOG_ERROR
,
"Error reading from SMDI interface %s, stopping listener thread
\n
"
,
iface
->
name
);
ast_log
(
LOG_ERROR
,
"Error reading from SMDI interface %s, stopping listener thread
\n
"
,
iface
->
name
);
ao2_ref
(
iface
,
-
1
);
return
NULL
;
return
NULL
;
}
}
...
@@ -982,6 +977,11 @@ static int smdi_load(int reload)
...
@@ -982,6 +977,11 @@ static int smdi_load(int reload)
return
0
;
return
0
;
new_ifaces
=
ao2_container_alloc_list
(
AO2_ALLOC_OPT_LOCK_MUTEX
,
0
,
NULL
,
smdi_ifaces_cmp_fn
);
new_ifaces
=
ao2_container_alloc_list
(
AO2_ALLOC_OPT_LOCK_MUTEX
,
0
,
NULL
,
smdi_ifaces_cmp_fn
);
if
(
!
new_ifaces
)
{
ast_config_destroy
(
conf
);
return
-
1
;
}
for
(
v
=
ast_variable_browse
(
conf
,
"interfaces"
);
v
;
v
=
v
->
next
)
{
for
(
v
=
ast_variable_browse
(
conf
,
"interfaces"
);
v
;
v
=
v
->
next
)
{
RAII_VAR
(
struct
ast_smdi_interface
*
,
iface
,
NULL
,
ao2_cleanup
);
RAII_VAR
(
struct
ast_smdi_interface
*
,
iface
,
NULL
,
ao2_cleanup
);
...
@@ -1104,7 +1104,13 @@ static int smdi_load(int reload)
...
@@ -1104,7 +1104,13 @@ static int smdi_load(int reload)
/* set the message expiry time */
/* set the message expiry time */
iface
->
msg_expiry
=
msg_expiry
;
iface
->
msg_expiry
=
msg_expiry
;
/* start the listener thread */
/*
* start the listener thread
*
* The listener thread does not actually hold a ref to iface. When all
* external refs go away, the destructor will stop the listener thread
* before actually destroying the iface object.
*/
ast_verb
(
3
,
"Starting SMDI monitor thread for %s
\n
"
,
iface
->
name
);
ast_verb
(
3
,
"Starting SMDI monitor thread for %s
\n
"
,
iface
->
name
);
if
(
ast_pthread_create_background
(
&
iface
->
thread
,
NULL
,
smdi_read
,
iface
))
{
if
(
ast_pthread_create_background
(
&
iface
->
thread
,
NULL
,
smdi_read
,
iface
))
{
ast_log
(
LOG_ERROR
,
"Error starting SMDI monitor thread for %s
\n
"
,
iface
->
name
);
ast_log
(
LOG_ERROR
,
"Error starting SMDI monitor thread for %s
\n
"
,
iface
->
name
);
...
@@ -1154,7 +1160,7 @@ static int smdi_load(int reload)
...
@@ -1154,7 +1160,7 @@ static int smdi_load(int reload)
return
-
1
;
return
-
1
;
}
}
if
(
ao2_container_count
(
new_ifaces
))
{
if
(
!
ao2_container_count
(
new_ifaces
))
{
res
=
1
;
res
=
1
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment