Github user ted-ross commented on a diff in the pull request:

    https://github.com/apache/qpid-dispatch/pull/169#discussion_r123356457
  
    --- Diff: src/router_core/transfer.c ---
    @@ -412,14 +412,41 @@ static void 
qdr_delete_delivery_internal_CT(qdr_core_t *core, qdr_delivery_t *de
         free_qdr_delivery_t(delivery);
     }
     
    +static bool qdr_delivery_has_peer_CT(qdr_delivery_t *dlv)
    +{
    +    if (!dlv->peer && DEQ_SIZE(dlv->peers) == 0)
    +        return false;
    +    return true;
    +}
    +
     
     void qdr_delivery_link_peers_CT(qdr_delivery_t *in_dlv, qdr_delivery_t 
*out_dlv)
     {
    -    assert(!in_dlv->peer);
    -    assert(!out_dlv->peer);
    +    // If there is no delivery or a peer, we cannot link each other.
    +    if (!in_dlv || !out_dlv)
    +        return;
    +
    +    if (!qdr_delivery_has_peer_CT(in_dlv)) {
    +        // This is the very first peer. Link them up.
    +        assert(!out_dlv->peer);
     
    -    out_dlv->peer = in_dlv;
    -    in_dlv->peer = out_dlv;
    +        out_dlv->peer = in_dlv;
    +        in_dlv->peer = out_dlv;
    +    }
    +    else {
    +        if (in_dlv->peer) {
    +            // This is the first time we know that in_dlv is going to have 
more than one peer.
    +            // There is already a peer in the in_dlv->peer pointer, move 
it into a list and zero it out.
    +            qdr_add_delivery_ref_CT(&in_dlv->peers, in_dlv->peer);
    +
    +            // Zero out the peer pointer. Since there is more than one 
peer, this peer has been moved to the "peers" linked list.
    +            // All peers will now reside in the peers linked list. No need 
to decref/incref here because you are transferring ownership.
    +            in_dlv->peer = 0;
    +        }
    +
    +        out_dlv->peer = in_dlv;
    --- End diff --
    
    Minor point:  You repeat this line.  Why not do this once outside of the 
if-then-else.  The condition does not affect the backward linkage from out to 
in.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to