I have programmed a device driver with interrupt all done in single
thread. So I use InterrruptLock()and InterruptUnlock() to deal with the
common data in the ISR and its thread.
Now I want to put the interrupt handle into one thread (to do more
work),and put other message handle cycle into another thread.That is to say
I want to reprogram the driver in two threads.I use interrupt thread to deal
with thread,and normal thread to receive and dispatch pulse message( such as
io_read() io_devctl()). Now there is a common data shared by the normal
thread, interrupt thread and interrupt handle.
The shared date are a queue about interrupt(include interrupt happen time,
interrupt data and so on).For get time in ISR is difficult.(there is no safe
time function in ISR).So I want to get interrupt time in the int_thread()
after return from ISR .And in io_read() deal with client reading the
interrupt queue data.So I must use the share data among them.
How to deal with the shared common data among the threads to protect share
data?
Still use InterrruptLock() and InterruptUnlock() as below?
static resmgr_io_funcs_t io_funcs;
int nor_thread()
{
…
io_funcs.read = io_read;
…
while(1) {
if((ctp = dispatch_block(ctp)) == NULL) {
fprintf(stderr, “block error\n”);
return EXIT_FAILURE;
}
dispatch_handler(ctp);
}
}
…
io_read(…)
{
…
InterrruptLock() ;
/* … critical section */
read_interrupt_queue_data_return_to_client
InterruptUnlock();
…
}
int_thread(…)
{
…
InterruptAttach (, isr_handler,);
…
while (1)
{
InterruptWait (NULL, NULL);
InterrruptLock() ;
/* … critical section */
get_interrupt_time…
create_interrupt_queue_data.
InterrruptUnlock() ;
}
}
int_handler(…)
{
InterrruptLock() ;
/* … critical section */
get_interrupt_data
InterruptUnlock();
}
any idea,thanks!