[asterisk-commits] kmoore: branch kmoore/channel-state-caching r380963 - in /team/kmoore/channel...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Feb 6 08:07:46 CST 2013


Author: kmoore
Date: Wed Feb  6 08:07:41 2013
New Revision: 380963

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=380963
Log:
Drop hung up channels from the channel state cache

Refactor the core of ast_event_get_cached to be able to unlink events
and add ast_event_drop_cached so that items can be dropped from event
caches. This is now used to drop hung up channels from the channel
state event cache to prevent unending memory growth.

Modified:
    team/kmoore/channel-state-caching/include/asterisk/event.h
    team/kmoore/channel-state-caching/main/event.c
    team/kmoore/channel-state-caching/main/manager.c

Modified: team/kmoore/channel-state-caching/include/asterisk/event.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/channel-state-caching/include/asterisk/event.h?view=diff&rev=380963&r1=380962&r2=380963
==============================================================================
--- team/kmoore/channel-state-caching/include/asterisk/event.h (original)
+++ team/kmoore/channel-state-caching/include/asterisk/event.h Wed Feb  6 08:07:41 2013
@@ -457,6 +457,37 @@
 struct ast_event *ast_event_get_cached(enum ast_event_type, ...);
 
 /*!
+ * \brief Drop an event from the cache
+ *
+ * \param ast_event_type The type of event to drop from the cache
+ *
+ * The rest of the arguments to this function specify information elements to
+ * match for dropping events from the cache.  They are specified in the form:
+ * \code
+ *    <enum ast_event_ie_type>, [enum ast_event_ie_pltype, [payload] ]
+ * \endcode
+ * and must end with AST_EVENT_IE_END.
+ *
+ * If the ie_type specified is *not* AST_EVENT_IE_END, then it must be followed
+ * by a valid IE payload type.  If the payload type specified is
+ * AST_EVENT_IE_PLTYPE_EXISTS, then the 3rd argument should not be provided.
+ * Otherwise, a payload must also be specified.
+ *
+ * Example Usage:
+ *
+ * \code
+ * ast_event_drop_cached(AST_EVENT_MWI,
+ *     AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox,
+ *     AST_EVENT_IE_END);
+ * \endcode
+ *
+ * This example will check for an MWI event in the cache that matches the
+ * specified mailbox.  This would be the way to find out the last known state
+ * of a mailbox without having to poll the mailbox directly.
+ */
+void ast_event_drop_cached(enum ast_event_type, ...);
+
+/*!
  * \brief Append an information element that has a string payload
  *
  * \param event the event that the IE will be appended to

Modified: team/kmoore/channel-state-caching/main/event.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/channel-state-caching/main/event.c?view=diff&rev=380963&r1=380962&r2=380963
==============================================================================
--- team/kmoore/channel-state-caching/main/event.c (original)
+++ team/kmoore/channel-state-caching/main/event.c Wed Feb  6 08:07:41 2013
@@ -160,6 +160,7 @@
 ast_event_ie_payload_cmp *raw_local_cmp_from_raw(const void *payload);
 ast_event_ie_payload_destroy *raw_local_destroy_from_raw(const void *payload);
 uint16_t raw_local_len_from_raw_len(uint16_t len);
+struct ast_event *event_get_cached(enum ast_event_type type, int unlink, va_list ap);
 
 /*!
  * \brief Event types that are kept in the cache.
@@ -1651,9 +1652,8 @@
 	return dup_event;
 }
 
-struct ast_event *ast_event_get_cached(enum ast_event_type type, ...)
-{
-	va_list ap;
+struct ast_event *event_get_cached(enum ast_event_type type, int unlink, va_list ap)
+{
 	enum ast_event_ie_type ie_type;
 	struct ast_event *dup_event = NULL;
 	struct ast_event_ref *cached_event_ref;
@@ -1677,7 +1677,6 @@
 		return NULL;
 	}
 
-	va_start(ap, type);
 	for (ie_type = va_arg(ap, enum ast_event_ie_type);
 		ie_type != AST_EVENT_IE_END;
 		ie_type = va_arg(ap, enum ast_event_ie_type))
@@ -1728,11 +1727,10 @@
 			break;
 		}
 	}
-	va_end(ap);
 
 	tmp_event_ref.event = cache_arg_event;
 
-	cached_event_ref = ao2_find(container, &tmp_event_ref, OBJ_POINTER);
+	cached_event_ref = ao2_find(container, &tmp_event_ref, OBJ_POINTER | (unlink ? OBJ_UNLINK | OBJ_NODATA : 0));
 
 	ast_event_destroy(cache_arg_event);
 	cache_arg_event = NULL;
@@ -1744,6 +1742,24 @@
 	}
 
 	return dup_event;
+}
+
+struct ast_event *ast_event_get_cached(enum ast_event_type type, ...)
+{
+	va_list ap;
+	struct ast_event *ret;
+	va_start(ap, type);
+	ret = event_get_cached(type, 0, ap);
+	va_end(ap);
+	return ret;
+}
+
+void ast_event_drop_cached(enum ast_event_type type, ...)
+{
+	va_list ap;
+	va_start(ap, type);
+	event_get_cached(type, 1, ap);
+	va_end(ap);
 }
 
 static struct ast_event_ref *alloc_event_ref(void)

Modified: team/kmoore/channel-state-caching/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/channel-state-caching/main/manager.c?view=diff&rev=380963&r1=380962&r2=380963
==============================================================================
--- team/kmoore/channel-state-caching/main/manager.c (original)
+++ team/kmoore/channel-state-caching/main/manager.c Wed Feb  6 08:07:41 2013
@@ -7521,6 +7521,12 @@
 	/* Generate a Hangup event when the old state is known and the channel has been hung up. */
 	if (old_snapshot && is_hungup) {
 		manager_hangup(new_snapshot);
+		/* drop the cache for this channel */
+		ast_event_drop_cached(AST_EVENT_CHANNEL_STATE,
+			AST_EVENT_IE_CEL_CHANNAME,        AST_EVENT_IE_PLTYPE_STR, new_snapshot->name,
+			AST_EVENT_IE_CHANNEL_STATE,       AST_EVENT_IE_PLTYPE_RAW_LOCAL, new_snapshot, sizeof(*new_snapshot),
+				ast_channel_snapshot_copy, ast_channel_snapshot_cmp, ast_channel_snapshot_destroy,
+			AST_EVENT_IE_END);
 	}
 
 	/* Destroy the snapshot removed from the cache.




More information about the asterisk-commits mailing list