The same way I can test whether the current thread has locked the MessageManager with MessageManager::currentThreadHasLockedMessageManager (), is there a way to test whether the current thread is currently holding the lock to a generic CriticalSection?
The purpose is to trigger a jassert if one of my methods is being called while its caller is NOT holding the lock.
You can’t enter a critical section if it’s already entered.
So if tryEnter returns false, it’s because either the current thread has locked it, or another thread has locked it.
I don’t see the point in checking if it’s your thread that locked it or not, it looks like a bad design to me, IMHO.
You better write a private method with a name in “unlockedDoSomething” and a public “doSomething” that calls the former, so you’re sure it’s done automatically.
Anyway, if you want to know which thread locked the CS, you’ll have to write a class like this: