[svn-commits] russell: branch russell/iax_refcount r79734 - in /team/russell/iax_refcount: ...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Aug 16 13:39:48 CDT 2007


Author: russell
Date: Thu Aug 16 13:39:48 2007
New Revision: 79734

URL: http://svn.digium.com/view/asterisk?view=rev&rev=79734
Log:
Allow ao2_find to take advantage of the fact that the peers are stored in a
hash table.  To do this, I made a slight change to astobj2 described below.

Previously, OBJ_POINTER implied both that the argument provided to ao2_callback
was of the same type of the objects in the container, but *also* implied that
this was the object that was being looked for in the container.  I made a slight
change to ao2_callback such that only the first part was true.  This made it so
I could pass in a temporary object that could be sent to the hash function for
getting the right hash for where to start looking, but let it still use my own
custom object compare function.

I also updated the documentation for the OBJ flags to reflect my changes as well
as an incorrect description for OBJ_NODATA.  OBJ_NODATA means *don't* return the
object (and consequently, increase its reference count) on a match.

Modified:
    team/russell/iax_refcount/channels/chan_iax2.c
    team/russell/iax_refcount/include/asterisk/astobj2.h
    team/russell/iax_refcount/main/astobj2.c

Modified: team/russell/iax_refcount/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/russell/iax_refcount/channels/chan_iax2.c?view=diff&rev=79734&r1=79733&r2=79734
==============================================================================
--- team/russell/iax_refcount/channels/chan_iax2.c (original)
+++ team/russell/iax_refcount/channels/chan_iax2.c Thu Aug 16 13:39:48 2007
@@ -1046,6 +1046,9 @@
 		return csub;
 }
 
+/*!
+ * \note The only member of the peer passed here guaranteed to be set is the name field
+ */
 static int peer_hash_cb(const void *obj, const int flags)
 {
 	const struct iax2_peer *peer = obj;
@@ -1053,12 +1056,14 @@
 	return ast_str_hash(peer->name);
 }
 
+/*!
+ * \note The only member of the peer passed here guaranteed to be set is the name field
+ */
 static int peer_cmp_cb(void *obj, void *arg, int flags)
 {
-	struct iax2_peer *peer = obj;
-	const char *name = arg;
-
-	return !strcasecmp(peer->name, name) ? CMP_MATCH : 0;
+	struct iax2_peer *peer = obj, *peer2 = arg;
+
+	return !strcasecmp(peer->name, peer2->name) ? CMP_MATCH : 0;
 }
 
 /*!
@@ -1068,8 +1073,11 @@
 static struct iax2_peer *find_peer(const char *name, int realtime) 
 {
 	struct iax2_peer *peer = NULL;
-
-	peer = ao2_find(peers, (void *) name, 0);
+	struct iax2_peer tmp_peer = {
+		.name = name,
+	};
+
+	peer = ao2_find(peers, &tmp_peer, OBJ_POINTER);
 
 	/* Now go for realtime if applicable */
 	if(!peer && realtime)
@@ -5061,7 +5069,7 @@
 	char md5secret[256] = "";
 	char rsasecret[256] = "";
 	char secret[256] = "";
-	struct iax2_peer *p;
+	struct iax2_peer *p = NULL;
 	struct ast_key *key;
 	char *keyn;
 	int x;
@@ -5185,7 +5193,8 @@
 	res = 0;
 
 return_unref:
-	peer_unref(p);
+	if (p)
+		peer_unref(p);
 
 	return res;
 }
@@ -5606,8 +5615,11 @@
 {
 	char *name = data;
 	struct iax2_peer *peer = NULL;
-
-	peer = ao2_find(peers, name, 0);
+	struct iax2_peer tmp_peer = {
+		.name = name,
+	};
+
+	peer = ao2_find(peers, &tmp_peer, OBJ_POINTER);
 	if (!peer)
 		return;
 
@@ -8693,9 +8705,12 @@
 	int maskfound=0;
 	int found=0;
 	int firstpass=1;
+	struct iax2_peer tmp_peer = {
+		.name = name,
+	};
 
 	if (!temponly) {
-		peer = ao2_find(peers, (void *) name, 0);
+		peer = ao2_find(peers, &tmp_peer, OBJ_POINTER);
 		if (peer && !ast_test_flag(peer, IAX_DELME))
 			firstpass = 0;
 	}

Modified: team/russell/iax_refcount/include/asterisk/astobj2.h
URL: http://svn.digium.com/view/asterisk/team/russell/iax_refcount/include/asterisk/astobj2.h?view=diff&rev=79734&r1=79733&r2=79734
==============================================================================
--- team/russell/iax_refcount/include/asterisk/astobj2.h (original)
+++ team/russell/iax_refcount/include/asterisk/astobj2.h Thu Aug 16 13:39:48 2007
@@ -262,10 +262,17 @@
  * according the following flags.
  */
 enum search_flags {
-	OBJ_UNLINK	= 0x01,	/* unlink the object found */
-	OBJ_NODATA	= 0x02,	/* on match, return the object. */
-	OBJ_MULTIPLE	= 0x08,	/* don't stop at the first match */
-	OBJ_POINTER	= 0x10	/* obj is an astobj object */
+	/*! unlink the object found */
+	OBJ_UNLINK	= (1 << 0),
+	/*! on match, don't return the object or increase its reference count. */
+	OBJ_NODATA	= (1 << 1),
+	/*! don't stop at the first match 
+	 *  \note This is not fully implemented. */
+	OBJ_MULTIPLE	= (1 << 2),
+	/*! obj is an object of the same type as the one being searched for.
+	 *  This implies that it can be passed to the object's hash function
+	 *  for optimized searching. */
+	OBJ_POINTER	= (1 << 3),
 };
 
 /*!

Modified: team/russell/iax_refcount/main/astobj2.c
URL: http://svn.digium.com/view/asterisk/team/russell/iax_refcount/main/astobj2.c?view=diff&rev=79734&r1=79733&r2=79734
==============================================================================
--- team/russell/iax_refcount/main/astobj2.c (original)
+++ team/russell/iax_refcount/main/astobj2.c Thu Aug 16 13:39:48 2007
@@ -399,9 +399,16 @@
 	}
 
 	/* override the match function if necessary */
+#if 0
+	/* Removing this slightly changes the meaning of OBJ_POINTER, but makes it
+	 * do what I want it to.  I'd like to hint to ao2_callback that the arg is
+	 * of the same object type, so it can be passed to the hash function.
+	 * However, I don't want to imply that this is the object being searched for. */
 	if (flags & OBJ_POINTER)
 		cb_fn = match_by_addr;
-	else if (cb_fn == NULL)	/* if NULL, match everything */
+	else
+#endif
+	if (cb_fn == NULL)	/* if NULL, match everything */
 		cb_fn = cb_true;
 	/*
 	 * XXX this can be optimized.




More information about the svn-commits mailing list