Skip to content

Commit

Permalink
Fix usage of Mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
flash-gordon committed May 7, 2016
1 parent 29d83be commit a4ad9c8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
13 changes: 9 additions & 4 deletions lib/hanami/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ def middleware
end

class << self
# @since 0.8.0
# @api private
@@mutex = Mutex.new

# @since 0.2.0
# @api private
@@applications = Set.new

# Registry of Hanami applications in the current Ruby process
#
Expand All @@ -130,9 +137,7 @@ class << self
# @since 0.2.0
# @api private
def applications
synchronize do
@@applications ||= Set.new
end
@@applications
end

# Configure the application.
Expand Down Expand Up @@ -238,7 +243,7 @@ def preload_applications!
# @since 0.2.0
# @api private
def synchronize
Mutex.new.synchronize do
@@mutex.synchronize do
yield
end
end
Expand Down
6 changes: 4 additions & 2 deletions lib/hanami/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@ def hanami_app?(app)
end
end

@@mutex = Mutex.new

attr_reader :routes

def self.configure(options = {}, &blk)
Mutex.new.synchronize do
@@mutex.synchronize do
@@options = options
@@configuration = blk
end
end

def initialize
Mutex.new.synchronize do
@@mutex.synchronize do
assert_configuration_presence!
prepare_middleware_stack!
end
Expand Down
9 changes: 7 additions & 2 deletions lib/hanami/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ module Hanami
# @since 0.1.0
# @api private
class Environment
# Global lock (used to serialize process of environment configuration)
#
# @since 0.8.0
# @api private
@@mutex = Mutex.new

# Standard Rack ENV key
#
# @since 0.1.0
Expand Down Expand Up @@ -192,8 +198,7 @@ class Environment
def initialize(options = {})
@options = Hanami::Hanamirc.new(root).options
@options.merge! Utils::Hash.new(options.clone).symbolize!
@mutex = Mutex.new
@mutex.synchronize { set_env_vars! }
@@mutex.synchronize { set_env_vars! }
end

# The current environment
Expand Down
5 changes: 2 additions & 3 deletions lib/hanami/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@ module Hanami
# @since 0.1.0
# @api private
class Loader
@@mutex = Mutex.new

STRICT_TRANSPORT_SECURITY_HEADER = 'Strict-Transport-Security'.freeze
STRICT_TRANSPORT_SECURITY_DEFAULT_VALUE = 'max-age=31536000'.freeze

def initialize(application)
@application = application
@configuration = @application.configuration

@mutex = Mutex.new
end

def load!
@mutex.synchronize do
@@mutex.synchronize do
load_configuration!
configure_frameworks!
load_configuration_load_paths!
Expand Down

0 comments on commit a4ad9c8

Please sign in to comment.