I've created a simple pthread_mutex_lock wrapper to have a scoped lock like in boost::thread
Now , while I'm trying to re-write some code to make use of this, I'm stucking this this part:
class ScopedLock : boost::noncopyable
As you see I'm creating a scope to lock mPrioQueueMutex inside. Then I'm constructing the smanager object, which I also need outside the scope.
boost::shared_ptr<SwarmManagerEntity> smanager(new SwarmManagerEntity(
entity_id, *this, mrPrioQueue, PrioSet::DEFAULT_PRIO));
// put it in the pointer container
std::make_pair<int, boost::shared_ptr<SwarmManagerEntity> >(entity_id, smanager));
// copy the entity state from swrm to object
I see 2 possibilities:
- adding a SwarmManagerEntity default ctor together with an initialize member to do two-step-construction. Then the object could be created outside the scope and initialized inside the critical section.
- I could expand the critical section to the point the smanager object isn't needed any more.
Is there another solution?
Thank you in advance!