[Freeswitch-svn] [commit] r12298 - in freeswitch/trunk/libs/sofia-sip: . libsofia-sip-ua/su libsofia-sip-ua/su/sofia-sip

FreeSWITCH SVN brian at freeswitch.org
Thu Feb 26 10:23:05 PST 2009


Author: brian
Date: Thu Feb 26 12:23:05 2009
New Revision: 12298

Log:
Tue Feb  3 10:29:44 CST 2009  Pekka Pessi <first.last at nokia.com>
  * su_alloc: added su_home_parent()



Modified:
   freeswitch/trunk/libs/sofia-sip/.update
   freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/sofia-sip/su_alloc.h
   freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/su_alloc.c
   freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/torture_su_alloc.c

Modified: freeswitch/trunk/libs/sofia-sip/.update
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/.update	(original)
+++ freeswitch/trunk/libs/sofia-sip/.update	Thu Feb 26 12:23:05 2009
@@ -1 +1 @@
-Wed Feb 25 13:40:08 CST 2009
+Thu Feb 26 12:22:23 CST 2009

Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/sofia-sip/su_alloc.h
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/sofia-sip/su_alloc.h	(original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/sofia-sip/su_alloc.h	Thu Feb 26 12:23:05 2009
@@ -101,6 +101,8 @@
 
 SU_DLL int su_home_has_parent(su_home_t const *home);
 
+SU_DLL su_home_t *su_home_parent(su_home_t const *home);
+
 SU_DLL void su_home_check(su_home_t const *home);
 
 SU_DLL int su_home_check_alloc(su_home_t const *home, void const *data);

Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/su_alloc.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/su_alloc.c	(original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/su_alloc.c	Thu Feb 26 12:23:05 2009
@@ -746,8 +746,21 @@
 /** Return true if home is a clone. */
 int su_home_has_parent(su_home_t const *home)
 {
-  return home && !home->suh_lock &&
-    home->suh_blocks && home->suh_blocks->sub_parent;
+  return su_home_parent(home) != NULL;
+}
+
+/** Return home's parent home. */
+su_home_t *su_home_parent(su_home_t const *home)
+{
+  su_home_t *parent = NULL;
+
+  if (home && home->suh_blocks) {
+    su_block_t *sub = MEMLOCK(home);
+    parent = sub->sub_parent;
+    UNLOCK(home);
+  }
+
+  return parent;
 }
 
 /** Allocate a memory block.
@@ -1134,6 +1147,12 @@
 	for (i = 0; i < n; i++)
 	  if (s->sub_nodes[i].sua_data) {
 	    su_block_add(d, s->sub_nodes[i].sua_data)[0] = s->sub_nodes[i];
+	    if (s->sub_nodes[i].sua_home) {
+	      su_home_t *subhome = s->sub_nodes[i].sua_data;
+	      su_block_t *subsub = MEMLOCK(subhome);
+	      subsub->sub_parent = dst;
+	      UNLOCK(subhome);
+	    }
 	  }
 
 	s->sub_used = 0;
@@ -1152,8 +1171,21 @@
     s = MEMLOCK(src);
 
     if (s && s->sub_used) {
+      n = s->sub_n;
+
+      for (i = 0; i < n; i++) {
+	if (s->sub_nodes[i].sua_data && s->sub_nodes[i].sua_home) {
+	  su_home_t *subhome = s->sub_nodes[i].sua_data;
+	  su_block_t *subsub = MEMLOCK(subhome);
+	  subsub->sub_parent = dst;
+	  UNLOCK(subhome);
+	}
+      }
+
       s->sub_used = 0;
       memset(s->sub_nodes, 0, s->sub_n * sizeof (s->sub_nodes[0]));
+
+      s->sub_used = 0;
     }
 
     UNLOCK(src);

Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/torture_su_alloc.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/torture_su_alloc.c	(original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/torture_su_alloc.c	Thu Feb 26 12:23:05 2009
@@ -192,6 +192,34 @@
     TEST(h1->suh_size, 13);
   }
 
+  /* Test su_home_parent() */
+  TEST_1(h0 = su_home_new(sizeof *h0));
+  TEST_1(h1 = su_home_clone(h0->home, sizeof *h1));
+  TEST_1(h2 = su_home_clone(h1->home, sizeof *h2));
+  TEST_1(h3 = su_home_clone(h2->home, sizeof *h3));
+
+  TEST_P(su_home_parent(h0->home), NULL);
+  TEST_P(su_home_parent(h1->home), h0);
+  TEST_P(su_home_parent(h2->home), h1);
+  TEST_P(su_home_parent(h3->home), h2);
+  TEST(su_home_move(h0->home, h1->home), 0);
+  TEST_P(su_home_parent(h2->home), h0);
+  TEST_P(su_home_parent(h3->home), h2);
+  TEST(su_home_move(h0->home, h2->home), 0);
+  TEST_P(su_home_parent(h3->home), h0);
+
+  su_home_move(NULL, h0->home);
+
+  TEST_P(su_home_parent(h0->home), NULL);
+  TEST_P(su_home_parent(h1->home), NULL);
+  TEST_P(su_home_parent(h2->home), NULL);
+  TEST_P(su_home_parent(h3->home), NULL);
+
+  su_home_unref(h0->home);
+  su_home_unref(h1->home);
+  su_home_unref(h2->home);
+  su_home_unref(h3->home);
+
   END();
 }
 



More information about the Freeswitch-svn mailing list