Subject: Kernel threads
To: None <tech-kern@netbsd.org>
From: Bharani Chadalavada <bharani.chadalavada@nexsi.com>
List: tech-kern
Date: 04/01/2001 19:25:31
Hi,

I am trying to port thr serial port to one of our custom chips. However
due to some hardware bugs I cannot do a transmit to the serial port with
interrupts disabled (like is done in comintr (/src/sys/dev/ic/com.c)).
So, I was using kernel thread which executes out of interrupt context to
write the actual bytes to the serial port. But I am running to a
dead-lock problem. Basically the thread code looks like this...

while(1)
{
    tsleep(&sync, ....);
     write_bytes();
    sync = 1;
}

And this thread gets woken up by comintr on transmit complete interrupt.

wakeup(&sync);

But hardware is so fast that I get the transmit complete interrupt
before the thread executes sleep. So, I am losing interrupts.

I was wondering if anyone encountered some problem like this. And if
there are some synchronisation mechanisms between threads. Basically
I need to wake up the thread only if it is not sleeping. And if it is
already executing I need to wait till it sleeps and then wake it up.

Is something like this doable??

Thank you in advance,
Bharani.