[Bf-blender-cvs] [4782000fd5b] master: Cycles: Fix possible race condition when initializing devices list

Sergey Sharybin noreply at git.blender.org
Wed Oct 11 09:54:13 CEST 2017


Commit: 4782000fd5b2a1ae3041884f64ab192dbcb853c0
Author: Sergey Sharybin
Date:   Wed Oct 11 12:48:19 2017 +0500
Branches: master
https://developer.blender.org/rB4782000fd5b2a1ae3041884f64ab192dbcb853c0

Cycles: Fix possible race condition when initializing devices list

===================================================================

M	intern/cycles/device/device.cpp
M	intern/cycles/device/device.h

===================================================================

diff --git a/intern/cycles/device/device.cpp b/intern/cycles/device/device.cpp
index e5a1aa610b6..7b0875965f8 100644
--- a/intern/cycles/device/device.cpp
+++ b/intern/cycles/device/device.cpp
@@ -34,6 +34,7 @@ CCL_NAMESPACE_BEGIN
 
 bool Device::need_types_update = true;
 bool Device::need_devices_update = true;
+thread_mutex Device::device_mutex;
 vector<DeviceType> Device::types;
 vector<DeviceInfo> Device::devices;
 
@@ -296,54 +297,49 @@ string Device::string_from_type(DeviceType type)
 
 vector<DeviceType>& Device::available_types()
 {
+	thread_scoped_lock lock(device_mutex);
 	if(need_types_update) {
 		types.clear();
 		types.push_back(DEVICE_CPU);
-
 #ifdef WITH_CUDA
-		if(device_cuda_init())
+		if(device_cuda_init()) {
 			types.push_back(DEVICE_CUDA);
+		}
 #endif
-
 #ifdef WITH_OPENCL
-		if(device_opencl_init())
+		if(device_opencl_init()) {
 			types.push_back(DEVICE_OPENCL);
+		}
 #endif
-
 #ifdef WITH_NETWORK
 		types.push_back(DEVICE_NETWORK);
 #endif
-
 		need_types_update = false;
 	}
-
 	return types;
 }
 
 vector<DeviceInfo>& Device::available_devices()
 {
+	thread_scoped_lock lock(device_mutex);
 	if(need_devices_update) {
 		devices.clear();
-
 #ifdef WITH_OPENCL
-		if(device_opencl_init())
+		if(device_opencl_init()) {
 			device_opencl_info(devices);
+		}
 #endif
-
 #ifdef WITH_CUDA
-		if(device_cuda_init())
+		if(device_cuda_init()) {
 			device_cuda_info(devices);
+		}
 #endif
-
 		device_cpu_info(devices);
-
 #ifdef WITH_NETWORK
 		device_network_info(devices);
 #endif
-
 		need_devices_update = false;
 	}
-
 	return devices;
 }
 
diff --git a/intern/cycles/device/device.h b/intern/cycles/device/device.h
index c134fc9411e..5cd9cf46769 100644
--- a/intern/cycles/device/device.h
+++ b/intern/cycles/device/device.h
@@ -354,6 +354,7 @@ public:
 private:
 	/* Indicted whether device types and devices lists were initialized. */
 	static bool need_types_update, need_devices_update;
+	static thread_mutex device_mutex;
 	static vector<DeviceType> types;
 	static vector<DeviceInfo> devices;
 };



More information about the Bf-blender-cvs mailing list