[cmyth] Replace library wide mutex with individual mutexes on certain data structures

Backported from cmyth upstream.