Use atomic operations on signal variable.

Signals are just used to set a flag on a variable which is in turn checked in
the main loop to see if the action of the signal needs to be executed.

Since signal can interrupt at any moment without guarantee, this change uses
gcc's atomic extensions to set and get the flags on the variable, and be sure
that no interleaving occurs.