On Tuesday, 8 January 2013 08:42:44 UTC, Kiste wrote: > > On Tuesday, 8 January 2013 06:00:26 UTC, ScannerPrincess wrote: > > > What about disabling interrupts in the mainline code, making > a copy of the variable and then enabling interrupts again? > Working with the copy should be safe ... > > > Isn't there then a risk missing an interrupt? I'm not sure about this, but > if we turn off interrupts I don't think they'd queue until turned back on. > > No, no Interrupt will be missed. The IF flags are set regardless of the > GIE flag setting, and as soon as GIE is enabled again, the interrupt is > triggered. >
Thank you, both, for helping me to understand all this. In that case, it's all trivially easy - that bit of inspiration I was hoping someone out there had! Making it general is presumably as simple as having two functions and scattering those throughout the code where needed: oldstate = maskinterrupts() -- returns previous GIE value ... restoreinterrupts(oldstate) -- puts it back. I take your point about libraries potentially wasting space and cycles, but I think I'd still do it this way, *and* use the functions from inside an ISR, just to keep things easy to understand. I'm quite happy to optimise stuff away when space becomes a premium (got some code I'm particularly proud of on a 12f615...), but readability 2 years later is also worthwhile :-) Does anyone think there's any use at all for that atomic lock library I mentioned earlier? I'm happy to test, document and release it, but I'm not sure there's any particular usage scenario, given the above. Cheers, Alun. -- You received this message because you are subscribed to the Google Groups "jallib" group. To view this discussion on the web visit https://groups.google.com/d/msg/jallib/-/oTBE4QGpJdQJ. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/jallib?hl=en.
