I have an array A of T *, and I want to make sure that A[0] is never used without locking the mutex M, while changing as little code as possible.
What I thought was writing a wrapper class:
1 2 3 4 5
class A_check{
T *data;
bool check;
//...
};
I need to cover a few cases, such as A[0]->foo, T *p=A[0], and a[0]=p.
Will these two overloads cover the last two cases as I expect?
1 2
operator T *() const{ returnthis->data; }
operator T *&(){ returnthis->data; }
And do you need to lock access to the object or to the pointer?
The pointer.
So wait.... where would you unlock the mutex in all of this?
This code doesn't actually lock the mutex. It just verifies that it's locked. It's used only for debugging. The mutex is locked and unlocked whenever the pointer needs to be used, which is why I need to make sure I didn't forget anything.
I'm not really seeing how the code you posted would work at all
That's because I omitted the checks. I just wanted to give the general idea of what I was trying to do.