[asterisk-commits] rizzo: branch rizzo/astobj2 r47320 - in /team/rizzo/astobj2: include/asterisk...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed Nov 8 08:04:53 MST 2006


Author: rizzo
Date: Wed Nov  8 09:04:51 2006
New Revision: 47320

URL: http://svn.digium.com/view/asterisk?rev=47320&view=rev
Log:
rename our objects to ao2_*

Names should be short and easy to use for the programmer.


Modified:
    team/rizzo/astobj2/include/asterisk/astobj2.h
    team/rizzo/astobj2/main/astobj2.c

Modified: team/rizzo/astobj2/include/asterisk/astobj2.h
URL: http://svn.digium.com/view/asterisk/team/rizzo/astobj2/include/asterisk/astobj2.h?rev=47320&r1=47319&r2=47320&view=diff
==============================================================================
--- team/rizzo/astobj2/include/asterisk/astobj2.h (original)
+++ team/rizzo/astobj2/include/asterisk/astobj2.h Wed Nov  8 09:04:51 2006
@@ -37,7 +37,7 @@
 USAGE - OBJECTS
 
 An object is a block of memory that must be allocated with the
-function astobj2_alloc(), and for which the system keeps track (with
+function ao2_alloc(), and for which the system keeps track (with
 abit of help from the programmer) of the number of references around.
 When an object has no more references, it is destroyed, by first
 invoking whatever 'destructor' function the programmer specifies
@@ -50,7 +50,7 @@
  
     struct foo *o;
  
-    o = astobj2_alloc(sizeof(struct foo), my_destructor_fn);
+    o = ao2_alloc(sizeof(struct foo), my_destructor_fn);
 
 The object returned has a refcount = 1.
 Note that the memory for the object is allocated and zeroed.
@@ -58,18 +58,20 @@
 - We cannot call free(o) to dispose of the object; rather we
   tell the system that we do not need the reference anymore:
 
-    astobj2_ref(o, -1)
+    ao2_ref(o, -1)
 
   causing the destructor to be called (and then memory freed) when
-  the refcount goes to 0. This is also available as astobj2_unref(o),
-  and returns NULL
-
-- astobj2_ref(o, +1) can be used to modify the refcount on the
+  the refcount goes to 0. This is also available as ao2_unref(o),
+  and returns NULL as a convenience, so you can do things like
+	o = ao2_unref(o);
+  and clean the original pointer to prevent errors.
+
+- ao2_ref(o, +1) can be used to modify the refcount on the
   object in case we want to pass it around.
 	
 
-- other calls on the object are astobj2_lock(obj), astobj2_unlock(),
-  astobj2_trylock(), to manipulate the lock.
+- other calls on the object are ao2_lock(obj), ao2_unlock(),
+  ao2_trylock(), to manipulate the lock.
 
 
 USAGE - CONTAINERS
@@ -85,9 +87,9 @@
     <b>Sample Usage:</b>
     \code
 
-    struct container *c;
-
-    c = astobj2_container_alloc(MAX_BUCKETS, my_hash_fn, my_cmp_fn, my_dump_fn);
+    ao2_container *c;
+
+    c = ao2_container_alloc(MAX_BUCKETS, my_hash_fn, my_cmp_fn, my_dump_fn);
 
 where
 - MAX_BUCKETS is the number of buckets in the hash table,
@@ -99,17 +101,17 @@
 - my_dump_fn() is a helper function used only for debugging.
 
 A container knows little or nothing about the object itself,
-other than the fact that it has been created by astobj2_alloc()
+other than the fact that it has been created by ao2_alloc()
 All knowledge of the (user-defined) internals of the object
 is left to the (user-supplied) functions passed as arguments
-to astobj2_container_alloc().
+to ao2_container_alloc().
 
 If we want to insert the object in the container, we should
 initialize its fields -- especially, those used by my_hash_fn() --
 to compute the bucket to use.
 Once done, we can link an object to a container with
 
-    astobj2_link(c, o);
+    ao2_link(c, o);
 
 The function returns NULL in case of errors (and the object
 is not inserted in the container). Other values mean success
@@ -137,17 +139,10 @@
  */
 
 /*!
- * What an astobj2 object looks like: fixed-size private data
- * followed by variable-size user data.
- * However you are not supposed to know.
- */
-struct astobj2;
-
-/*!
  * Invoked just before freeing the memory for the object.
  * It is passed a pointer to user data.
  */
-typedef void (*astobj2_destructor_fn)(void *);
+typedef void (*ao2_destructor_fn)(void *);
 
 /*!
  * Allocate and initialize an object.
@@ -162,13 +157,12 @@
  * - storage is zeroed; XXX maybe we want a flag to enable/disable this.
  * - the refcount of the object just created is 1
  * - the returned pointer cannot be free()'d or realloc()'ed;
- *   rather, we just call astobj2_ref(o, -1);
- */
-void *astobj2_alloc(const size_t data_size, 
-		astobj2_destructor_fn destructor_fn);
-
-/*!
- * Reference/unreference an object.
+ *   rather, we just call ao2_ref(o, -1);
+ */
+void *ao2_alloc(const size_t data_size, ao2_destructor_fn destructor_fn);
+
+/*!
+ * Reference/unreference an object and return the old refcount.
  *
  * \param o A pointer to the object
  * \param delta Value to add to the reference counter.
@@ -182,7 +176,7 @@
  * can go away is when we release our reference, and it is
  * the last one in existence.
  */
-int astobj2_ref(void *o, int delta);
+int ao2_ref(void *o, int delta);
 
 /*!
  * Lock an object.
@@ -190,7 +184,7 @@
  * \param a A pointer to the object we want lock.
  * \return 0 on success, other values on error.
  */
-int astobj2_lock(void *a);
+int ao2_lock(void *a);
 
 /*!
  * Unlock an object.
@@ -198,7 +192,7 @@
  * \param a A pointer to the object we want unlock.
  * \return 0 on success, other values on error.
  */
-int astobj2_unlock(void *a);
+int ao2_unlock(void *a);
 
 /*!
  *
@@ -214,17 +208,17 @@
 
 Operations on container include:
 
-    c = astobj2_container_alloc(size, cmp_fn, hash_fn)
+    c = ao2_container_alloc(size, cmp_fn, hash_fn)
 	allocate a container with desired size and default compare
 	and hash function
 
-    astobj2_find(c, arg, flags)
+    ao2_find(c, arg, flags)
 	returns zero or more element matching a given criteria
 	(specified as arg). Flags indicate how many results we
 	want (only one or all matching entries), and whether we
 	should unlink the object from the container.
 
-    astobj2_callback(c, flags, fn, arg)
+    ao2_callback(c, flags, fn, arg)
 	apply fn(obj, arg) to all objects in the container.
 	Similar to find. fn() can tell when to stop, and
 	do anything with the object including unlinking it.
@@ -240,22 +234,21 @@
     iterate on a container
 	this is done with the following sequence
 
-	    struct container *c = ... // our container
-	    struct astobj2_iterator i;
+	    ao2_container *c = ... // our container
+	    ao2_iterator i;
 	    void *o;
 
-	    astobj2_iterator_init(c, &i);
+	    ao2_iterator_init(c, &i);
      
-	    while ( (o = astobj2_iterator_next(&i)) ) {
+	    while ( (o = ao2_iterator_next(&i)) ) {
 		... do something on o ...
+		ao2_ref(o, -1);
 	    }
-	    if (o) // early exit
-		astobj2_ref(o, -1);
 
 	The difference with the callback is that the control
 	on how to iterate is left to us.
 
-    astobj2_ref(c, -1)
+    ao2_ref(c, -1)
 	dropping a reference to a container destroys it, very simple!
  
 Containers are astobj2 object themselves, and this is why their
@@ -278,7 +271,7 @@
  * Type of a generic function to generate a hash value from an object.
  *
  */
-typedef int (*astobj2_hash_fn)(const void *obj, const int flags);
+typedef int (*ao2_hash_fn)(const void *obj, const int flags);
 
 /*!
  * valid callback results:
@@ -297,20 +290,20 @@
  * _cb_results as described above.
  *
  * \param o	object from container
- * \param arg	search parameters (directly from astobj2_find)
- * \param flags	passed directly from astobj2_find
+ * \param arg	search parameters (directly from ao2_find)
+ * \param flags	passed directly from ao2_find
  *	XXX explain.
  */
 
 /*!
  * Type of a generic callback function
  * \param obj  pointer to the (user-defined part) of an object.
- * \param arg callback argument from astobj2_callback()
- * \param flags flags from astobj2_callback()
+ * \param arg callback argument from ao2_callback()
+ * \param flags flags from ao2_callback()
  * The return values are the same as a compare function.
  * In fact, they are the same thing.
  */
-typedef int (*astobj2_callback_fn)(void *obj, void *arg, int flags);
+typedef int (*ao2_callback_fn)(void *obj, void *arg, int flags);
 
 /*!
  * Here start declarations of containers.
@@ -322,7 +315,7 @@
  * It is opaque, defined in astobj2.c, so we only need
  * a type declaration.
  */
-struct container;
+typedef struct __ao2_container ao2_container;
 
 /*!
  * Allocate and initialize a container 
@@ -338,13 +331,13 @@
  *
  * destructor is set implicitly.
  */
-struct container *astobj2_container_alloc(const uint n_buckets,
-		astobj2_hash_fn hash_fn, astobj2_callback_fn cmp_fn);
+ao2_container *ao2_container_alloc(const uint n_buckets,
+		ao2_hash_fn hash_fn, ao2_callback_fn cmp_fn);
 
 /*!
  * Returns the number of elements in a container.
  */
-int astobj2_container_count(struct container *c);
+int ao2_container_count(ao2_container *c);
 
 /*
  * Here we have functions to manage objects.
@@ -363,17 +356,17 @@
  *
  * \note Remember to set the key before calling this function.
  */
-void *astobj2_link(struct container *c, void *newobj);
-void *astobj2_unlink(struct container *c, void *newobj);
+void *ao2_link(ao2_container *c, void *newobj);
+void *ao2_unlink(ao2_container *c, void *newobj);
 
 /*! \struct Used as return value if the flag OBJ_MULTIPLE is set */
-struct astobj2_list {
-	struct astobj2_list *next;
+struct ao2_list {
+	struct ao2_list *next;
 	void *obj;	/* pointer to the user portion of the object */
 };
 
 /*!
- * astobj2_callback() and astob2_find() are the same thing with only one difference:
+ * ao2_callback() and astob2_find() are the same thing with only one difference:
  * the latter uses as a callback the function passed as my_cmp_f() at
  * the time of the creation of the container.
  * 
@@ -416,20 +409,20 @@
  * In case we return a list, the callee must take care to destroy 
  * that list when no longer used.
  *
- * \note When the returned object is no longer in use, astobj2_ref() should
+ * \note When the returned object is no longer in use, ao2_ref() should
  * be used to free the additional reference possibly created by this function.
  */
 /* XXX order of arguments to find */
-void *astobj2_find(struct container *c, void *arg, enum search_flags flags);
-void *astobj2_callback(struct container *c,
+void *ao2_find(ao2_container *c, void *arg, enum search_flags flags);
+void *ao2_callback(ao2_container *c,
 	enum search_flags flags,
-	astobj2_callback_fn cb_fn, void *arg);
+	ao2_callback_fn cb_fn, void *arg);
 
 /*!
  *
 
 When we need to walk through a container, we use
-astobj2_iterator to keep track of the current position.
+ao2_iterator to keep track of the current position.
 
 Because the navigation is typically done without locking
 the container, objects can be inserted or deleted or moved
@@ -439,29 +432,28 @@
 We do implement a few things to reduce the chance of the
 above happening.
 
-An iterator must be first initialized with astobj2_iterator_init(),
-then we can use o = astobj2_iterator_next() to move from one
+An iterator must be first initialized with ao2_iterator_init(),
+then we can use o = ao2_iterator_next() to move from one
 element to the next. Remember that the object returned by
-astobj2_iterator_next() has its refcount incremented,
+ao2_iterator_next() has its refcount incremented,
 and the refcount will be decremented by the next call to
-astobj2_iterator_next(). If we terminate the loop early,
+ao2_iterator_next(). If we terminate the loop early,
 we need to release the refcount explicitly when we are
 done with the object.
 Example:
 
     \code
 
-    struct container *c = ... // the container we want to iterate on
-    struct astobj2_iterator i;
+    ao2_container *c = ... // the container we want to iterate on
+    ao2_iterator i;
     struct my_obj *o;
 
-    astobj2_iterator_init(c, &i);
+    ao2_iterator_init(c, &i);
  
-    while ( (o = astobj2_iterator_next(&i)) ) {
+    while ( (o = ao2_iterator_next(&i)) ) {
 	... do something on o ...
+	ao2_ref(o, -1);
     }
-    if (o)
-	astobj2_ref(o, -1);
 
     \endcode
 
@@ -474,17 +466,19 @@
  * without too much trouble.
  * It contains a pointer to the container, the bucket where the current
  * object is, and the version number of the current object. How this is
- * used, you will find in the implementation of astobj2_iterator_next()
+ * used, you will find in the implementation of ao2_iterator_next()
  * A freshly-initialized iterator has bucket=0, version = 0.
  */
-struct astobj2_iterator {
-        struct container *c;    /* the container */
+
+struct __ao2_iterator {
+        ao2_container *c;    /* the container */
         int bucket;     /* current bucket */
 	uint version;	/* container version when the object was created */
 };              
-
-void astobj2_iterator_init(struct container *c, struct astobj2_iterator *i);
-
-void *astobj2_iterator_next(struct astobj2_iterator *a);
+typedef struct __ao2_iterator ao2_iterator;
+
+void ao2_iterator_init(ao2_container *c, ao2_iterator *i);
+
+void *ao2_iterator_next(ao2_iterator *a);
 
 #endif /* _ASTERISK_ASTOBJ2_H */

Modified: team/rizzo/astobj2/main/astobj2.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/astobj2/main/astobj2.c?rev=47320&r1=47319&r2=47320&view=diff
==============================================================================
--- team/rizzo/astobj2/main/astobj2.c (original)
+++ team/rizzo/astobj2/main/astobj2.c Wed Nov  8 09:04:51 2006
@@ -39,7 +39,7 @@
 struct __priv_data {
         ast_mutex_t     lock;
         int             ref_counter;
-        astobj2_destructor_fn destructor_fn;
+        ao2_destructor_fn destructor_fn;
 };
 
 /*!
@@ -51,7 +51,7 @@
         void *user_data[0];
 };
 
-volatile int astobj2_total_objects;
+volatile int ao2_total_objects;
 
 /*
  * From a pointer _p to a user-defined object,
@@ -65,12 +65,12 @@
  */
 #define EXTERNAL_OBJ(_p)	((_p) == NULL ? NULL : (_p)->user_data)
 
-int astobj2_lock(void *user_data)
+int ao2_lock(void *user_data)
 {
 	return ast_mutex_lock( &INTERNAL_OBJ(user_data)->priv_data.lock );
 }
 
-int astobj2_unlock(void *user_data)
+int ao2_unlock(void *user_data)
 {
 	return ast_mutex_unlock( &INTERNAL_OBJ(user_data)->priv_data.lock );
 }
@@ -78,7 +78,7 @@
 /*
  * The argument is a pointer to the user portion.
  */
-int astobj2_ref(void *user_data, const int delta)
+int ao2_ref(void *user_data, const int delta)
 {
 #if 0
  	ast_log(LOG_NOTICE, "Reference counter changed by %i\n", delta);
@@ -117,7 +117,7 @@
 		 */
 		bzero(obj, sizeof(struct astobj2 *) + sizeof(void *) );
 		free(obj);
-		ast_atomic_fetchadd_int(&astobj2_total_objects, -1);
+		ast_atomic_fetchadd_int(&ao2_total_objects, -1);
 	}
 
 	return ret;
@@ -127,7 +127,7 @@
  * We always alloc at least the size of a void *,
  * for debugging purposes.
  */
-void *astobj2_alloc(size_t data_size, astobj2_destructor_fn destructor_fn)
+void *ao2_alloc(size_t data_size, ao2_destructor_fn destructor_fn)
 {
 	/* allocation */
 	struct astobj2 *obj;
@@ -144,7 +144,7 @@
 	ast_mutex_init(&obj->priv_data.lock);
 	obj->priv_data.ref_counter = 1;
 	obj->priv_data.destructor_fn = destructor_fn;	/* can be NULL */
-	ast_atomic_fetchadd_int(&astobj2_total_objects, 1);
+	ast_atomic_fetchadd_int(&ao2_total_objects, 1);
 
 	/* return a pointer to the user data */
 	return EXTERNAL_OBJ(obj);
@@ -174,9 +174,9 @@
  * Since all objects have a version >0, we can use 0 as a marker for
  * 'we need the first object in the bucket'.
  */
-struct container {
-        astobj2_hash_fn hash_fn;
-        astobj2_callback_fn cmp_fn;
+struct __ao2_container {
+        ao2_hash_fn hash_fn;
+        ao2_callback_fn cmp_fn;
         int     n_buckets;
         int     elements;       /* number of elements in the container */
 	uint version;		/* please read above */
@@ -195,15 +195,15 @@
 /*
  * A container is just an object, after all!
  */
-struct container *
-astobj2_container_alloc(const uint n_buckets, astobj2_hash_fn hash_fn,
-		astobj2_callback_fn cmp_fn)
+ao2_container *
+ao2_container_alloc(const uint n_buckets, ao2_hash_fn hash_fn,
+		ao2_callback_fn cmp_fn)
 {
 	/* XXX maybe consistency check on arguments ? */
 	/* compute the container size */
-	size_t container_size = sizeof(struct container) + n_buckets * sizeof(struct bucket);
-
-	struct container *c = astobj2_alloc(container_size, container_destruct);
+	size_t container_size = sizeof(ao2_container) + n_buckets * sizeof(struct bucket);
+
+	ao2_container *c = ao2_alloc(container_size, container_destruct);
 
 	if (c == NULL)
 		return NULL;
@@ -221,7 +221,7 @@
 /*!
  * return the number of elements in the container
  */
-int astobj2_container_count(struct container *c)
+int ao2_container_count(ao2_container *c)
 {
 	return c->elements;
 }
@@ -240,7 +240,7 @@
 /*!
  * link an object to a container
  */
-void *astobj2_link(struct container *c, void *user_data)
+void *ao2_link(ao2_container *c, void *user_data)
 {
 	int i;
 	/* create a new list entry */
@@ -251,7 +251,7 @@
 	/* apply the hash function */
 	i = c->hash_fn(user_data, OBJ_POINTER);
 
-	astobj2_lock(c);
+	ao2_lock(c);
 	i %= c->n_buckets;
 
 	p->next = NULL;
@@ -263,7 +263,7 @@
 		c->buckets[i].tail->next = p;
 	c->buckets[i].tail = p;
 	ast_atomic_fetchadd_int(&c->elements, 1);
-	astobj2_unlock(c);
+	ao2_unlock(c);
 	return p;
 }
 
@@ -279,15 +279,15 @@
 
 /*! 
  * \brief Unlink an object from the container
- * and destroy the associated * astobj2_bucket_list structure.
- */
-void *astobj2_unlink(struct container *c, void *user_data)
+ * and destroy the associated * ao2_bucket_list structure.
+ */
+void *ao2_unlink(ao2_container *c, void *user_data)
 {
 	// ast_verbose("unlinking %p from container\n", user_data);
-	astobj2_callback(c, OBJ_SINGLE | OBJ_UNLINK | OBJ_POINTER, match_by_addr, user_data);
+	ao2_callback(c, OBJ_SINGLE | OBJ_UNLINK | OBJ_POINTER, match_by_addr, user_data);
 	/* the container has changed its content, so we update the version */
 	ast_atomic_fetchadd_int(&c->version, 1);
-	astobj2_ref(user_data, -1);
+	ao2_ref(user_data, -1);
 	return NULL;
 }
 
@@ -302,9 +302,9 @@
  * \return Is a pointer to an object or to a list of object if OBJ_MULTIPLE is 
  * specified.
  */
-void *astobj2_callback(struct container *c,
+void *ao2_callback(ao2_container *c,
 	const enum search_flags flags,
-	astobj2_callback_fn cb_fn, void *arg)
+	ao2_callback_fn cb_fn, void *arg)
 {
 	int i, last;	/* search boundaries */
 	void *ret = NULL;
@@ -339,7 +339,7 @@
 		last = i+1;
 	}
 
-	astobj2_lock(c);	/* avoid modifications to the content */
+	ao2_lock(c);	/* avoid modifications to the content */
 
 	for(; i < last ; i++) {
 		/* scan the list with prev-cur pointers */
@@ -393,29 +393,29 @@
 			}
 		}
 	}
-	astobj2_unlock(c);
+	ao2_unlock(c);
 
 	/* increase the reference counter, unlock the container and return */
 	if ( ret != NULL )
-		astobj2_ref(ret, 1);
+		ao2_ref(ret, 1);
 	return ret;
 }
 
 /*!
  * the find function just invokes the default callback with some reasonable flags.
  */
-void *astobj2_find(struct container *c, void *arg, enum search_flags flags)
+void *ao2_find(ao2_container *c, void *arg, enum search_flags flags)
 {
 	if (flags == 0)
 		flags = OBJ_SINGLE | OBJ_DATA;	/* reasonable default */
-	ast_log(LOG_NOTICE, "astobj2_find\n");
-	return astobj2_callback(c, flags, c->cmp_fn, arg);
+	ast_log(LOG_NOTICE, "ao2_find\n");
+	return ao2_callback(c, flags, c->cmp_fn, arg);
 }
 
 /*!
  * initialize an iterator so we start from the first object
  */
-void astobj2_iterator_init(struct container *c, struct astobj2_iterator *a)
+void ao2_iterator_init(ao2_container *c, ao2_iterator *a)
 {
 	a->c = c;
 	a->bucket = 0;
@@ -425,12 +425,12 @@
 /*
  * move to the next element in the container.
  */
-void * astobj2_iterator_next(struct astobj2_iterator *a)
+void * ao2_iterator_next(ao2_iterator *a)
 {
 	int lim;
 	struct bucket_list *p = NULL;
 
-	astobj2_lock(a->c);
+	ao2_lock(a->c);
 	lim = a->c->n_buckets;
 
 	/* Browse the buckets array, moving to the next
@@ -445,13 +445,13 @@
 			if (p->version > a->version) { /* found */
 				a->version = p->version;
 				/* inc refcount of returned object */
-				astobj2_ref(EXTERNAL_OBJ(p->astobj), 1);
+				ao2_ref(EXTERNAL_OBJ(p->astobj), 1);
 				goto done;
 			}
 		}
 	}
 done:
-	astobj2_unlock(a->c);
+	ao2_unlock(a->c);
 	return p ? EXTERNAL_OBJ(p->astobj) : NULL;
 }
 
@@ -460,15 +460,15 @@
  */
 static int cd_cb(void *obj, void *arg, int flag)
 {
-	astobj2_ref(obj, -1);
+	ao2_ref(obj, -1);
 	return 0;
 }
 	
 static void container_destruct(void *_c)
 {
-	struct container *c = _c;
+	ao2_container *c = _c;
 	
-	astobj2_callback(c, OBJ_UNLINK, cd_cb, NULL);
+	ao2_callback(c, OBJ_UNLINK, cd_cb, NULL);
 }
 
 static int print_cb(void *obj, void *arg, int flag)
@@ -487,63 +487,63 @@
 int handle_astobj2_test(int fd, int argc, char *argv[])
 
 {
-	struct container *c1;
+	ao2_container *c1;
 	int i, lim;
 	char *obj;
 	static int prof_id = -1;
-	struct astobj2_iterator ai;
+	ao2_iterator ai;
 
 	if (prof_id == -1)
-		prof_id = ast_add_profile("astobj2_alloc", 0);
+		prof_id = ast_add_profile("ao2_alloc", 0);
 
 	ast_cli(fd, "argc %d argv %s %s %s\n", argc, argv[0], argv[1], argv[2]);
 	lim = atoi(argv[2]);
 	ast_cli(fd, "called astobj_test\n");
 
 	ast_verbose("at the beginning have %d objects\n",
-		astobj2_total_objects);
+		ao2_total_objects);
 	/*
 	 * allocate a container with no default callback, and no hash function.
 	 * No hash means everything goes in the same bucket.
 	 */
-	c1 = astobj2_container_alloc(100, NULL /* no callback */, NULL /* no hash */);
+	c1 = ao2_container_alloc(100, NULL /* no callback */, NULL /* no hash */);
 	ast_cli(fd, "container allocated as %p\n", c1);
 
 	/*
 	 * fill the container with objects.
-	 * astobj2_alloc() gives us a reference which we pass to the
+	 * ao2_alloc() gives us a reference which we pass to the
 	 * container when we do the insert.
 	 */
 	for (i = 0; i < lim; i++) {
 		ast_mark(prof_id, 1 /* start */);
-		obj = astobj2_alloc(80, NULL);
+		obj = ao2_alloc(80, NULL);
 		ast_mark(prof_id, 0 /* stop */);
 		ast_cli(fd, "object %d allocated as %p\n", i, obj);
 		sprintf(obj, "-- this is obj %d --", i);
-		astobj2_link(c1, obj);
+		ao2_link(c1, obj);
 	}
 	ast_cli(fd, "testing callbacks\n");
-	astobj2_callback(c1, 0, print_cb, (void *)fd);
+	ao2_callback(c1, 0, print_cb, (void *)fd);
 
 	ast_cli(fd, "testing iterators, remove every second object\n");
-	astobj2_iterator_init(c1, &ai);
+	ao2_iterator_init(c1, &ai);
 {
 	int x = 0;
-	while ( (obj = astobj2_iterator_next(&ai)) ) {
+	while ( (obj = ao2_iterator_next(&ai)) ) {
 		ast_cli(fd, "iterator on <%s>\n", obj);
 		if (x++ & 1) {
-		    astobj2_unlink(c1, obj);
+		    ao2_unlink(c1, obj);
 		}
-		astobj2_ref(obj, -1);
+		ao2_ref(obj, -1);
 	}
 }
 	ast_cli(fd, "testing callbacks again\n");
-	astobj2_callback(c1, 0, print_cb, (void*)fd);
+	ao2_callback(c1, 0, print_cb, (void*)fd);
 
 	ast_cli(fd, "destroy container\n");
-	astobj2_ref(c1, -1);	/* destroy container */
+	ao2_ref(c1, -1);	/* destroy container */
 	ast_verbose("at the end have %d objects\n",
-		astobj2_total_objects);
+		ao2_total_objects);
 	return 0;
 }
 



More information about the asterisk-commits mailing list