THRIFT-3038 Fix a couple races and removed volatile per analysis, replacing with atomics
This close #981
diff --git a/lib/cpp/src/thrift/server/TThreadPoolServer.cpp b/lib/cpp/src/thrift/server/TThreadPoolServer.cpp
index efd7c23..b81a522 100644
--- a/lib/cpp/src/thrift/server/TThreadPoolServer.cpp
+++ b/lib/cpp/src/thrift/server/TThreadPoolServer.cpp
@@ -69,7 +69,6 @@
inputProtocolFactory,
outputProtocolFactory),
threadManager_(threadManager),
- stop_(false),
timeout_(0),
taskExpiration_(0) {
}
@@ -88,7 +87,6 @@
inputProtocolFactory,
outputProtocolFactory),
threadManager_(threadManager),
- stop_(false),
timeout_(0),
taskExpiration_(0) {
}
@@ -117,17 +115,18 @@
taskExpiration_ = value;
}
-boost::shared_ptr<apache::thrift::concurrency::ThreadManager> TThreadPoolServer::getThreadManager()
- const {
+boost::shared_ptr<apache::thrift::concurrency::ThreadManager>
+TThreadPoolServer::getThreadManager() const {
return threadManager_;
}
void TThreadPoolServer::onClientConnected(const shared_ptr<TConnectedClient>& pClient) {
- threadManager_->add(pClient, timeout_, taskExpiration_);
+ threadManager_->add(pClient, getTimeout(), getTaskExpiration());
}
void TThreadPoolServer::onClientDisconnected(TConnectedClient*) {
}
+
}
}
} // apache::thrift::server
diff --git a/lib/cpp/src/thrift/server/TThreadPoolServer.h b/lib/cpp/src/thrift/server/TThreadPoolServer.h
index 189d7e9..c750b8c 100644
--- a/lib/cpp/src/thrift/server/TThreadPoolServer.h
+++ b/lib/cpp/src/thrift/server/TThreadPoolServer.h
@@ -20,6 +20,7 @@
#ifndef _THRIFT_SERVER_TTHREADPOOLSERVER_H_
#define _THRIFT_SERVER_TTHREADPOOLSERVER_H_ 1
+#include <boost/atomic.hpp>
#include <thrift/concurrency/ThreadManager.h>
#include <thrift/server/TServerFramework.h>
@@ -89,13 +90,10 @@
virtual void onClientDisconnected(TConnectedClient* pClient) /* override */;
boost::shared_ptr<apache::thrift::concurrency::ThreadManager> threadManager_;
-
- volatile bool stop_;
-
- volatile int64_t timeout_;
-
- volatile int64_t taskExpiration_;
+ boost::atomic<int64_t> timeout_;
+ boost::atomic<int64_t> taskExpiration_;
};
+
}
}
} // apache::thrift::server
diff --git a/lib/cpp/src/thrift/transport/TFileTransport.h b/lib/cpp/src/thrift/transport/TFileTransport.h
index acd7bf9..d7fa556 100644
--- a/lib/cpp/src/thrift/transport/TFileTransport.h
+++ b/lib/cpp/src/thrift/transport/TFileTransport.h
@@ -27,6 +27,7 @@
#include <string>
#include <stdio.h>
+#include <boost/atomic.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/shared_ptr.hpp>
@@ -352,7 +353,7 @@
// To keep track of whether the buffer has been flushed
Monitor flushed_;
- volatile bool forceFlush_;
+ boost::atomic<bool> forceFlush_;
// Mutex that is grabbed when enqueueing and swapping the read/write buffers
Mutex mutex_;
@@ -438,3 +439,4 @@
} // apache::thrift::transport
#endif // _THRIFT_TRANSPORT_TFILETRANSPORT_H_
+