RAII locking implementation. This should fix bug [#32096] Background music stops when playing 3D sounds.