share data in interrupt deal thread.

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!

zhz_zhang wrote:

How to deal with the shared common data among the threads to protect share
data?

Pick up “Programming with Posix Threads” by David R. Butenhof ISBN
0-201-63392-2. This book should cover everything you know about
synchronizing data accesses between threads.

Rennie

But if one thread have interrupt handle by ISR (InterrruptAttach)or
InterruptAttachEvent .Only use mutx …and so on,could they
protect share data in interrput thread and normal thread?

“Rennie Allen” <rallen@csical.com> wrote in message
news:3DC8CA77.1050504@csical.com

zhz_zhang wrote:

How to deal with the shared common data among the threads to protect
share
data?

Pick up “Programming with Posix Threads” by David R. Butenhof ISBN
0-201-63392-2. This book should cover everything you know about
synchronizing data accesses between threads.

Rennie

zhz_zhang wrote:

But if one thread have interrupt handle by ISR (InterrruptAttach)or
InterruptAttachEvent .Only use mutx …and so on,could they
protect share data in interrput thread and normal thread?

You don’t. The idea is that the interrupt handler does nothing but return
an event. The interrupt thread (i.e. the thread that does an
InterruptWait()), does all the real processing and is a completely
“normal” thread (i.e. all the pthread sync primitives can be used).

Rennie