You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by tr...@apache.org on 2014/05/12 20:17:19 UTC

svn commit: r1594043 - in /qpid/dispatch/trunk/src: router_node.c router_private.h

Author: tross
Date: Mon May 12 18:17:18 2014
New Revision: 1594043

URL: http://svn.apache.org/r1594043
Log:
DISPATCH-43 - Cleaned up the management of link mask-bits in preparation
              for generalizing inter-router links.

Modified:
    qpid/dispatch/trunk/src/router_node.c
    qpid/dispatch/trunk/src/router_private.h

Modified: qpid/dispatch/trunk/src/router_node.c
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/src/router_node.c?rev=1594043&r1=1594042&r2=1594043&view=diff
==============================================================================
--- qpid/dispatch/trunk/src/router_node.c (original)
+++ qpid/dispatch/trunk/src/router_node.c Mon May 12 18:17:18 2014
@@ -225,6 +225,10 @@ static int qd_router_terminus_is_router(
 }
 
 
+/**
+ * Generate a temporary routable address for a destination connected to this
+ * router node.
+ */
 static void qd_router_generate_temp_addr(qd_router_t *router, char *buffer, size_t length)
 {
     static const char *table = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+_";
@@ -244,11 +248,17 @@ static void qd_router_generate_temp_addr
 }
 
 
+/**
+ * Assign a link-mask-bit to a new link.  Do this in such a way that all links on the same
+ * connection share the same mask-bit value.
+ */
 static int qd_router_find_mask_bit_LH(qd_router_t *router, qd_link_t *link)
 {
     qd_router_conn_t *shared = (qd_router_conn_t*) qd_link_get_conn_context(link);
-    if (shared)
+    if (shared) {
+        shared->ref_count++;
         return shared->mask_bit;
+    }
 
     int mask_bit;
     if (qd_bitmask_first_set(router->neighbor_free_mask, &mask_bit)) {
@@ -259,7 +269,8 @@ static int qd_router_find_mask_bit_LH(qd
     }
 
     shared = new_qd_router_conn_t();
-    shared->mask_bit = mask_bit;
+    shared->ref_count = 1;
+    shared->mask_bit  = mask_bit;
     qd_link_set_conn_context(link, shared);
     return mask_bit;
 }
@@ -1154,17 +1165,27 @@ static int router_link_detach_handler(vo
     qd_address_t     *oaddr  = 0;
     int               lost_link_mask_bit = -1;
 
-    if (shared) {
-        qd_link_set_conn_context(link, 0);
-        free_qd_router_conn_t(shared);
-    }
-
     if (!rlink)
         return 0;
 
     sys_mutex_lock(router->lock);
 
     //
+    // If this link is part of an inter-router connection, drop the
+    // reference count.  If this is the last link on the connection,
+    // free the mask-bit and the shared connection record.
+    //
+    if (shared) {
+        shared->ref_count--;
+        if (shared->ref_count == 0) {
+            lost_link_mask_bit = rlink->mask_bit;
+            qd_bitmask_set_bit(router->neighbor_free_mask, rlink->mask_bit);
+            qd_link_set_conn_context(link, 0);
+            free_qd_router_conn_t(shared);
+        }
+    }
+
+    //
     // If the link is outgoing, we must disassociate it from its address.
     //
     if (rlink->link_direction == QD_OUTGOING && rlink->owning_addr) {
@@ -1184,14 +1205,6 @@ static int router_link_detach_handler(vo
     }
 
     //
-    // If this is an incoming inter-router link, we must free the mask_bit.
-    //
-    if (rlink->link_type == QD_LINK_ROUTER && rlink->link_direction == QD_INCOMING) {
-        lost_link_mask_bit = rlink->mask_bit;
-        qd_bitmask_set_bit(router->neighbor_free_mask, rlink->mask_bit);
-    }
-
-    //
     // Remove the link from the master list-of-links.
     //
     DEQ_REMOVE(router->links, rlink);

Modified: qpid/dispatch/trunk/src/router_private.h
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/src/router_private.h?rev=1594043&r1=1594042&r2=1594043&view=diff
==============================================================================
--- qpid/dispatch/trunk/src/router_private.h (original)
+++ qpid/dispatch/trunk/src/router_private.h Mon May 12 18:17:18 2014
@@ -115,6 +115,7 @@ DEQ_DECLARE(qd_router_link_ref_t, qd_rou
 
 
 struct qd_router_conn_t {
+    int ref_count;
     int mask_bit;
 };
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org