[asterisk-commits] kmoore: branch kmoore/event_system_strip r395318 - /team/kmoore/event_system_...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jul 24 15:33:39 CDT 2013


Author: kmoore
Date: Wed Jul 24 15:33:38 2013
New Revision: 395318

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=395318
Log:
Remove the remainder of the cache including ast_event_ref

Modified:
    team/kmoore/event_system_strip/main/event.c

Modified: team/kmoore/event_system_strip/main/event.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/event_system_strip/main/event.c?view=diff&rev=395318&r1=395317&r2=395318
==============================================================================
--- team/kmoore/event_system_strip/main/event.c (original)
+++ team/kmoore/event_system_strip/main/event.c Wed Jul 24 15:33:38 2013
@@ -92,20 +92,6 @@
 } __attribute__((packed));
 
 
-/*!
- * \brief A holder for an event
- *
- * \details This struct used to have more of a purpose than it does now.
- * It is used to hold events in the event cache.  It can be completely removed
- * if one of these two things is done:
- *  - ast_event gets changed such that it never has to be realloc()d
- *  - astobj2 is updated so that you can realloc() an astobj2 object
- */
-struct ast_event_ref {
-	struct ast_event *event;
-	unsigned int cache;
-};
-
 struct ast_event_ie_val {
 	AST_LIST_ENTRY(ast_event_ie_val) entry;
 	enum ast_event_ie_type ie_type;
@@ -137,50 +123,6 @@
 /*! \brief Event subscriptions
  * The event subscribers are indexed by which event they are subscribed to */
 static AST_RWDLLIST_HEAD(ast_event_sub_list, ast_event_sub) ast_event_subs[AST_EVENT_TOTAL];
-
-static int ast_event_cmp(void *obj, void *arg, int flags);
-
-#ifdef LOW_MEMORY
-#define NUM_CACHE_BUCKETS 17
-#else
-#define NUM_CACHE_BUCKETS 563
-#endif
-
-#define MAX_CACHE_ARGS 8
-
-struct cache_events {
-	/*!
-	 * \brief Container of cached events
-	 *
-	 * \details This gets allocated in ast_event_init() when Asterisk starts
-	 * for the event types declared as using the cache.
-	 */
-	struct ao2_container *container;
-	/*! \brief Event type specific hash function */
-	ao2_hash_fn *hash_fn;
-	/*!
-	 * \brief Information Elements used for caching
-	 *
-	 * \details This array is the set of information elements that will be unique
-	 * among all events in the cache for this event type.  When a new event gets
-	 * cached, a previous event with the same values for these information elements
-	 * will be replaced.
-	 */
-	enum ast_event_ie_type cache_args[MAX_CACHE_ARGS];
-};
-
-/*!
- * \brief Event types that are kept in the cache.
- */
-static struct cache_events ast_event_cache[AST_EVENT_TOTAL] = {
-};
-
-/*!
- * \brief Names of cached event types, for CLI tab completion
- *
- * \note These names must match what is in the event_names array.
- */
-static const char * const cached_event_types[] = { "MWI", "DeviceState", "DeviceStateChange", NULL };
 
 /*!
  * \brief Event Names
@@ -1259,94 +1201,15 @@
 	ast_free(event);
 }
 
-static void ast_event_ref_destroy(void *obj)
-{
-	struct ast_event_ref *event_ref = obj;
-
-	ast_event_destroy(event_ref->event);
-}
-
-static struct ast_event *ast_event_dup(const struct ast_event *event)
-{
-	struct ast_event *dup_event;
-	uint16_t event_len;
-
-	event_len = ast_event_get_size(event);
-
-	if (!(dup_event = ast_calloc(1, event_len))) {
-		return NULL;
-	}
-
-	memcpy(dup_event, event, event_len);
-
-	return dup_event;
-}
-
-static struct ast_event_ref *alloc_event_ref(void)
-{
-	return ao2_alloc(sizeof(struct ast_event_ref), ast_event_ref_destroy);
-}
-
-/*!
- * \internal
- * \brief Update the given event cache with the new event.
- * \since 1.8
- *
- * \param cache Event cache container to update.
- * \param event New event to put in the cache.
- *
- * \return Nothing
- */
-static void event_update_cache(struct ao2_container *cache, struct ast_event *event)
-{
-	struct ast_event_ref tmp_event_ref = {
-		.event = event,
-	};
-	struct ast_event *dup_event;
-	struct ast_event_ref *event_ref;
-
-	/* Hold the cache container lock while it is updated. */
-	ao2_lock(cache);
-
-	/* Remove matches from the cache. */
-	ao2_callback(cache, OBJ_POINTER | OBJ_UNLINK | OBJ_MULTIPLE | OBJ_NODATA,
-		ast_event_cmp, &tmp_event_ref);
-
-	/* Save a copy of the event in the cache. */
-	dup_event = ast_event_dup(event);
-	if (dup_event) {
-		event_ref = alloc_event_ref();
-		if (event_ref) {
-			event_ref->event = dup_event;
-			ao2_link(cache, event_ref);
-			ao2_ref(event_ref, -1);
-		} else {
-			ast_event_destroy(dup_event);
-		}
-	}
-
-	ao2_unlock(cache);
-}
-
 static int handle_event(void *data)
 {
-	struct ast_event_ref *event_ref = data;
+	struct ast_event *event = data;
 	struct ast_event_sub *sub;
 	const enum ast_event_type event_types[] = {
-		ntohs(event_ref->event->type),
+		ntohs(event->type),
 		AST_EVENT_ALL
 	};
 	int i;
-
-	if (event_ref->cache) {
-		struct ao2_container *container;
-		container = ast_event_cache[ast_event_get_type(event_ref->event)].container;
-		if (!container) {
-			ast_log(LOG_WARNING, "cache requested for non-cached event type\n");
-		} else {
-			event_update_cache(container, event_ref->event);
-		}
-	}
 
 	for (i = 0; i < ARRAY_LEN(event_types); i++) {
 		AST_RWDLLIST_RDLOCK(&ast_event_subs[event_types[i]]);
@@ -1354,7 +1217,7 @@
 			struct ast_event_ie_val *ie_val;
 
 			AST_LIST_TRAVERSE(&sub->ie_vals, ie_val, entry) {
-				if (!match_ie_val(event_ref->event, ie_val, NULL)) {
+				if (!match_ie_val(event, ie_val, NULL)) {
 					/* The current subscription ie did not match an event ie. */
 					break;
 				}
@@ -1363,19 +1226,18 @@
 				/* The event did not match this subscription. */
 				continue;
 			}
-			sub->cb(event_ref->event, sub->userdata);
+			sub->cb(event, sub->userdata);
 		}
 		AST_RWDLLIST_UNLOCK(&ast_event_subs[event_types[i]]);
 	}
 
-	ao2_ref(event_ref, -1);
+	ast_event_destroy(event);
 
 	return 0;
 }
 
 int ast_event_queue(struct ast_event *event)
 {
-	struct ast_event_ref *event_ref;
 	uint16_t host_event_type;
 	int res;
 
@@ -1395,83 +1257,10 @@
 		return 0;
 	}
 
-	if (!(event_ref = alloc_event_ref())) {
-		return -1;
-	}
-
-	event_ref->event = event;
-	event_ref->cache = 0;
-
-	res = ast_taskprocessor_push(event_dispatcher, handle_event, event_ref);
+	res = ast_taskprocessor_push(event_dispatcher, handle_event, event);
 	if (res) {
-		event_ref->event = NULL;
-		ao2_ref(event_ref, -1);
-	}
-	return res;
-}
-
-static int ast_event_hash(const void *obj, const int flags)
-{
-	const struct ast_event_ref *event_ref;
-	const struct ast_event *event;
-	ao2_hash_fn *hash_fn;
-
-	event_ref = obj;
-	event = event_ref->event;
-
-	if (!(hash_fn = ast_event_cache[ast_event_get_type(event)].hash_fn)) {
-		return 0;
-	}
-
-	return hash_fn(event, flags);
-}
-
-/*!
- * \internal
- * \brief Compare two events
- *
- * \param[in] obj the first event, as an ast_event_ref
- * \param[in] arg the second event, as an ast_event_ref
- * \param[in] flags unused
- *
- * \pre Both events must be the same type.
- * \pre The event type must be declared as a cached event type in ast_event_cache
- *
- * \details This function takes two events, and determines if they are considered
- * equivalent.  The values of information elements specified in the cache arguments
- * for the event type are used to determine if the events are equivalent.
- *
- * \retval 0 No match
- * \retval CMP_MATCH The events are considered equivalent based on the cache arguments
- */
-static int ast_event_cmp(void *obj, void *arg, int flags)
-{
-	struct ast_event_ref *event_ref, *event_ref2;
-	struct ast_event *event, *event2;
-	int res = CMP_MATCH;
-	int i;
-	enum ast_event_ie_type *cache_args;
-
-	event_ref = obj;
-	event = event_ref->event;
-
-	event_ref2 = arg;
-	event2 = event_ref2->event;
-
-	cache_args = ast_event_cache[ast_event_get_type(event)].cache_args;
-
-	for (i = 0; i < ARRAY_LEN(ast_event_cache[0].cache_args) && cache_args[i]; i++) {
-		struct ast_event_ie_val ie_val = {
-			.ie_pltype = ast_event_get_ie_pltype(cache_args[i]),
-			.ie_type = cache_args[i],
-		};
-
-		if (!match_ie_val(event, &ie_val, event2)) {
-			res = 0;
-			break;
-		}
-	}
-
+		ast_event_destroy(event);
+	}
 	return res;
 }
 
@@ -1496,15 +1285,6 @@
 		AST_RWDLLIST_UNLOCK(&ast_event_subs[i]);
 		AST_RWDLLIST_HEAD_DESTROY(&ast_event_subs[i]);
 	}
-
-	for (i = 0; i < AST_EVENT_TOTAL; i++) {
-		if (!ast_event_cache[i].hash_fn) {
-			continue;
-		}
-		if (ast_event_cache[i].container) {
-			ao2_ref(ast_event_cache[i].container, -1);
-		}
-	}
 }
 
 int ast_event_init(void)
@@ -1513,18 +1293,6 @@
 
 	for (i = 0; i < AST_EVENT_TOTAL; i++) {
 		AST_RWDLLIST_HEAD_INIT(&ast_event_subs[i]);
-	}
-
-	for (i = 0; i < AST_EVENT_TOTAL; i++) {
-		if (!ast_event_cache[i].hash_fn) {
-			/* This event type is not cached. */
-			continue;
-		}
-
-		if (!(ast_event_cache[i].container = ao2_container_alloc(NUM_CACHE_BUCKETS,
-				ast_event_hash, ast_event_cmp))) {
-			goto event_init_cleanup;
-		}
 	}
 
 	if (!(event_dispatcher = ast_taskprocessor_get("core_event_dispatcher", 0))) {




More information about the asterisk-commits mailing list