Lock / unlock MessageManager in callback


#1

Hi there !

I’ve got a subclass with a virtual method called “observer_lock” and another called “observer_unlock”. When a callback arrives to the observer and needs to alter it’s internals, all the code is wrapped in things like this:

observer_lock(); *ivar = NULL; observer_unlock();

Since some observers are connected to the message manager, it would be good to use these locks to lock/unlock the MessageManager, but I have only found scoped locks.

Does this mean I should do :

[code]void observer_lock() {
lock_ = new MessageManagerLock();
}

void observer_unlock() {
delete lock_;
}[/code]

Or is there another way to do this ?


#2

Yes, you could do it that way… Personally I’d suggest making your own class work as a scoped lock too, so you can just put a MM lock object inside it.


#3