Maybe there is a variant of lock_guard already in the standard library or boost that supports custom lock/unlock functions? (similar to how smart pointers support custom delete operations)
E.g. one common scenario is to lock a texture buffer to write to from CPU:
Code: Select all
Ogre::HardwarePixelBufferSharedPtr pixelBuffer = texture->getBuffer();
pixelBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD);
const Ogre::PixelBox& pixelBox = pixelBuffer->getCurrentLock();
// do some writing to pixelBox.data...
pixelBuffer->unlock();