lib/cosmos/system/system.rb in cosmos-3.3.0 vs lib/cosmos/system/system.rb in cosmos-3.3.1

- old
+ new

@@ -60,20 +60,20 @@ KNOWN_PORTS = ['CTS_API', 'TLMVIEWER_API', 'CTS_PREIDENTIFIED'] # Known COSMOS paths KNOWN_PATHS = ['LOGS', 'TMP', 'SAVED_CONFIG', 'TABLES', 'HANDBOOKS', 'PROCEDURES'] @@instance = nil + @@instance_mutex = Mutex.new # Create a new System object. Note, this should not be called directly but # you should instead use System.instance and treat this class as a # singleton. # # @param filename [String] Full path to the system configuration file to # read. Be default this is <Cosmos::USERPATH>/config/system/system.txt def initialize(filename = nil) raise "Cosmos::System created twice" unless @@instance.nil? - @@instance = self @targets = {} @targets['UNKNOWN'] = Target.new('UNKNOWN') @config = nil @commands = nil @telemetry = nil @@ -113,10 +113,11 @@ process_file(filename) ENV['COSMOS_LOGS_DIR'] = @paths['LOGS'] @initial_filename = filename @initial_config = nil + @@instance = self end # @return [String] Configuration name def self.configuration_name # In order not to make the @config instance variable accessable to the @@ -192,11 +193,14 @@ self.instance.limits_set = limits_set end # @return [System] The System singleton def self.instance(filename = nil) - @@instance ||= self.new(filename) - return @@instance + return @@instance if @@instance + @@instance_mutex.synchronize do + @@instance ||= self.new(filename) + return @@instance + end end # Process the system.txt configuration file # # @param filename [String] The configuration file