Add a mutex to protect the events map.

Fixes 7 races that the race detector was complaining about right off the bat.
Add mutexes to protect the Connection and Event structs.

Eliminates the remaining races that the race detector was complaining about in the test suite. This just kind of silences specific noise for now though.
Merge pull request #1 from anachronistic/races

Races