Sha256: 0e83e7e3c04c755fac9e15b4eec5a59a6e021bad8569474f98aa4f7bb7663026
Contents?: true
Size: 833 Bytes
Versions: 17
Compression:
Stored size: 833 Bytes
Contents
require 'thread' require 'set' # 同時実行抑制インターセプタ class SynchronizeInterceptor @@pool = {} @@pool_mutex = Mutex.new # コンストラクタ def initialize( point, options ) @id = options[:id] || :default @mutex = mutex( @id ) end def process( chain, context ) # 2重ロックの回避 set = Thread.current[:synchronize_interceptor_locked] ||= Set.new if set.include? @id chain.process_next( context ) else set.add( @id ) begin @mutex.synchronize { chain.process_next( context ) } ensure set.delete( @id ) end end end # IDに対応するmutexを取得する def mutex( id ) @@pool_mutex.synchronize { @@pool[id] ||= Mutex.new } end end
Version data entries
17 entries across 17 versions & 2 rubygems