From: David B. <da...@we...> - 2012-08-24 09:35:13
|
On 23/08/2012 22:52, William Swanson wrote: > On Thu, Aug 23, 2012 at 12:49 PM, William Swanson <swa...@gm...> wrote: >>> Another option is a single inline assembly call for the "|=" if the above >>> code split does not help. >> >> I've had to do this in a few places, like when I need to atomically >> update a hardware flag. > > I just realized something horrible. Code like this is not safe: > > P1IFG &= ~P1_PWR_SW; > > There is no assurance that the "&=" operator will work atomically. > Even if it does compile to the correct "bis.b" instruction, what > happens if another IO pin toggles mid-instruction? Could the > transition be lost? Hopefully the chip designers accounted for this, > but it's still a scary thought. > There is no guarantee that the compiler will produce a single "bis" instruction for such code (though it normally will) - as I said before, "volatile" gives you very few guarantees according to the standards. |