Rearranged tests in canque_test_outslot for faster and more optimal behavior.
authorppisa <ppisa>
Mon, 19 Apr 2004 00:50:39 +0000 (00:50 +0000)
committerppisa <ppisa>
Mon, 19 Apr 2004 00:50:39 +0000 (00:50 +0000)
Some tests required additional loop for EMPTY and DEAD edge states.

lincan/src/can_queue.c

index b0c027e..c4130aa 100644 (file)
@@ -313,6 +313,20 @@ int canque_test_outslot(struct canque_ends_t *qends,
                while(!list_empty(&qends->active[prio])){
                        edge=list_entry(qends->active[prio].next,struct canque_edge_t,activepeers);
                        if(!canque_fifo_test_fl(&edge->fifo,DEAD)) {
+                               /* The first test on unlocked FIFO */
+                               if(canque_fifo_test_fl(&edge->fifo,EMPTY)) {
+                                       can_spin_lock(&edge->fifo.fifo_lock);
+                                       /* Test has to be repeated to ensure that EMPTY
+                                          state has not been nagated when locking FIFO */
+                                       if(canque_fifo_test_fl(&edge->fifo,EMPTY)) {
+                                               canque_fifo_set_fl(&edge->fifo,INACTIVE);
+                                               list_del(&edge->activepeers);
+                                               list_add(&edge->activepeers,&qends->idle);
+                                               can_spin_unlock(&edge->fifo.fifo_lock);
+                                               continue;
+                                       }
+                                       can_spin_unlock(&edge->fifo.fifo_lock);
+                               }
                                canque_edge_incref(edge);
                                can_spin_unlock_irqrestore(&qends->ends_lock, flags);
                                *qedgep=edge;
@@ -320,14 +334,16 @@ int canque_test_outslot(struct canque_ends_t *qends,
                                ret=canque_fifo_test_outslot(&edge->fifo, slotp);
                                if(ret>=0)
                                        return ret;
+
+                               canque_edge_decref(edge);
                                can_spin_lock_irqsave(&qends->ends_lock, flags);
-                       }
-                       can_spin_lock(&edge->fifo.fifo_lock);
-                       if(canque_fifo_test_and_set_fl(&edge->fifo,INACTIVE)) {
+                       } else {
+                               can_spin_lock(&edge->fifo.fifo_lock);
+                               canque_fifo_set_fl(&edge->fifo,INACTIVE);
                                list_del(&edge->activepeers);
                                list_add(&edge->activepeers,&qends->idle);
+                               can_spin_unlock(&edge->fifo.fifo_lock);
                        }
-                       can_spin_unlock(&edge->fifo.fifo_lock);
                }
        }
        can_spin_unlock_irqrestore(&qends->ends_lock, flags);