Switches to master/slave role in separate and single thread

Previously switching to master happened in the state machine event thread
which introduced problems if that for some reason took a long time since
no other events could be processed and eventually this instance to become
master would be suspect of suspicions from the other instance. This would
add instabilities during master switches and prolong some switches as
well.

Now the switching happens in a separate, yet single, thread that is shared
by both the slave and master switching and so they cannot happen
concurrently either.