InterruptLock()/InterruptUnlock() question

In DDK dev_lock()/dev_unlock() are implemented as InterruptLock()/InterruptUnlock(). So, my question
is
will it work for syncronizing two threads (not a thread and ISR). For example, for devc-ser8250
InterruptLock/Unlock is only way because tti()/tto() are called from ISR, but in devc-par those are
called from thread writer() which isn’t an interrupt handler. Basicly I want to know, if my
“hardware” handler is a thread (not an ISR) should I use pair dev_lock/unlock, will it work like a
mutex, and is there some workaround to avoid cli/sti (I really don’t need it because my hardware
doesn’t produce any interrupts).

Thanks in advance,
Eduard

“ed1k” <ed1k@humber.bay> wrote in message
news:MPG.1a2f44b772f19279989708@inn.qnx.com

In DDK dev_lock()/dev_unlock() are implemented as
InterruptLock()/InterruptUnlock(). So, my question
is
will it work for syncronizing two threads (not a thread and ISR). For
example, for devc-ser8250
InterruptLock/Unlock is only way because tti()/tto() are called from ISR,
but in devc-par those are
called from thread writer() which isn’t an interrupt handler. Basicly I
want to know, if my
“hardware” handler is a thread (not an ISR) should I use pair
dev_lock/unlock, will it work like a
mutex, and is there some workaround to avoid cli/sti (I really don’t need
it because my hardware
doesn’t produce any interrupts).

Thanks in advance,
Eduard

A mutex might be enough. For example, in networking drivers mutex(s) are
used to synchronize “receiver” thread and “transmitter” logic. Actually
“receiver” is a thread created by a driver on init, and “transmitter” is a
callback executed from one of io-net’s threads.

In article <bq949o$onf$1@inn.qnx.com>, nospam@nospam.no says…

“ed1k” <> ed1k@humber.bay> > wrote in message
news:> MPG.1a2f44b772f19279989708@inn.qnx.com> …
In DDK dev_lock()/dev_unlock() are implemented as
InterruptLock()/InterruptUnlock(). So, my question
is
will it work for syncronizing two threads (not a thread and ISR). For
example, for devc-ser8250
InterruptLock/Unlock is only way because tti()/tto() are called from ISR,
but in devc-par those are
called from thread writer() which isn’t an interrupt handler. Basicly I
want to know, if my
“hardware” handler is a thread (not an ISR) should I use pair
dev_lock/unlock, will it work like a
mutex, and is there some workaround to avoid cli/sti (I really don’t need
it because my hardware
doesn’t produce any interrupts).

Thanks in advance,
Eduard

A mutex might be enough. For example, in networking drivers mutex(s) are
used to synchronize “receiver” thread and “transmitter” logic. Actually
“receiver” is a thread created by a driver on init, and “transmitter” is a
callback executed from one of io-net’s threads.

Sure mutex will do the job. But my device is pure character device and I’d like to use io-char
library to handle POSIX behaviour of character device. There is no source of library in DDK in QNX
6.2+ NC, there is only libio-char.a and I can’t and I do not want to modify the io-char library.
However, there are lots of io-char devices which do not use interrupts and I think library should
provide mechanism of synchronizing for any kind of devices. If I will use pthread_mutex_lock() while
extracting data from buffer and library will use InterruptLock() during inserting data into buffer,
in RK’s house analogy ™, this would be like a washroom with two doors and only one shower. So,
I’m forced to use dev_lock() [which actually is InterruptLock()] and question remains - will
InterruptLock() work for protecting shared recource between two threads? And is any plans to provide
more flexible dev_lock()?

Cheers,
Eduard.


\

“ed1k” <ed1k@humber.bay> wrote in message
news:MPG.1a387392c2222d8a98970d@inn.qnx.com

Sure mutex will do the job. But my device is pure character device and I’d
like to use io-char
library to handle POSIX behaviour of character device. There is no source
of library in DDK in QNX
6.2+ NC, there is only libio-char.a and I can’t and I do not want to
modify the io-char library.
However, there are lots of io-char devices which do not use interrupts and
I think library should
provide mechanism of synchronizing for any kind of devices. If I will use
pthread_mutex_lock() while
extracting data from buffer and library will use InterruptLock() during
inserting data into buffer,
in RK’s house analogy ™, this would be like a washroom with two doors
and only one shower. So,
I’m forced to use dev_lock() [which actually is InterruptLock()] and
question remains - will
InterruptLock() work for protecting shared recource between two threads?
And is any plans to provide
more flexible dev_lock()?

Well, InterruptLock() appears to be a spinlock. So yes, it should work
between threads too.

– igor