unlock around call to createChannel

This commit is contained in:
Michael Davidsaver
2015-12-08 20:08:32 -05:00
parent 3223c5da19
commit 3118f92a61
3 changed files with 18 additions and 32 deletions

View File

@ -149,27 +149,3 @@ ChannelCache::~ChannelCache()
timerQueue->release();
delete cleaner;
}
// caller must host cacheLock
ChannelCacheEntry::shared_pointer
ChannelCache::get(const std::string& name)
{
entries_t::const_iterator it=entries.find(name);
if(it!=entries.end()) {
it->second->dropPoke = true;
return it->second;
}
ChannelCacheEntry::shared_pointer ent(new ChannelCacheEntry(this, name));
std::cout<<"Create client channel for '"<<name<<"'\n";
pva::ChannelRequester::shared_pointer req(new ChannelCacheEntry::CRequester(ent));
ent->channel = provider->createChannel(name, req);
if(!ent->channel)
THROW_EXCEPTION2(std::runtime_error, "Failed to createChannel");
assert(ent->channel->getChannelRequester().get()==req.get());
entries[name] = ent;
assert(entries.size()>0);
return ent;
}

View File

@ -154,10 +154,6 @@ struct ChannelCache
ChannelCache();
~ChannelCache();
// caller must host cacheLock
ChannelCacheEntry::shared_pointer get(const std::string& name);
};
#endif // CHANCACHE_H

View File

@ -68,11 +68,24 @@ struct GWServerChannelProvider : public
if(it==cache.entries.end()) {
// first request, create ChannelCacheEntry
//TODO: async lookup
cache.get(newName);
assert(cache.entries.size()>0);
ChannelCacheEntry::shared_pointer ent(new ChannelCacheEntry(&cache, newName));
} else if(it->second->channel->isConnected()) {
cache.entries[newName] = ent;
pva::Channel::shared_pointer M;
{
// unlock to call createChannel()
epicsGuardRelease<epicsMutex> U(G);
pva::ChannelRequester::shared_pointer req(new ChannelCacheEntry::CRequester(ent));
M = cache.provider->createChannel(newName, req);
if(!M)
THROW_EXCEPTION2(std::runtime_error, "Failed to createChannel");
}
ent->channel = M;
} else if(it->second->channel && it->second->channel->isConnected()) {
// another request, and hey we're connected this time
ret=this->shared_from_this();
@ -127,7 +140,8 @@ struct GWServerChannelProvider : public
Guard G(cache.cacheLock);
ChannelCache::entries_t::const_iterator it = cache.entries.find(newName);
if(it!=cache.entries.end() && it->second->channel->isConnected())
if(it!=cache.entries.end() && it->second->channel
&& it->second->channel->isConnected())
{
ret.reset(new GWChannel(it->second, channelRequester));
it->second->interested.insert(ret);