aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow
diff options
context:
space:
mode:
authorGravatar Peter Hawkins <phawkins@google.com>2016-12-19 18:12:46 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2016-12-19 18:25:26 -0800
commit1466d8a4f039284532998ef3020a039e38304741 (patch)
treeee4b7ee41efe3682f054786fbe2d5651e65b3a27 /tensorflow
parent79c27b9b3acee58481cc55e6b249795713b00ca8 (diff)
Fix initialization order problem for mutexes on Mac GPU opensource build.
Change: 142508618
Diffstat (limited to 'tensorflow')
-rw-r--r--tensorflow/stream_executor/cuda/cuda_driver.cc4
-rw-r--r--tensorflow/stream_executor/dso_loader.cc10
-rw-r--r--tensorflow/stream_executor/dso_loader.h1
-rw-r--r--tensorflow/stream_executor/plugin_registry.cc10
-rw-r--r--tensorflow/stream_executor/plugin_registry.h4
5 files changed, 16 insertions, 13 deletions
diff --git a/tensorflow/stream_executor/cuda/cuda_driver.cc b/tensorflow/stream_executor/cuda/cuda_driver.cc
index 8e3732d715..ac0f15b687 100644
--- a/tensorflow/stream_executor/cuda/cuda_driver.cc
+++ b/tensorflow/stream_executor/cuda/cuda_driver.cc
@@ -519,9 +519,9 @@ static port::Status InternalInit() {
// called once, but CUDADriver::Init may be called many times.
static port::Status init_retval;
static bool set = false;
- static mutex init_mu(LINKER_INITIALIZED);
+ static mutex *init_mu = new mutex;
- mutex_lock lock(init_mu);
+ mutex_lock lock(*init_mu);
if (!set) {
init_retval = InternalInit();
set = true;
diff --git a/tensorflow/stream_executor/dso_loader.cc b/tensorflow/stream_executor/dso_loader.cc
index a539c9a4ae..9aa50e976f 100644
--- a/tensorflow/stream_executor/dso_loader.cc
+++ b/tensorflow/stream_executor/dso_loader.cc
@@ -92,8 +92,13 @@ string GetCudnnVersion() { return TF_CUDNN_VERSION; }
dso_handle);
}
+static mutex& GetRpathMutex() {
+ static mutex* mu = new mutex;
+ return *mu;
+}
+
/* static */ void DsoLoader::RegisterRpath(port::StringPiece path) {
- mutex_lock lock{rpath_mutex_};
+ mutex_lock lock{GetRpathMutex()};
GetRpaths()->push_back(path.ToString());
}
@@ -138,7 +143,6 @@ static std::vector<string>* CreatePrimordialRpaths() {
return rpaths;
}
-/* static */ mutex DsoLoader::rpath_mutex_{LINKER_INITIALIZED};
/* static */ std::vector<string>* DsoLoader::GetRpaths() {
static std::vector<string>* rpaths = CreatePrimordialRpaths();
return rpaths;
@@ -172,7 +176,7 @@ static std::vector<string>* CreatePrimordialRpaths() {
// Otherwise, try binary-plus-rpath locations.
string binary_directory =
GetBinaryDirectory(true /* = strip_executable_name */);
- mutex_lock lock{rpath_mutex_};
+ mutex_lock lock{GetRpathMutex()};
for (const string& rpath : *GetRpaths()) {
candidate =
port::Join(StringPieces{binary_directory, rpath, library_name}, "/");
diff --git a/tensorflow/stream_executor/dso_loader.h b/tensorflow/stream_executor/dso_loader.h
index d8843af9b2..0c83bb2504 100644
--- a/tensorflow/stream_executor/dso_loader.h
+++ b/tensorflow/stream_executor/dso_loader.h
@@ -56,7 +56,6 @@ class DsoLoader {
private:
// Registered rpaths (singleton vector) and a mutex that guards it.
static std::vector<string>* GetRpaths();
- static mutex rpath_mutex_;
// Descriptive boolean wrapper to indicate whether symbols are made available
// to resolve in later-loaded libraries.
diff --git a/tensorflow/stream_executor/plugin_registry.cc b/tensorflow/stream_executor/plugin_registry.cc
index fba8bdeb10..54761139ea 100644
--- a/tensorflow/stream_executor/plugin_registry.cc
+++ b/tensorflow/stream_executor/plugin_registry.cc
@@ -44,13 +44,17 @@ string PluginKindString(PluginKind plugin_kind) {
PluginRegistry::DefaultFactories::DefaultFactories() :
blas(kNullPlugin), dnn(kNullPlugin), fft(kNullPlugin), rng(kNullPlugin) { }
-/* static */ mutex PluginRegistry::mu_(LINKER_INITIALIZED);
+static mutex& GetPluginRegistryMutex() {
+ static mutex* mu = new mutex;
+ return *mu;
+}
+
/* static */ PluginRegistry* PluginRegistry::instance_ = nullptr;
PluginRegistry::PluginRegistry() {}
/* static */ PluginRegistry* PluginRegistry::Instance() {
- mutex_lock lock{mu_};
+ mutex_lock lock{GetPluginRegistryMutex()};
if (instance_ == nullptr) {
instance_ = new PluginRegistry();
}
@@ -66,7 +70,7 @@ template <typename FACTORY_TYPE>
port::Status PluginRegistry::RegisterFactoryInternal(
PluginId plugin_id, const string& plugin_name, FACTORY_TYPE factory,
std::map<PluginId, FACTORY_TYPE>* factories) {
- mutex_lock lock{mu_};
+ mutex_lock lock{GetPluginRegistryMutex()};
if (factories->find(plugin_id) != factories->end()) {
return port::Status{
diff --git a/tensorflow/stream_executor/plugin_registry.h b/tensorflow/stream_executor/plugin_registry.h
index 7a02c8380b..8636a49ce6 100644
--- a/tensorflow/stream_executor/plugin_registry.h
+++ b/tensorflow/stream_executor/plugin_registry.h
@@ -138,10 +138,6 @@ class PluginRegistry {
bool HasFactory(const PluginFactories& factories, PluginKind plugin_kind,
PluginId plugin) const;
- // As this object is a singleton, a global mutex can be used for static and
- // instance protection.
- static mutex mu_;
-
// The singleton itself.
static PluginRegistry* instance_;