X-Git-Url: http://rtime.felk.cvut.cz/gitweb/lincan.git/blobdiff_plain/94b8e4f0425cebad0a186daf054168fa6910f9b8..91dfab84182937b62ef64cb12d8e4f89e6d5c3ec:/lincan/include/can_queue.h diff --git a/lincan/include/can_queue.h b/lincan/include/can_queue.h index 264fce5..2fc422f 100644 --- a/lincan/include/can_queue.h +++ b/lincan/include/can_queue.h @@ -51,7 +51,7 @@ struct canque_fifo_t { struct canque_slot_t **tail; /* points to NULL pointer for chaining */ struct canque_slot_t *flist; /* points the first entry in the free list */ struct canque_slot_t *entry; /* points to first allocated entry */ - spinlock_t fifo_lock; /* spin_lock_irqsave / spin_lock_irqrestore */ + can_spinlock_t fifo_lock; /* can_spin_lock_irqsave / can_spin_unlock_irqrestore */ }; #define CAN_FIFOF_DESTROY_b 15 @@ -102,21 +102,21 @@ struct canque_fifo_t { static inline int canque_fifo_get_inslot(struct canque_fifo_t *fifo, struct canque_slot_t **slotp, int cmd) { - unsigned long flags; + can_spin_irqflags_t flags; struct canque_slot_t *slot; - spin_lock_irqsave(&fifo->fifo_lock, flags); + can_spin_lock_irqsave(&fifo->fifo_lock, flags); /* get the first free slot slot from flist */ if(!(slot=fifo->flist)) { canque_fifo_set_fl(fifo,OVERRUN); canque_fifo_set_fl(fifo,FULL); - spin_unlock_irqrestore(&fifo->fifo_lock, flags); + can_spin_unlock_irqrestore(&fifo->fifo_lock, flags); *slotp=NULL; return -1; } /* adjust free slot list */ if(!(fifo->flist=slot->next)) canque_fifo_set_fl(fifo,FULL); - spin_unlock_irqrestore(&fifo->fifo_lock, flags); + can_spin_unlock_irqrestore(&fifo->fifo_lock, flags); *slotp=slot; slot->slot_flags=cmd&CAN_SLOTF_CMD; return 1; @@ -134,9 +134,9 @@ static inline int canque_fifo_put_inslot(struct canque_fifo_t *fifo, struct canque_slot_t *slot) { int ret; - unsigned long flags; + can_spin_irqflags_t flags; slot->next=NULL; - spin_lock_irqsave(&fifo->fifo_lock, flags); + can_spin_lock_irqsave(&fifo->fifo_lock, flags); if(*fifo->tail) printk(KERN_CRIT "canque_fifo_put_inslot: fifo->tail != NULL\n"); *fifo->tail=slot; fifo->tail=&slot->next; @@ -145,7 +145,7 @@ int canque_fifo_put_inslot(struct canque_fifo_t *fifo, struct canque_slot_t *slo ret=CAN_FIFOF_EMPTY; /* Fifo has been empty before put */ if(canque_fifo_test_and_clear_fl(fifo,INACTIVE)) ret=CAN_FIFOF_INACTIVE; /* Fifo has been empty before put */ - spin_unlock_irqrestore(&fifo->fifo_lock, flags); + can_spin_unlock_irqrestore(&fifo->fifo_lock, flags); return ret; } @@ -160,13 +160,13 @@ static inline int canque_fifo_abort_inslot(struct canque_fifo_t *fifo, struct canque_slot_t *slot) { int ret=0; - unsigned long flags; - spin_lock_irqsave(&fifo->fifo_lock, flags); + can_spin_irqflags_t flags; + can_spin_lock_irqsave(&fifo->fifo_lock, flags); slot->next=fifo->flist; fifo->flist=slot; if(canque_fifo_test_and_clear_fl(fifo,FULL)) ret=CAN_FIFOF_FULL; - spin_unlock_irqrestore(&fifo->fifo_lock, flags); + can_spin_unlock_irqrestore(&fifo->fifo_lock, flags); return ret; } @@ -184,19 +184,19 @@ int canque_fifo_abort_inslot(struct canque_fifo_t *fifo, struct canque_slot_t *s static inline int canque_fifo_test_outslot(struct canque_fifo_t *fifo, struct canque_slot_t **slotp) { - unsigned long flags; + can_spin_irqflags_t flags; int cmd; struct canque_slot_t *slot; - spin_lock_irqsave(&fifo->fifo_lock, flags); + can_spin_lock_irqsave(&fifo->fifo_lock, flags); if(!(slot=fifo->head)){; canque_fifo_set_fl(fifo,EMPTY); - spin_unlock_irqrestore(&fifo->fifo_lock, flags); + can_spin_unlock_irqrestore(&fifo->fifo_lock, flags); *slotp=NULL; return -1; } if(!(fifo->head=slot->next)) fifo->tail=&fifo->head; - spin_unlock_irqrestore(&fifo->fifo_lock, flags); + can_spin_unlock_irqrestore(&fifo->fifo_lock, flags); *slotp=slot; cmd=slot->slot_flags; @@ -218,8 +218,8 @@ static inline int canque_fifo_free_outslot(struct canque_fifo_t *fifo, struct canque_slot_t *slot) { int ret=0; - unsigned long flags; - spin_lock_irqsave(&fifo->fifo_lock, flags); + can_spin_irqflags_t flags; + can_spin_lock_irqsave(&fifo->fifo_lock, flags); slot->next=fifo->flist; fifo->flist=slot; if(canque_fifo_test_and_clear_fl(fifo,FULL)) @@ -228,7 +228,7 @@ int canque_fifo_free_outslot(struct canque_fifo_t *fifo, struct canque_slot_t *s canque_fifo_set_fl(fifo,EMPTY); ret|=CAN_FIFOF_EMPTY; } - spin_unlock_irqrestore(&fifo->fifo_lock, flags); + can_spin_unlock_irqrestore(&fifo->fifo_lock, flags); return ret; } @@ -242,12 +242,12 @@ int canque_fifo_free_outslot(struct canque_fifo_t *fifo, struct canque_slot_t *s static inline int canque_fifo_again_outslot(struct canque_fifo_t *fifo, struct canque_slot_t *slot) { - unsigned long flags; - spin_lock_irqsave(&fifo->fifo_lock, flags); + can_spin_irqflags_t flags; + can_spin_lock_irqsave(&fifo->fifo_lock, flags); if(!(slot->next=fifo->head)) fifo->tail=&slot->next; fifo->head=slot; - spin_unlock_irqrestore(&fifo->fifo_lock, flags); + can_spin_unlock_irqrestore(&fifo->fifo_lock, flags); return 1; } @@ -333,7 +333,7 @@ struct canque_ends_t { struct list_head idle; struct list_head inlist; struct list_head outlist; - spinlock_t ends_lock; /* spin_lock_irqsave / spin_lock_irqrestore */ + can_spinlock_t ends_lock; /* can_spin_lock_irqsave / can_spin_unlock_irqrestore */ void (*notify)(struct canque_ends_t *qends, struct canque_edge_t *qedge, int what); void *context; union { @@ -341,6 +341,9 @@ struct canque_ends_t { wait_queue_head_t readq; wait_queue_head_t writeq; wait_queue_head_t emptyq; + #ifdef CAN_ENABLE_KERN_FASYNC + struct fasync_struct *fasync; + #endif /*CAN_ENABLE_KERN_FASYNC*/ } fileinfo; struct { wait_queue_head_t daemonq; @@ -415,23 +418,23 @@ void canque_notify_bothends(struct canque_edge_t *qedge, int what) static inline void canque_activate_edge(struct canque_ends_t *inends, struct canque_edge_t *qedge) { - unsigned long flags; + can_spin_irqflags_t flags; struct canque_ends_t *outends; if(qedge->edge_prio>=CANQUEUE_PRIO_NR) qedge->edge_prio=CANQUEUE_PRIO_NR-1; - spin_lock_irqsave(&inends->ends_lock, flags); + can_spin_lock_irqsave(&inends->ends_lock, flags); if((outends=qedge->outends)){ - spin_lock(&outends->ends_lock); - spin_lock(&qedge->fifo.fifo_lock); + can_spin_lock(&outends->ends_lock); + can_spin_lock(&qedge->fifo.fifo_lock); if(!canque_fifo_test_fl(&qedge->fifo,EMPTY)){ list_del(&qedge->activepeers); list_add_tail(&qedge->activepeers,&outends->active[qedge->edge_prio]); } - spin_unlock(&qedge->fifo.fifo_lock); - spin_unlock(&outends->ends_lock); + can_spin_unlock(&qedge->fifo.fifo_lock); + can_spin_unlock(&outends->ends_lock); } - spin_unlock_irqrestore(&inends->ends_lock, flags); + can_spin_unlock_irqrestore(&inends->ends_lock, flags); } /** @@ -488,6 +491,10 @@ void canqueue_block_inlist(struct canque_ends_t *qends); void canqueue_block_outlist(struct canque_ends_t *qends); +int canqueue_ends_kill_inlist(struct canque_ends_t *qends, int send_rest); + +int canqueue_ends_kill_outlist(struct canque_ends_t *qends); + /* edge reference and traversal functions */ void canque_edge_do_dead(struct canque_edge_t *edge, int dead_fl); @@ -501,34 +508,34 @@ void canque_edge_incref(struct canque_edge_t *edge) static inline void canque_edge_decref(struct canque_edge_t *edge) { - unsigned long flags; + can_spin_irqflags_t flags; struct canque_ends_t *inends=edge->inends; struct canque_ends_t *outends=edge->outends; int dead_fl; - spin_lock_irqsave(&inends->ends_lock, flags); - spin_lock(&outends->ends_lock); + can_spin_lock_irqsave(&inends->ends_lock, flags); + can_spin_lock(&outends->ends_lock); if(atomic_dec_and_test(&edge->edge_used)) { dead_fl=canque_fifo_test_and_set_fl(&edge->fifo,DEAD); /*This should not be there, but it cannot be outside of the lock :-(*/ canque_notify_bothends(edge,CANQUEUE_NOTIFY_NOUSR); - spin_unlock(&outends->ends_lock); - spin_unlock_irqrestore(&inends->ends_lock, flags); + can_spin_unlock(&outends->ends_lock); + can_spin_unlock_irqrestore(&inends->ends_lock, flags); canque_edge_do_dead(edge, dead_fl); } else { - spin_unlock(&outends->ends_lock); - spin_unlock_irqrestore(&inends->ends_lock, flags); + can_spin_unlock(&outends->ends_lock); + can_spin_unlock_irqrestore(&inends->ends_lock, flags); } } static inline struct canque_edge_t *canque_first_inedge(struct canque_ends_t *qends) { - unsigned long flags; + can_spin_irqflags_t flags; struct list_head *entry; struct canque_edge_t *edge; - spin_lock_irqsave(&qends->ends_lock, flags); + can_spin_lock_irqsave(&qends->ends_lock, flags); entry=qends->inlist.next; skip_dead: if(entry != &qends->inlist) { @@ -541,7 +548,7 @@ struct canque_edge_t *canque_first_inedge(struct canque_ends_t *qends) } else { edge=NULL; } - spin_unlock_irqrestore(&qends->ends_lock, flags); + can_spin_unlock_irqrestore(&qends->ends_lock, flags); return edge; } @@ -549,11 +556,11 @@ struct canque_edge_t *canque_first_inedge(struct canque_ends_t *qends) static inline struct canque_edge_t *canque_next_inedge(struct canque_ends_t *qends, struct canque_edge_t *edge) { - unsigned long flags; + can_spin_irqflags_t flags; struct list_head *entry; struct canque_edge_t *next; - spin_lock_irqsave(&qends->ends_lock, flags); + can_spin_lock_irqsave(&qends->ends_lock, flags); entry=edge->inpeers.next; skip_dead: if(entry != &qends->inlist) { @@ -566,7 +573,7 @@ struct canque_edge_t *canque_next_inedge(struct canque_ends_t *qends, struct can } else { next=NULL; } - spin_unlock_irqrestore(&qends->ends_lock, flags); + can_spin_unlock_irqrestore(&qends->ends_lock, flags); canque_edge_decref(edge); return next; } @@ -577,11 +584,11 @@ struct canque_edge_t *canque_next_inedge(struct canque_ends_t *qends, struct can static inline struct canque_edge_t *canque_first_outedge(struct canque_ends_t *qends) { - unsigned long flags; + can_spin_irqflags_t flags; struct list_head *entry; struct canque_edge_t *edge; - spin_lock_irqsave(&qends->ends_lock, flags); + can_spin_lock_irqsave(&qends->ends_lock, flags); entry=qends->outlist.next; skip_dead: if(entry != &qends->outlist) { @@ -594,7 +601,7 @@ struct canque_edge_t *canque_first_outedge(struct canque_ends_t *qends) } else { edge=NULL; } - spin_unlock_irqrestore(&qends->ends_lock, flags); + can_spin_unlock_irqrestore(&qends->ends_lock, flags); return edge; } @@ -602,11 +609,11 @@ struct canque_edge_t *canque_first_outedge(struct canque_ends_t *qends) static inline struct canque_edge_t *canque_next_outedge(struct canque_ends_t *qends, struct canque_edge_t *edge) { - unsigned long flags; + can_spin_irqflags_t flags; struct list_head *entry; struct canque_edge_t *next; - spin_lock_irqsave(&qends->ends_lock, flags); + can_spin_lock_irqsave(&qends->ends_lock, flags); entry=edge->outpeers.next; skip_dead: if(entry != &qends->outlist) { @@ -619,7 +626,7 @@ struct canque_edge_t *canque_next_outedge(struct canque_ends_t *qends, struct ca } else { next=NULL; } - spin_unlock_irqrestore(&qends->ends_lock, flags); + can_spin_unlock_irqrestore(&qends->ends_lock, flags); canque_edge_decref(edge); return next; }