pvaClientChannel.cpp fix possible race conditions; pvaClientNTMultiData.cpp fix bug if not all channels connect

This commit is contained in:
mrkraimer
2016-03-29 06:39:43 -04:00
parent ec1f6d5eb6
commit c55bf7ec45
2 changed files with 35 additions and 26 deletions

View File

@@ -170,12 +170,16 @@ PvaClientChannel::~PvaClientChannel()
void PvaClientChannel::channelCreated(const Status& status, Channel::shared_pointer const & channel)
{
Lock xx(mutex);
if(isDestroyed) throw std::runtime_error("pvaClientChannel was destroyed");
if(status.isOK()) {
this->channel = channel;
if(channel->isConnected()) {
bool waitingForConnect = false;
if(connectState==connectActive) waitingForConnect = true;
connectState = connected;
channelConnectStatus = Status::Ok;
if(waitingForConnect) waitForConnect.signal();
}
return;
}
@@ -258,15 +262,18 @@ void PvaClientChannel::connect(double timeout)
void PvaClientChannel::issueConnect()
{
if(isDestroyed) throw std::runtime_error("pvaClientChannel was destroyed");
if(connectState!=connectIdle) {
throw std::runtime_error("pvaClientChannel already connected");
}
{
Lock xx(mutex);
if(isDestroyed) throw std::runtime_error("pvaClientChannel was destroyed");
if(connectState!=connectIdle) {
throw std::runtime_error("pvaClientChannel already connected");
}
channelConnectStatus = Status(
Status::STATUSTYPE_ERROR,
getChannelName() + " createChannel failed");
connectState = connectActive;
channelConnectStatus = Status(
Status::STATUSTYPE_ERROR,
getChannelName() + " createChannel failed");
connectState = connectActive;
}
ChannelProviderRegistry::shared_pointer reg = getChannelProviderRegistry();
ChannelProvider::shared_pointer provider = reg->getProvider(providerName);
if(!provider) {
@@ -281,8 +288,11 @@ void PvaClientChannel::issueConnect()
Status PvaClientChannel::waitConnect(double timeout)
{
if(isDestroyed) throw std::runtime_error("pvaClientChannel was destroyed");
if(channel->isConnected()) return Status::Ok;
{
Lock xx(mutex);
if(isDestroyed) throw std::runtime_error("pvaClientChannel was destroyed");
if(channel->isConnected()) return Status::Ok;
}
waitForConnect.wait(timeout);
return channelConnectStatus;
}