sync: make EnterCritical() & push_lock() type safe
The functions EnterCritical() and push_lock() take a pointer to a
mutex, but that pointer used to be of type void* because we use a few
different types for mutexes. This void* argument was not type safe
because somebody could have send a pointer to anything that is not a
mutex. Furthermore it wouldn't allow to check whether the passed mutex
is recursive or not.Thus, change the functions to templated ones so that we can implement
stricter checks for non-recursive mutexes. This also simplifies the
callers of EnterCritical().
sync: detect double lock from the same thread
Double lock of the same (non-recursive) mutex from the same thread
is producing an undefined behavior. Detect this from DEBUG_LOCKORDER
and react similarly to the deadlock detection.
This is a backport of core#19337 and core#20507
Note that boost::mutex is no longer in use since D13966