More canqueue locking changes.
authorppisa <ppisa>
Thu, 24 Jun 2004 14:15:18 +0000 (14:15 +0000)
committerppisa <ppisa>
Thu, 24 Jun 2004 14:15:18 +0000 (14:15 +0000)
lincan/include/can_queue.h
lincan/src/can_queue.c

index 3be8469..5ed1fe4 100644 (file)
@@ -554,24 +554,24 @@ void canque_edge_incref(struct canque_edge_t *edge)
 }
 
 static inline
-can_spin_irqflags_t canque_edge_lock_both_ends(struct canque_edge_t *edge)
+can_spin_irqflags_t canque_edge_lock_both_ends(struct canque_ends_t *inends, struct canque_ends_t *outends)
 {
        can_spin_irqflags_t  flags;
-       if(edge->inends<edge->outends) {
-               can_spin_lock_irqsave(&edge->inends->ends_lock, flags);
-               can_spin_lock(&edge->outends->ends_lock);
+       if(inends<outends) {
+               can_spin_lock_irqsave(&inends->ends_lock, flags);
+               can_spin_lock(&outends->ends_lock);
        }else{
-               can_spin_lock_irqsave(&edge->outends->ends_lock, flags);
-               if(edge->outends!=edge->inends) can_spin_lock(&edge->inends->ends_lock);
+               can_spin_lock_irqsave(&outends->ends_lock, flags);
+               if(outends!=inends) can_spin_lock(&inends->ends_lock);
        }
        return flags;   
 }
 
 static inline
-void canque_edge_unlock_both_ends(struct canque_edge_t *edge, can_spin_irqflags_t flags)
+void canque_edge_unlock_both_ends(struct canque_ends_t *inends, struct canque_ends_t *outends, can_spin_irqflags_t flags)
 {
-       if(edge->outends!=edge->inends) can_spin_unlock(&edge->outends->ends_lock);
-       can_spin_unlock_irqrestore(&edge->inends->ends_lock, flags);
+       if(outends!=inends) can_spin_unlock(&outends->ends_lock);
+       can_spin_unlock_irqrestore(&inends->ends_lock, flags);
 }
 
 /* Non-inlined version of edge reference decrement */
@@ -582,15 +582,17 @@ void __canque_edge_decref_body(struct canque_edge_t *edge)
 {
        can_spin_irqflags_t flags;
        int dead_fl=0;
+       struct canque_ends_t *inends=edge->inends;
+       struct canque_ends_t *outends=edge->outends;
        
-       flags=canque_edge_lock_both_ends(edge);
+       flags=canque_edge_lock_both_ends(inends, outends);
        if(atomic_dec_and_test(&edge->edge_used)) {
                dead_fl=!canque_fifo_test_and_set_fl(&edge->fifo,DEAD);
                /* Because of former evolution of edge references 
                   management notify of CANQUEUE_NOTIFY_NOUSR could
                   be moved to canque_edge_do_dead :-) */
        }
-       canque_edge_unlock_both_ends(edge, flags);
+       canque_edge_unlock_both_ends(inends, outends, flags);
        if(dead_fl) canque_edge_do_dead(edge);
 }
 
index a75bb46..d90b9c5 100644 (file)
@@ -524,7 +524,7 @@ int canqueue_connect_edge(struct canque_edge_t *qedge, struct canque_ends_t *ine
        if(qedge == NULL) return -1;
        DEBUGQUE("canqueue_connect_edge %d\n",qedge->edge_num);
        canque_edge_incref(qedge);
-       flags=canque_edge_lock_both_ends(qedge);
+       flags=canque_edge_lock_both_ends(inends, outends);
        can_spin_lock(&qedge->fifo.fifo_lock);
        qedge->inends=inends;
        list_add(&qedge->inpeers,&inends->inlist);
@@ -532,7 +532,7 @@ int canqueue_connect_edge(struct canque_edge_t *qedge, struct canque_ends_t *ine
        list_add(&qedge->outpeers,&outends->outlist);
        list_add(&qedge->activepeers,&outends->idle);
        can_spin_unlock(&qedge->fifo.fifo_lock);
-       canque_edge_unlock_both_ends(qedge, flags);
+       canque_edge_unlock_both_ends(inends, outends, flags);
        canque_notify_bothends(qedge, CANQUEUE_NOTIFY_ATTACH);
 
        if(canque_fifo_test_and_set_fl(&qedge->fifo, READY))
@@ -557,7 +557,7 @@ int canqueue_disconnect_edge(struct canque_edge_t *qedge)
        outends=qedge->outends;
 
        if(inends && outends) {
-               flags=canque_edge_lock_both_ends(qedge);
+               flags=canque_edge_lock_both_ends(inends, outends);
        } else {
                DEBUGQUE("canqueue_disconnect_edge called with not fully connected edge");
                if(inends) can_spin_lock_irqsave(&inends->ends_lock,flags);
@@ -582,7 +582,7 @@ int canqueue_disconnect_edge(struct canque_edge_t *qedge)
        can_spin_unlock(&qedge->fifo.fifo_lock);
 
        if(inends && outends) {
-               canque_edge_unlock_both_ends(qedge, flags);
+               canque_edge_unlock_both_ends(inends, outends, flags);
        } else {
                if(outends) can_spin_unlock(&outends->ends_lock);
                if(inends) can_spin_unlock_irqrestore(&inends->ends_lock,flags);