35 std::lock_guard<std::mutex> guard {mtx};
39 lastTimeUseCountReachedZero = clock::now();
45 assert(managedObjectProxy);
50 RemoteHandleControlBlock::RemoteHandleControlBlock(
Ice::ObjectAdapterPtr objectAdapter, Ice::ObjectPrx managedObjectPrx, std::function<
void ()> deleter):
51 objectAdapter {std::move(objectAdapter)},
52 deleter {std::move(deleter)},
53 managedObjectProxy {std::move(managedObjectPrx)}
57 throw std::invalid_argument {
"RemoteHandleControlBlock() called with a null object adapter."};
59 if (!managedObjectPrx)
61 throw std::invalid_argument {
"RemoteHandleControlBlock() called with a null proxy."};
65 ident.name =
"RemoteHandleControlBlock::" + managedObjectProxy->ice_getIdentity().name +
"::" + IceUtil::generateUUID();
66 selfProxy = RemoteHandleControlBlockInterfacePrx::uncheckedCast(objectAdapter->add(
this, std::move(ident)));
70 deletionDelay {deletionDelayMs},
71 sweeper {
new PeriodicTaskType{
this, &armarx::SharedRemoteHandleState::sweep,
static_cast<int>(deletionDelayMs)}}
78 std::lock_guard<std::mutex> stateGuard {stateMutex};
91 std::lock_guard<std::mutex> stateGuard {stateMutex};
92 rhs.emplace(std::move(rh));
95 void SharedRemoteHandleState::sweep()
97 auto deletionTime = RemoteHandleControlBlock::clock::now() - deletionDelay;
98 std::lock_guard<std::mutex> stateGuard {stateMutex};
99 auto blockIt = rhs.begin();
100 while (blockIt != rhs.end())
102 auto curBlockIt = blockIt++;
103 auto& block = *curBlockIt;
105 std::unique_lock<std::mutex> blockGuard {block->mtx};
108 (!block->useCount && deletionTime > block->lastTimeUseCountReachedZero) ||
109 block->forcedDeletion
115 rhs.erase(std::move(curBlockIt));