Review Board 1.7.16


Add ability to clone ao2 containers.

Review Request #1746 - Created Feb. 15, 2012 and submitted

rmudgett
trunk
Reviewers
asterisk-dev
Asterisk
Occasionally there is a need to put all objects in one container also into another container.

Some reasons you might need to do this:
1) You need to reconfigure a container.   You would do this by creating a new container with the new configuration and ao2_container_dup the old container into it.  Then replace the old container with the new.  Then destroy the old container.

2) You need the contents of a container to remain stable while operating on all of the objects.  You would do this by creating a cloned container of the original with ao2_container_clone.  The cloned container is a snapshot of the objects at the time of the cloning.  When done, just destroy the cloned container.
Added unit testing code to test the new ao2_container_clone and ao2_container_dup functions.

Tests still pass.

Changes between revision 3 and 4

1 2 3 4
1 2 3 4

  1. /trunk/include/asterisk/astobj2.h: Loading...
  2. /trunk/main/astobj2.c: Loading...
  3. /trunk/tests/test_astobj2.c: Loading...
/trunk/include/asterisk/astobj2.h
Diff Revision 3 Diff Revision 4
[20] 393 lines
[+20] [+] typedef void (*ao2_destructor_fn)(void *);
394
/*!
394
/*!
395
 * \brief Allocate and initialize an object.
395
 * \brief Allocate and initialize an object.
396
 *
396
 *
397
 * \param data_size The sizeof() of the user-defined structure.
397
 * \param data_size The sizeof() of the user-defined structure.
398
 * \param destructor_fn The destructor function (can be NULL)
398
 * \param destructor_fn The destructor function (can be NULL)
399
 * \param debug_msg Ao2 object debug tracing message.
399
 * \param debug_msg An ao2 object debug tracing message.
400
 * \return A pointer to user-data.
400
 * \return A pointer to user-data.
401
 *
401
 *
402
 * \details
402
 * \details
403
 * Allocates a struct astobj2 with sufficient space for the
403
 * Allocates a struct astobj2 with sufficient space for the
404
 * user-defined structure.
404
 * user-defined structure.
[+20] [20] 378 lines
[+20] [+] int ao2_container_count(struct ao2_container *c);
783
 * \param dest Container to copy src object references into.
783
 * \param dest Container to copy src object references into.
784
 * \param src Container to copy all object references from.
784
 * \param src Container to copy all object references from.
785
 * \param flags OBJ_NOLOCK if a lock is already held on both containers.
785
 * \param flags OBJ_NOLOCK if a lock is already held on both containers.
786
 *    Otherwise, the src container is locked first.
786
 *    Otherwise, the src container is locked first.
787
 *
787
 *

    
   
788
 * \pre The dest container must be empty.  If the duplication fails, the

    
   
789
 * dest container will be emptied.

    
   
790
 *
788
 * \note This can potentially be expensive because a malloc is
791
 * \note This can potentially be expensive because a malloc is
789
 * needed for every object in the src container.
792
 * needed for every object in the src container.
790
 *
793
 *
791
 * \retval 0 on success.
794
 * \retval 0 on success.
792
 * \retval -1 on error.  The dest container has an incomplete
795
 * \retval -1 on error.
793
 * copy of the src container objs.

   
794
 */
796
 */
795
int ao2_container_dup(struct ao2_container *dest, struct ao2_container *src, enum search_flags flags);
797
int ao2_container_dup(struct ao2_container *dest, struct ao2_container *src, enum search_flags flags);
796

    
   
798

   
797
/*!
799
/*!
798
 * \brief Create a clone/copy of the given container.
800
 * \brief Create a clone/copy of the given container.
[+20] [20] 443 lines
/trunk/main/astobj2.c
Diff Revision 3 Diff Revision 4
 
/trunk/tests/test_astobj2.c
Diff Revision 3 Diff Revision 4
 
  1. /trunk/include/asterisk/astobj2.h: Loading...
  2. /trunk/main/astobj2.c: Loading...
  3. /trunk/tests/test_astobj2.c: Loading...

https://reviewboard.asterisk.org/ runs on a server provided by Digium, Inc. and uses bandwidth donated to the open source Asterisk community by API Digital Communications in Huntsville, AL USA.
Please report problems with this site to asteriskteam@digium.com.