RTLinux-2.2:

I have an interrupt driven thread that reads data from hardware into an
intermediate buffer.  It flushes the buffer to a fifo at a certain
threshold.  There is a corresponding Linux process that reads the fifo.
I need to guarantee that all data is rtf_put'd; no partial writes.

Seems to me in order to do this, I need to yield the processor to the
Linux kernel so the consumer process can empty the fifo to make room.

I could do this with a periodic helper thread that waits on a condition
variable, but I'm a little fuzzy on what it means for a periodic thread to
sleep on a condition.  Also, I would like to eliminate any unnecessary
preemption of my interrupt driven thread.

The alternative is to convert the interrupt driven thread into a
periodic thread which attempts to flush the data and when all the data is
done, converts itself back to an interrupt driven thread.  Something like
so:

    ...
    if (buffer is over threshold) {
        written = rtf_put(buffer.start, buffer.length);
        if (written < buffer.length) {
            pthread_make_periodic_np(self, now, period);
            buffer.start += written;
            buffer.length -= written;
            while (buffer.length > 0) {
                written = rtf_put(buffer.start, buffer.length);
                buffer.start += written;
                buffer.length -= written;
                pthread_wait_np();
            }
            pthread_make_periodic_np(self, now, 0);
        }
    }

    /* The IRQ handler clears the interrupt and wakes this thread up. I have
     * a control line that holds off further hardware inputs (and
     * interrupts) until I reset it here
     */
    reset_control_line();
    rtl_hard_enable_irq(...);


Anything wrong with this scheme?  Does setting the period to 0 do the trick?
Is the cpu state preserved across pthread_make_periodic_np(), that is, will
the code start executing where I think it will, or am I completely
confused?

I apologize if the mail is too lengthy.


-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
---
For more information on Real-Time Linux see:
http://www.rtlinux.org/rtlinux/

Reply via email to