> On Wed, 20 Oct 1999, David Hinds wrote:
>
> >Look at net/irda/*.c [..]
>
> /* Make sure nobody tries to transmit during the speed change */
> while (irda_lock((void *) &self->netdev.tbusy) == FALSE) {
> WARNING(__FUNCTION__ "(), device locked!\n");
> current->state = TASK_INTERRUPTIBLE;
> schedule_timeout(MSECS_TO_JIFFIES(10));
>
> if (n++ > 10) {
> WARNING(__FUNCTION__ "(), breaking loop!\n");
> break;
> }
> }
I've already sent a very large patch to Alan a couple of days ago, which
removes all the schedule_timeout's from the lower parts of the IrDA
stack. Instead I'm impl. things as state machines and do the timeouts using
timers. Some code can look a bit hairy because of this, but it's working
quite well.
struct irda_task;
typedef int (*TASK_CALLBACK) (struct irda_task *task);
struct irda_task {
queue_t q;
magic_t magic;
TASK_STATE state;
TASK_CALLBACK function;
TASK_CALLBACK finished;
struct irda_task *parent;
struct timer_list timer;
void *instance; /* Instance being called */
void *param; /* Parameter to be used by instance */
};
... then I can do things like this to make timeouts:
int tekram_reset(struct irda_task *task)
{
dongle_t *self = (dongle_t *) task->instance;
int ret = 0;
DEBUG(2, __FUNCTION__ "()\n");
ASSERT(task != NULL, return -1;);
/* Power off dongle */
self->set_dtr_rts(self->dev, FALSE, FALSE);
switch (task->state) {
case IRDA_TASK_INIT:
irda_task_next_state(task, IRDA_TASK_WAIT1);
/* Sleep 50 ms */
ret = MSECS_TO_JIFFIES(50);
break;
case IRDA_TASK_WAIT1:
/* Clear DTR, Set RTS */
self->set_dtr_rts(self->dev, FALSE, TRUE);
irda_task_next_state(task, IRDA_TASK_WAIT2);
/* Should sleep 1 ms, but 10 should not do any harm */
ret = MSECS_TO_JIFFIES(10);
break;
There are a couple of helping functions as well, but I guess you get my
point.
The reason is that the lower part is interrupt driven, and I previously had
to use a user-space daemon to help me get the process context for doing
schedule_timeout. Now there is no need for such a deamon anymore (at least
if my patch goes in, and when I have done a few more patches to IrLAN ;-)
Anyway, thanks for the info.
-- Dag
-- / Dag Brattli | The Linux-IrDA Project / // University of Tromsoe, Norway | Infrared communication for Linux // /// http://www.cs.uit.no/~dagb | http://www.cs.uit.no/linux-irda/ ///- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/