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 1 and 2

1 2 3 4
1 2 3 4

  1. /trunk/include/asterisk/astobj2.h: Loading...
/trunk/include/asterisk/astobj2.h
Diff Revision 1 Diff Revision 2
[20] 757 lines
[+20] [+] int ao2_container_count(struct ao2_container *c);
758
 * \param dest Container to copy src object references into.
758
 * \param dest Container to copy src object references into.
759
 * \param src Container to copy all object references from.
759
 * \param src Container to copy all object references from.
760
 * \param flags OBJ_NOLOCK if a lock is already held on both containers.
760
 * \param flags OBJ_NOLOCK if a lock is already held on both containers.
761
 *    Otherwise, the src container is locked first.
761
 *    Otherwise, the src container is locked first.
762
 *
762
 *

    
   
763
 * \note This can potentially be expensive because a malloc is

    
   
764
 * needed for every object in the src container.

    
   
765
 *
763
 * \retval 0 on success.
766
 * \retval 0 on success.
764
 * \retval -1 on error.
767
 * \retval -1 on error.
765
 */
768
 */
766
int ao2_container_dup(struct ao2_container *dest, struct ao2_container *src, enum search_flags flags);
769
int ao2_container_dup(struct ao2_container *dest, struct ao2_container *src, enum search_flags flags);
767

    
   
770

   
768
/*!
771
/*!
769
 * \brief Create a clone/copy of the given container.
772
 * \brief Create a clone/copy of the given container.
770
 * \since 11.0
773
 * \since 11.0
771
 *
774
 *
772
 * \param orig Container to copy all object references from.
775
 * \param orig Container to copy all object references from.
773
 * \param flags OBJ_NOLOCK if a lock is already held on the container.
776
 * \param flags OBJ_NOLOCK if a lock is already held on the container.
774
 *
777
 *

    
   
778
 * \note This can potentially be expensive because a malloc is

    
   
779
 * needed for every object in the orig container.

    
   
780
 *
775
 * \retval Clone container on success.
781
 * \retval Clone container on success.
776
 * \retval NULL on error.
782
 * \retval NULL on error.
777
 */
783
 */
778
struct ao2_container *__ao2_container_clone(struct ao2_container *orig, enum search_flags flags);
784
struct ao2_container *__ao2_container_clone(struct ao2_container *orig, enum search_flags flags);
779
struct ao2_container *__ao2_container_clone_debug(struct ao2_container *orig, enum search_flags flags, const char *tag, char *file, int line, const char *funcname, int ref_debug);
785
struct ao2_container *__ao2_container_clone_debug(struct ao2_container *orig, enum search_flags flags, const char *tag, char *file, int line, const char *funcname, int ref_debug);
[+20] [20] 412 lines
  1. /trunk/include/asterisk/astobj2.h: 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.