Based on this question, I extended std::mutex so that I can check if the mutex is already locked by the current thread:
std::mutex