[Asterisk-code-review] res pjsip: Create human friendly serializer names. (asterisk[master])
Richard Mudgett
asteriskteam at digium.com
Fri Jan 8 14:08:24 CST 2016
Richard Mudgett has uploaded a new change for review.
https://gerrit.asterisk.org/1958
Change subject: res_pjsip: Create human friendly serializer names.
......................................................................
res_pjsip: Create human friendly serializer names.
PJSIP name formats:
pjsip/aor/<aor>-<seq> -- registrar thread pool serializer
pjsip/default-<seq> -- default thread pool serializer
pjsip/messaging-<seq> -- messaging thread pool serializer
pjsip/outreg/<registration>-<seq> -- outbound registration thread pool
serializer
pjsip/pubsub/<endpoint>-<seq> -- pubsub thread pool serializer
pjsip/refer/<endpoint>-<seq> -- REFER thread pool serializer
pjsip/session/<endpoint>-<seq> -- session thread pool serializer
pjsip/websocket-<seq> -- websocket thread pool serializer
Change-Id: Iff9df8da3ddae1132cb2ef65f64df0c465c5e084
---
M include/asterisk/res_pjsip.h
M res/res_pjsip.c
M res/res_pjsip_messaging.c
M res/res_pjsip_outbound_registration.c
M res/res_pjsip_pubsub.c
M res/res_pjsip_refer.c
M res/res_pjsip_registrar.c
M res/res_pjsip_session.c
M res/res_pjsip_transport_websocket.c
9 files changed, 43 insertions(+), 17 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/58/1958/1
diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h
index d9123f9..165692b 100644
--- a/include/asterisk/res_pjsip.h
+++ b/include/asterisk/res_pjsip.h
@@ -1106,32 +1106,36 @@
/*!
* \brief Create a new serializer for SIP tasks
+ * \since 13.8.0
*
* See \ref ast_threadpool_serializer for more information on serializers.
* SIP creates serializers so that tasks operating on similar data will run
* in sequence.
*
+ * \param name Creator's name suffix for the serializer.
+ *
* \retval NULL Failure
* \retval non-NULL Newly-created serializer
*/
-struct ast_taskprocessor *ast_sip_create_serializer(void);
+struct ast_taskprocessor *ast_sip_create_serializer(const char *name);
struct ast_serializer_shutdown_group;
/*!
* \brief Create a new serializer for SIP tasks
- * \since 13.5.0
+ * \since 13.8.0
*
* See \ref ast_threadpool_serializer for more information on serializers.
* SIP creates serializers so that tasks operating on similar data will run
* in sequence.
*
+ * \param name Creator's name suffix for the serializer.
* \param shutdown_group Group shutdown controller. (NULL if no group association)
*
* \retval NULL Failure
* \retval non-NULL Newly-created serializer
*/
-struct ast_taskprocessor *ast_sip_create_serializer_group(struct ast_serializer_shutdown_group *shutdown_group);
+struct ast_taskprocessor *ast_sip_create_serializer_group(const char *name, struct ast_serializer_shutdown_group *shutdown_group);
/*!
* \brief Set a serializer on a SIP dialog so requests and responses are automatically serialized
diff --git a/res/res_pjsip.c b/res/res_pjsip.c
index a4748d2..b4ad7e0 100644
--- a/res/res_pjsip.c
+++ b/res/res_pjsip.c
@@ -3433,23 +3433,30 @@
return 0;
}
-struct ast_taskprocessor *ast_sip_create_serializer_group(struct ast_serializer_shutdown_group *shutdown_group)
+struct ast_taskprocessor *ast_sip_create_serializer_group(const char *name, struct ast_serializer_shutdown_group *shutdown_group)
{
struct ast_taskprocessor *serializer;
- char name[AST_UUID_STR_LEN];
+ char tps_name[AST_TASKPROCESSOR_MAX_NAME + 1];
+ char seq[8 + 1 + 1];
- ast_uuid_generate_str(name, sizeof(name));
+ /*
+ * Create name with seq number appended.
+ * Truncate suffix name to ensure string fits.
+ */
+ snprintf(seq, sizeof(seq), "-%08x", ast_taskprocessor_seq_num());
+ snprintf(tps_name, sizeof(tps_name) - sizeof(seq) + 1, "pjsip/%s", name);
+ strcat(tps_name, seq);
- serializer = ast_threadpool_serializer_group(name, sip_threadpool, shutdown_group);
+ serializer = ast_threadpool_serializer_group(tps_name, sip_threadpool, shutdown_group);
if (!serializer) {
return NULL;
}
return serializer;
}
-struct ast_taskprocessor *ast_sip_create_serializer(void)
+struct ast_taskprocessor *ast_sip_create_serializer(const char *name)
{
- return ast_sip_create_serializer_group(NULL);
+ return ast_sip_create_serializer_group(name, NULL);
}
/*!
@@ -3482,7 +3489,7 @@
int idx;
for (idx = 0; idx < SERIALIZER_POOL_SIZE; ++idx) {
- serializer_pool[idx] = ast_sip_create_serializer();
+ serializer_pool[idx] = ast_sip_create_serializer("default");
if (!serializer_pool[idx]) {
serializer_pool_shutdown();
return -1;
diff --git a/res/res_pjsip_messaging.c b/res/res_pjsip_messaging.c
index f398505..f0ff2ce 100644
--- a/res/res_pjsip_messaging.c
+++ b/res/res_pjsip_messaging.c
@@ -758,7 +758,7 @@
return AST_MODULE_LOAD_DECLINE;
}
- message_serializer = ast_sip_create_serializer();
+ message_serializer = ast_sip_create_serializer("messaging");
if (!message_serializer) {
ast_sip_unregister_service(&messaging_module);
ast_msg_tech_unregister(&msg_tech);
diff --git a/res/res_pjsip_outbound_registration.c b/res/res_pjsip_outbound_registration.c
index 88007d1..f96a33c 100644
--- a/res/res_pjsip_outbound_registration.c
+++ b/res/res_pjsip_outbound_registration.c
@@ -977,6 +977,7 @@
static struct sip_outbound_registration_state *sip_outbound_registration_state_alloc(struct sip_outbound_registration *registration)
{
struct sip_outbound_registration_state *state;
+ char outreg_name[AST_TASKPROCESSOR_MAX_NAME + 1];
state = ao2_alloc(sizeof(*state), sip_outbound_registration_state_destroy);
if (!state) {
@@ -989,7 +990,10 @@
return NULL;
}
- state->client_state->serializer = ast_sip_create_serializer_group(shutdown_group);
+ snprintf(outreg_name, sizeof(outreg_name), "outreg/%s",
+ ast_sorcery_object_get_id(registration));
+ state->client_state->serializer = ast_sip_create_serializer_group(outreg_name,
+ shutdown_group);
if (!state->client_state->serializer) {
ao2_cleanup(state);
return NULL;
diff --git a/res/res_pjsip_pubsub.c b/res/res_pjsip_pubsub.c
index bbf2128..c067f91 100644
--- a/res/res_pjsip_pubsub.c
+++ b/res/res_pjsip_pubsub.c
@@ -1234,6 +1234,7 @@
static struct sip_subscription_tree *allocate_subscription_tree(struct ast_sip_endpoint *endpoint)
{
struct sip_subscription_tree *sub_tree;
+ char pubsub_name[AST_TASKPROCESSOR_MAX_NAME + 1];
sub_tree = ao2_alloc(sizeof *sub_tree, subscription_tree_destructor);
if (!sub_tree) {
@@ -1242,7 +1243,9 @@
ast_module_ref(ast_module_info->self);
- sub_tree->serializer = ast_sip_create_serializer();
+ snprintf(pubsub_name, sizeof(pubsub_name), "pubsub/%s",
+ ast_sorcery_object_get_id(endpoint));
+ sub_tree->serializer = ast_sip_create_serializer(pubsub_name);
if (!sub_tree->serializer) {
ao2_ref(sub_tree, -1);
return NULL;
diff --git a/res/res_pjsip_refer.c b/res/res_pjsip_refer.c
index 657406b..d9458ad 100644
--- a/res/res_pjsip_refer.c
+++ b/res/res_pjsip_refer.c
@@ -342,6 +342,7 @@
const pj_str_t str_true = { "true", 4 };
pjsip_tx_data *tdata;
pjsip_hdr hdr_list;
+ char refer_name[AST_TASKPROCESSOR_MAX_NAME + 1];
*progress = NULL;
@@ -363,7 +364,9 @@
/* To prevent a potential deadlock we need the dialog so we can lock/unlock */
(*progress)->dlg = session->inv_session->dlg;
- if (!((*progress)->serializer = ast_sip_create_serializer())) {
+ snprintf(refer_name, sizeof(refer_name), "refer/%s",
+ ast_sorcery_object_get_id(session->endpoint));
+ if (!((*progress)->serializer = ast_sip_create_serializer(refer_name))) {
goto error;
}
diff --git a/res/res_pjsip_registrar.c b/res/res_pjsip_registrar.c
index b9ad0ea..e169e42 100644
--- a/res/res_pjsip_registrar.c
+++ b/res/res_pjsip_registrar.c
@@ -231,6 +231,7 @@
static struct serializer *serializer_create(const char *aor_name)
{
+ char registered_name[AST_TASKPROCESSOR_MAX_NAME + 1];
size_t size = strlen(aor_name) + 1;
struct serializer *ser = ao2_alloc(
sizeof(*ser) + size, serializer_destroy);
@@ -239,7 +240,8 @@
return NULL;
}
- if (!(ser->serializer = ast_sip_create_serializer())) {
+ snprintf(registered_name, sizeof(registered_name), "aor/%s", aor_name);
+ if (!(ser->serializer = ast_sip_create_serializer(registered_name))) {
ao2_ref(ser, -1);
return NULL;
}
diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c
index fc87248..30c8c64 100644
--- a/res/res_pjsip_session.c
+++ b/res/res_pjsip_session.c
@@ -1266,6 +1266,7 @@
RAII_VAR(struct ast_sip_session *, session, NULL, ao2_cleanup);
struct ast_sip_session_supplement *iter;
int dsp_features = 0;
+ char session_name[AST_TASKPROCESSOR_MAX_NAME + 1];
session = ao2_alloc(sizeof(*session), session_destructor);
if (!session) {
@@ -1286,7 +1287,9 @@
/* fill session->media with available types */
ao2_callback(sdp_handlers, OBJ_NODATA, add_session_media, session);
- session->serializer = ast_sip_create_serializer();
+ snprintf(session_name, sizeof(session_name), "session/%s",
+ ast_sorcery_object_get_id(endpoint));
+ session->serializer = ast_sip_create_serializer(session_name);
if (!session->serializer) {
return NULL;
}
diff --git a/res/res_pjsip_transport_websocket.c b/res/res_pjsip_transport_websocket.c
index 3157a94..26d995e 100644
--- a/res/res_pjsip_transport_websocket.c
+++ b/res/res_pjsip_transport_websocket.c
@@ -323,7 +323,7 @@
return;
}
- if (!(serializer = ast_sip_create_serializer())) {
+ if (!(serializer = ast_sip_create_serializer("websocket"))) {
ast_websocket_unref(session);
return;
}
--
To view, visit https://gerrit.asterisk.org/1958
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iff9df8da3ddae1132cb2ef65f64df0c465c5e084
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
More information about the asterisk-code-review
mailing list