ian zagorskih <ianzag@novosoft-us.com> wrote:
“Wojtek Lerch” <> wojtek_l@yahoo.ca> > wrote in message
news:9o54pt$pgc$> 1@nntp.qnx.com> …
…
Just do something like this:
unsigned flags = disable();
…
restore( flags );
assumed that all code both mine and written by someone else was written
according to the rules and no one dosn’t touch IF flag directly. only
enable()/disable() calls.
void third_party_fnc(void) {
disable();
/* … */
enable();
};
void my_fnc(void) {
unsigned old_flags;
/* enter critical section /
old_flags = disable();
/ … /
third_party_fnc();
/ at this point, where’s the guarantee that interrupts are still been
disabled ? pure russian rulette… /
/ … /
/ The Most Critical Part Is Here… maybe leading to the crash maybe
not… /
/ … /
/ “leave critical section” */
restore(old_flags);
};
You should minimize the amount of code that runs with interrupts
disabled. In particular, I don’t think it’s a good idea to disable
interrupts and then call a function that was not designed to run with
interrupts disabled. And things get even worse if it’s a kind of
function that disables interrupts itself – what if there’s code in it
that assumes that interrupts are enabled, and spins in a loop to wait
for an interrupt?
It’s hard for me to come up with a realistic example of why you would
need to do anything like that. What kind of third-party code are you
talking about?
Personally, I wouldn’t feel comfortable calling a third-party function
with interrupts disabled, even if I knew that that function never
enables interrupts. Instead, I would try to re-arrange my code in such
a way that it would never need to disable interrupts for more than
several opcodes.
Keep in mind that QNX is a realtime OS, and even if your particular
setup does not require hard realtime, disabling interrupts for too long
may break some drivers that were not designed with that kind of a
situation in mind. It’s a situation that normally doesn’t occur under
QNX.
Of course, it’s generally not a good idea to disable interrupts for a
long time. Even if you need interrupts disabled almost most of the
time for a while, you can improve overall interrupt latency by finding
places in the code where you can safely insert calls to enable() and
disable().
well, agree that this is another question how disabled interrupts can
reflect on the overal system performance.
I wasn’t talking about the overall performance. I was talking about the
worst-case interrupt latency.
For instance, how long can you disable interrupts for before you start
getting overruns on the serial port? What about the network card or
other hardware?
–
Wojtek Lerch QNX Software Systems Ltd.