public void Shutdown() { Logging.Info("ShutdownableManager is shutting down all shutdownables:"); IsShuttingDown = true; while (true) { ShutdownDelegate shutdown_delegate = null; // Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start(); lock (shutdown_delegates_lock) { // l1_clk.LockPerfTimerStop(); if (!shutdown_delegates.Any()) { break; } shutdown_delegate = shutdown_delegates[0]; shutdown_delegates.RemoveAt(0); } try { Logging.Info("ShutdownableManager is shutting down {0}", shutdown_delegate.Target); shutdown_delegate(); } catch (Exception ex) { Logging.Error(ex, "There was a problem shutting down Shutdownable {0}", shutdown_delegate.Target); } } }
public void Shutdown() { Logging.Info("ShutdownableManager is shutting down all shutdownables:"); while (true) { ShutdownDelegate shutdown_delegate = null; lock (shutdown_delegates) { if (0 == shutdown_delegates.Count) { break; } shutdown_delegate = shutdown_delegates[0]; shutdown_delegates.RemoveAt(0); } try { Logging.Info("ShutdownableManager is shutting down {0}", shutdown_delegate.Target); shutdown_delegate(); } catch (Exception ex) { Logging.Error(ex, "There was a problem shutting down Shutdownable {0}", shutdown_delegate.Target); } } }
public void Register(ShutdownDelegate shutdown_delegate) { lock (shutdown_delegates) { Logging.Info("ShutdownableManager is registering {0}", shutdown_delegate.Target); shutdown_delegates.Add(shutdown_delegate); } }
public void Register(ShutdownDelegate shutdown_delegate) { // Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start(); lock (shutdown_delegates_lock) { // l1_clk.LockPerfTimerStop(); Logging.Info("ShutdownableManager is registering {0}", shutdown_delegate.Target); shutdown_delegates.Add(shutdown_delegate); } }
public void Shutdown(string reason) { lock (first_known_shutdown_reason_lock) { if (first_known_shutdown_reason == null) { first_known_shutdown_reason = reason; } else { reason = $"{first_known_shutdown_reason}\n Subsequent shutdown reason: {reason}"; } } Logging.Info($"ShutdownableManager is shutting down all shutdownables. Reason: {reason}"); IsShuttingDown = true; while (true) { ShutdownDelegate shutdown_delegate = null; // Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start(); lock (shutdown_delegates_lock) { // l1_clk.LockPerfTimerStop(); if (!shutdown_delegates.Any()) { break; } // process Shutdown registered items in LIFO order: shutdown in reverse of init sequence! int idx = shutdown_delegates.Count - 1; shutdown_delegate = shutdown_delegates[idx]; shutdown_delegates.RemoveAt(idx); } try { Logging.Info("ShutdownableManager is shutting down {0}", shutdown_delegate.Target); shutdown_delegate(); } catch (Exception ex) { Logging.Error(ex, "There was a problem shutting down Shutdownable {0}", shutdown_delegate.Target); } } }
/// public static bool LoadPlugin(bool force_opencl) { bool use_nvidia = SystemInfo.graphicsDeviceName.Contains("NVIDIA") || SystemInfo.graphicsDeviceName.Contains("GeForce"); function_ptrs = new IntPtr[function_names.Length]; #if (UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX) if (use_nvidia && !force_opencl) { #if (UNITY_EDITOR) handle = dlopen("Assets/Rove/ImportedPlugins/x86_64/libRoveGLCUDA.so", 2); #else handle = dlopen(Application.dataPath + "/Rove/Data/libRoveGLCUDA.so", 2); #endif if (handle == IntPtr.Zero) { Debug.LogError("Rove: Failed to get library."); string error = Marshal.PtrToStringAuto(dlerror()); Debug.LogError(error); return(false); } } else { #if (UNITY_EDITOR) handle = dlopen("Assets/Rove/ImportedPlugins/x86_64/libRoveGLCL.so", 2); #else handle = dlopen(Application.dataPath + "/Rove/Data/libRoveGLCL.so", 2); #endif if (handle == IntPtr.Zero) { Debug.LogError("Rove: Failed to get library."); string error = Marshal.PtrToStringAuto(dlerror()); Debug.LogError(error); return(false); } } for (uint fi = 1; fi < function_names.Length; ++fi) { function_ptrs[fi] = dlsym(handle, function_names[fi]); if (function_ptrs[fi] == IntPtr.Zero) { Debug.LogError("Rove: Failed to get function pointer: " + function_names[fi]); string error = Marshal.PtrToStringAuto(dlerror()); Debug.LogError(error); return(false); } } #elif (UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX) if (use_nvidia && !force_opencl) { #if (UNITY_EDITOR) handle = dlopen("Assets/Rove/ImportedPlugins/x86_64/RoveGLCUDA.bundle", 2); #else handle = dlopen(Application.dataPath + "/Rove/Data/RoveGLCUDA.bundle", 2); #endif if (handle == IntPtr.Zero) { Debug.LogError("Rove: Failed to get library."); string error = Marshal.PtrToStringAuto(dlerror()); Debug.LogError(error); return(false); } } else { #if (UNITY_EDITOR) handle = dlopen("Assets/Rove/ImportedPlugins/x86_64/RoveGLCL.bundle", 2); #else handle = dlopen(Application.dataPath + "/Rove/Data/RoveGLCL.bundle", 2); #endif if (handle == IntPtr.Zero) { Debug.LogError("Rove: Failed to get library."); string error = Marshal.PtrToStringAuto(dlerror()); Debug.LogError(error); return(false); } } for (uint fi = 1; fi < function_names.Length; ++fi) { function_ptrs[fi] = dlsym(handle, function_names[fi]); if (function_ptrs[fi] == IntPtr.Zero) { Debug.LogError("Rove: Failed to get function pointer: " + function_names[fi]); string error = Marshal.PtrToStringAuto(dlerror()); Debug.LogError(error); return(false); } } #elif (UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN) if (use_nvidia && !force_opencl) { #if (ROVE_FORCE_GL) #if (UNITY_EDITOR) handle = LoadLibrary("Assets/Rove/ImportedPlugins/x86_64/RoveGLCUDA.dll"); #else handle = LoadLibrary(Application.dataPath + "/Rove/Data/RoveGLCUDA.dll"); #endif #else #if (UNITY_EDITOR) handle = LoadLibrary("Assets/Rove/ImportedPlugins/x86_64/RoveD3D11CUDA.dll"); #else handle = LoadLibrary(Application.dataPath + "/Rove/Data/RoveD3D11CUDA.dll"); #endif #endif if (handle == IntPtr.Zero) { Debug.LogError("Rove: Failed to get library."); Debug.LogError("Error code: " + GetLastError() + "."); return(false); } } else { #if (ROVE_FORCE_GL) #if (UNITY_EDITOR) handle = LoadLibrary("Assets/Rove/ImportedPlugins/x86_64/RoveGLCL.dll"); #else handle = LoadLibrary(Application.dataPath + "/Rove/Data/RoveGLCL.dll"); #endif #else #if (UNITY_EDITOR) handle = LoadLibrary("Assets/Rove/ImportedPlugins/x86_64/RoveD3D11CL.dll"); #else handle = LoadLibrary(Application.dataPath + "/Rove/Data/RoveD3D11CL.dll"); #endif #endif if (handle == IntPtr.Zero) { Debug.LogError("Rove: Failed to get library."); Debug.LogError("Error code: " + GetLastError() + "."); return(false); } } #if (ROVE_FORCE_GL) for (uint fi = 1; fi < function_names.Length; ++fi) { #else for (uint fi = 0; fi < function_names.Length; ++fi) { #endif function_ptrs[fi] = GetProcAddress(handle, function_names[fi]); if (function_ptrs[fi] == IntPtr.Zero) { Debug.LogError("Rove: Failed to get function pointer: " + function_names[fi]); Debug.LogError("Error code: " + GetLastError() + "."); return(false); } } #endif uint i = 0; #if ((!ROVE_FORCE_GL) && (UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN)) SetD3D11Device = (SetD3D11DeviceDelegate) Marshal.GetDelegateForFunctionPointer(function_ptrs[i++], typeof(SetD3D11DeviceDelegate)); #else ++i; #endif GetLock = (GetLockDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(GetLockDelegate)); Setup = (SetupDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(SetupDelegate)); Shutdown = (ShutdownDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(ShutdownDelegate)); Resize = (ResizeDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(ResizeDelegate)); StartUpdate = (StartUpdateDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(StartUpdateDelegate)); FinishUpdate = (FinishUpdateDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(FinishUpdateDelegate)); ResetRenderAtStart = (ResetRenderAtStartDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(ResetRenderAtStartDelegate)); ResetRenderAtEnd = (ResetRenderAtEndDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(ResetRenderAtEndDelegate)); GetThreadCount = (GetThreadCountDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(GetThreadCountDelegate)); GetComputeAPI = (GetComputeAPIDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(GetComputeAPIDelegate)); GetDeviceCount = (GetDeviceCountDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(GetDeviceCountDelegate)); GetDeviceName = (GetDeviceNameDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(GetDeviceNameDelegate)); ImportMesh = (ImportMeshDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(ImportMeshDelegate)); FreeMesh = (FreeMeshDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(FreeMeshDelegate)); DefineSubMesh = (DefineSubMeshDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(DefineSubMeshDelegate)); ChangeSubMeshMaterial = (ChangeSubMeshMaterialDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(ChangeSubMeshMaterialDelegate)); SetMeshTransform = (SetMeshTransformDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(SetMeshTransformDelegate)); AddMaterial = (AddMaterialDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(AddMaterialDelegate)); SetMaterialMapFlags = (SetMaterialMapFlagsDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(SetMaterialMapFlagsDelegate)); SetMaterialDoubleSided = (SetMaterialDoubleSidedDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(SetMaterialDoubleSidedDelegate)); SetMaterialAlbedo = (SetMaterialAlbedoDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(SetMaterialAlbedoDelegate)); SetMaterialMetallic = (SetMaterialMetallicDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(SetMaterialMetallicDelegate)); SetMaterialSmoothness = (SetMaterialSmoothnessDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(SetMaterialSmoothnessDelegate)); SetMaterialGlass = (SetMaterialGlassDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(SetMaterialGlassDelegate)); SetMaterialEmission = (SetMaterialEmissionDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(SetMaterialEmissionDelegate)); SetMaterialAlbedoBounds = (SetMaterialAlbedoBoundsDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(SetMaterialAlbedoBoundsDelegate)); SetMaterialNormalBounds = (SetMaterialNormalBoundsDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(SetMaterialNormalBoundsDelegate)); SetMaterialMetallicBounds = (SetMaterialMetallicBoundsDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(SetMaterialMetallicBoundsDelegate)); SetMaterialEmissionBounds = (SetMaterialEmissionBoundsDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(SetMaterialEmissionBoundsDelegate)); SetAlbedoAtlas = (SetAlbedoAtlasDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(SetAlbedoAtlasDelegate)); SetNormalAtlas = (SetNormalAtlasDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(SetNormalAtlasDelegate)); SetMetallicAtlas = (SetMetallicAtlasDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(SetMetallicAtlasDelegate)); SetEmissionAtlas = (SetEmissionAtlasDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(SetEmissionAtlasDelegate)); SetFieldOfView = (SetFieldOfViewDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(SetFieldOfViewDelegate)); SetMaxBounces = (SetMaxBouncesDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(SetMaxBouncesDelegate)); SetSamplesPerFrame = (SetSamplesPerFrameDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(SetSamplesPerFrameDelegate)); SetImageProperties = (SetImagePropertiesDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(SetImagePropertiesDelegate)); SetCameraApertureSize = (SetCameraApertureSizeDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(SetCameraApertureSizeDelegate)); SetCameraFocalDepth = (SetCameraFocalDepthDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(SetCameraFocalDepthDelegate)); SetCameraTransform = (SetCameraTransformDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(SetCameraTransformDelegate)); SetEnvironmentType = (SetEnvironmentTypeDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(SetEnvironmentTypeDelegate)); SetSunDirection = (SetSunDirectionDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(SetSunDirectionDelegate)); SetSkyIntensity = (SetSkyIntensityDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(SetSkyIntensityDelegate)); SetSunIntensity = (SetSunIntensityDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(SetSunIntensityDelegate)); SetSunColor = (SetSunColorDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(SetSunColorDelegate)); SetEnvironmentMap = (SetEnvironmentMapDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(SetEnvironmentMapDelegate)); SetEnvironmentProperties = (SetEnvironmentPropertiesDelegate)Marshal.GetDelegateForFunctionPointer( function_ptrs[i++], typeof(SetEnvironmentPropertiesDelegate)); return(true); }