[asterisk-commits] rizzo: branch rizzo/astobj2 r47998 -
/team/rizzo/astobj2/main/astobj2.c
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Fri Nov 24 11:38:05 MST 2006
Author: rizzo
Date: Fri Nov 24 12:38:05 2006
New Revision: 47998
URL: http://svn.digium.com/view/asterisk?view=rev&rev=47998
Log:
reminder to improve link/unlink of objects to a container.
Modified:
team/rizzo/astobj2/main/astobj2.c
Modified: team/rizzo/astobj2/main/astobj2.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/astobj2/main/astobj2.c?view=diff&rev=47998&r1=47997&r2=47998
==============================================================================
--- team/rizzo/astobj2/main/astobj2.c (original)
+++ team/rizzo/astobj2/main/astobj2.c Fri Nov 24 12:38:05 2006
@@ -35,6 +35,8 @@
* The refcount is used to decide when it is time to
* invoke the destructor.
* The magic number is used for consistency check.
+ * XXX the lock is not always needed, and its initialization may be
+ * expensive. Consider making it external.
*/
struct __priv_data {
ast_mutex_t lock;
@@ -236,6 +238,13 @@
* which is the next one in the list with a higher number.
* Since all objects have a version >0, we can use 0 as a marker for
* 'we need the first object in the bucket'.
+ *
+ * XXX TODO: Linking and unlink objects is typically expensive, as it
+ * involves a malloc() of a small object which is very inefficient.
+ * To optimize this, we allocate larger arrays of bucket_list's
+ * when we run out of them, and then manage our own freelist.
+ * This will be more efficient as we can do the freelist management while
+ * we hold the lock (that we need anyways).
*/
struct __ao2_container {
ao2_hash_fn hash_fn;
@@ -305,6 +314,7 @@
*/
void *ao2_link(ao2_container *c, void *user_data)
{
+ static int prof_id = -1;
int i;
/* create a new list entry */
struct bucket_list *p;
@@ -313,6 +323,9 @@
return NULL;
if (INTERNAL_OBJ(c) == NULL)
return NULL;
+ if (prof_id == -1)
+ prof_id = ast_add_profile("ao2_link", 0);
+ ast_mark(prof_id, 1);
p = ast_calloc(1, sizeof(struct bucket_list));
if (p == NULL) /* alloc failure, die */
return NULL;
@@ -332,6 +345,7 @@
c->buckets[i].tail = p;
ast_atomic_fetchadd_int(&c->elements, 1);
ao2_unlock(c);
+ ast_mark(prof_id, 0);
return p;
}
More information about the asterisk-commits
mailing list