[svn-commits] rmudgett: branch rmudgett/stasis_cache r409702 - in /team/rmudgett/stasis_cac...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Mar 4 20:32:04 CST 2014


Author: rmudgett
Date: Tue Mar  4 20:32:00 2014
New Revision: 409702

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=409702
Log:
devicestate.c: Store the eid and device name after the struct.

Modified:
    team/rmudgett/stasis_cache/include/asterisk/devicestate.h
    team/rmudgett/stasis_cache/main/devicestate.c

Modified: team/rmudgett/stasis_cache/include/asterisk/devicestate.h
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/stasis_cache/include/asterisk/devicestate.h?view=diff&rev=409702&r1=409701&r2=409702
==============================================================================
--- team/rmudgett/stasis_cache/include/asterisk/devicestate.h (original)
+++ team/rmudgett/stasis_cache/include/asterisk/devicestate.h Tue Mar  4 20:32:00 2014
@@ -275,10 +275,20 @@
  */
 /* BUGBUG the changes to this struct should only be done on trunk.  Back them out for v12 version. */
 struct ast_device_state_message {
-	const char *device;					/*!< The name of the device */
-	struct ast_eid *eid;				/*!< The EID of the server where this message originated, NULL EID means aggregate state */
-	enum ast_device_state state;		/*!< The state of the device */
-	enum ast_devstate_cache cachable;	/*!< Flag designating the cachability of this device state */
+	/*! The name of the device */
+	const char *device;
+	/*!
+	 * \brief The EID of the server where this message originated.
+	 *
+	 * \note A NULL EID means aggregate state.
+	 */
+	const struct ast_eid *eid;
+	/*! The state of the device */
+	enum ast_device_state state;
+	/*! Flag designating the cachability of this device state */
+	enum ast_devstate_cache cachable;
+	/*! The device and eid data is stuffed here when the struct is allocated. */
+	struct ast_eid stuff[0];
 };
 
 /*!

Modified: team/rmudgett/stasis_cache/main/devicestate.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/stasis_cache/main/devicestate.c?view=diff&rev=409702&r1=409701&r2=409702
==============================================================================
--- team/rmudgett/stasis_cache/main/devicestate.c (original)
+++ team/rmudgett/stasis_cache/main/devicestate.c Tue Mar  4 20:32:00 2014
@@ -526,40 +526,36 @@
 	return NULL;
 }
 
-static void device_state_dtor(void *obj)
-{
-	struct ast_device_state_message *device_state = obj;
-
-	ast_free((char *) device_state->device);
-	ast_free(device_state->eid);
-}
-
 static struct ast_device_state_message *device_state_alloc(const char *device, enum ast_device_state state, enum ast_devstate_cache cachable, const struct ast_eid *eid)
 {
 	struct ast_device_state_message *new_device_state;
+	char *pos;
+	size_t stuff_len;
 
 	ast_assert(!ast_strlen_zero(device));
 
-	new_device_state = ao2_alloc_options(sizeof(*new_device_state), device_state_dtor,
+	stuff_len = strlen(device) + 1;
+	if (eid) {
+		stuff_len += sizeof(*eid);
+	}
+	new_device_state = ao2_alloc_options(sizeof(*new_device_state) + stuff_len, NULL,
 		AO2_ALLOC_OPT_LOCK_NOLOCK);
 	if (!new_device_state) {
 		return NULL;
 	}
 
-	new_device_state->device = ast_strdup(device);
-	if (!new_device_state->device) {
-		ao2_cleanup(new_device_state);
-		return NULL;
-	}
 	if (eid) {
 		/* non-aggregate device state. */
-		new_device_state->eid = ast_malloc(sizeof(*eid));
-		if (!new_device_state->eid) {
-			ao2_cleanup(new_device_state);
-			return NULL;
-		}
-		*new_device_state->eid = *eid;
-	}
+		new_device_state->stuff[0] = *eid;
+		new_device_state->eid = &new_device_state->stuff[0];
+		pos = (char *) &new_device_state->stuff[1];
+	} else {
+		pos = (char *) &new_device_state->stuff[0];
+	}
+
+	strcpy(pos, device);/* Safe */
+	new_device_state->device = pos;
+
 	new_device_state->state = state;
 	new_device_state->cachable = cachable;
 




More information about the svn-commits mailing list