[asterisk-commits] kmoore: branch kmoore/stasis-device_state r383310 - /team/kmoore/stasis-devic...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Mar 18 08:31:04 CDT 2013


Author: kmoore
Date: Mon Mar 18 08:30:59 2013
New Revision: 383310

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=383310
Log:
Take advantage of topic pools

Modified:
    team/kmoore/stasis-device_state/main/devicestate.c

Modified: team/kmoore/stasis-device_state/main/devicestate.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-device_state/main/devicestate.c?view=diff&rev=383310&r1=383309&r2=383310
==============================================================================
--- team/kmoore/stasis-device_state/main/devicestate.c (original)
+++ team/kmoore/stasis-device_state/main/devicestate.c Mon Mar 18 08:30:59 2013
@@ -198,29 +198,7 @@
 static struct stasis_topic *device_state_topic_all;
 static struct stasis_caching_topic *device_state_topic_cached;
 static struct stasis_message_type *device_state_message_type;
-static struct ao2_container *device_state_topics;
-
-/* container for dynamically generated device-specific topics */
-struct device_state_topic {
-	char *device;
-	struct stasis_subscription *forward;
-	struct stasis_topic *topic;
-};
-
-static void device_state_topic_dtor(void *obj)
-{
-	struct device_state_topic *topic = obj;
-	ast_free(topic->device);
-	topic->device = NULL;
-	topic->forward = stasis_unsubscribe(topic->forward);
-	ao2_cleanup(topic->topic);
-	topic->topic = NULL;
-}
-
-static struct device_state_topic *device_state_topic_alloc(void)
-{
-	return ao2_alloc(sizeof(struct device_state_topic), device_state_topic_dtor);
-}
+static struct stasis_topic_pool *device_state_topic_pool;
 
 /* Forward declarations */
 static int getproviderstate(const char *provider, const char *address);
@@ -743,38 +721,7 @@
 
 struct stasis_topic *stasis_device_state_topic(const char *device)
 {
-	RAII_VAR(struct device_state_topic *, device_state_topic, NULL, ao2_cleanup);
-	SCOPED_AO2LOCK(topic_container_lock, device_state_topics);
-	device_state_topic = ao2_find(device_state_topics, device, OBJ_KEY | OBJ_NOLOCK);
-
-	if (device_state_topic) {
-		return device_state_topic->topic;
-	}
-
-	device_state_topic = device_state_topic_alloc();
-
-	if (!device_state_topic) {
-		return NULL;
-	}
-
-	device_state_topic->topic = stasis_topic_create(device);
-	if (!device_state_topic->topic) {
-		return NULL;
-	}
-
-	device_state_topic->forward = stasis_forward_all(device_state_topic->topic, stasis_device_state_topic_all());
-	if (!device_state_topic->forward) {
-		return NULL;
-	}
-
-	device_state_topic->device = ast_strdup(device);
-	if (!device_state_topic->device) {
-		return NULL;
-	}
-
-	ao2_link_flags(device_state_topics, device_state_topic, OBJ_NOLOCK);
-
-	return device_state_topic->topic;
+	return stasis_topic_pool_get_topic(device_state_topic_pool, device);
 }
 
 int stasis_publish_device_state_full(
@@ -820,19 +767,6 @@
 	return device_state->cache_id;
 }
 
-static int device_state_topic_hash(const void *obj, const int flags)
-{
-	const char *device = (flags & OBJ_KEY) ? obj : ((struct device_state_topic*) obj)->device;
-	return ast_str_case_hash(device);
-}
-
-static int device_state_topic_cmp(void *obj, void *arg, int flags)
-{
-	struct device_state_topic *opt1 = obj, *opt2 = arg;
-	const char *device = (flags & OBJ_KEY) ? arg : opt2->device;
-	return strcasecmp(opt1->device, device) ? 0 : CMP_MATCH | CMP_STOP;
-}
-
 static void devstate_exit(void)
 {
 	ao2_cleanup(device_state_topic_all);
@@ -840,8 +774,8 @@
 	device_state_topic_cached = stasis_caching_unsubscribe(device_state_topic_cached);
 	ao2_cleanup(device_state_message_type);
 	device_state_message_type = NULL;
-	ao2_cleanup(device_state_topics);
-	device_state_topics = NULL;
+	ao2_cleanup(device_state_topic_pool);
+	device_state_topic_pool = NULL;
 }
 
 int devstate_init(void)
@@ -858,8 +792,8 @@
 	if (!device_state_message_type) {
 		return -1;
 	}
-	device_state_topics = ao2_container_alloc(DEVSTATE_TOPIC_BUCKETS, device_state_topic_hash, device_state_topic_cmp);
-	if (!device_state_topics) {
+	device_state_topic_pool = stasis_topic_pool_create(stasis_device_state_topic_all());
+	if (!device_state_topic_pool) {
 		return -1;
 	}
 




More information about the asterisk-commits mailing list