Use RAII mechanism and weak_prt / shared_ptr pattern to protect fwData against race condition and memory dumping
Description
Currently, people use IService::getInput/output/inout()
to access data through a shared pointer. It's fine unless threads and worker come into the dance. Smart people then use mutex/mutex guard to lock the data like ::fwData::mt::ObjectReadLock
, but usually most people simply forgot to use them (because of laziness, because of lack of forecasting the use of the service in a multi threaded context, ...).
Proposal
The main idea is to deprecated IService::getInput/output/inout()
in favor of something that return a kind of weak_ptr. This weak_ptr should be locked to acquire a kind of shared_ptr that will also lock a mutex and lock for dump data that holds a BufferObject, as long as the shared_ptr is alive. The weak_ptr can be stored as class variable, as it is "weak" it won't take ownership until locked.