lib/glue/array.rb in glue-0.20.0 vs lib/glue/array.rb in glue-0.21.0

- old
+ new

@@ -1,61 +1,61 @@ # * George Moschovitis <gm@navel.gr> # (c) 2002-2005 Navel, all rights reserved. -# $Id: array.rb 1 2005-04-11 11:04:30Z gmosx $ +# $Id: array.rb 182 2005-07-22 10:07:50Z gmosx $ require 'sync' module Glue # A thread-safe array. We use a sync object instead of a # mutex, because it is re-entrant. An exclusive lock is # needed when writing, a shared lock IS NEEDED when reading. class SafeArray < Array - - attr :sync + + attr :sync - # gmosx: delegator is not used. - - def initialize(delegator = nil) - @sync = Sync.new() - end + # gmosx: delegator is not used. + + def initialize(delegator = nil) + @sync = Sync.new() + end - def << (value) - return @sync.synchronize(Sync::SH) { super } - end - - def delete_if(&block) - return @sync.synchronize(Sync::SH) { super } - end - - def [](key) - return @sync.synchronize(Sync::SH) { super } - end + def << (value) + return @sync.synchronize(Sync::SH) { super } + end + + def delete_if(&block) + return @sync.synchronize(Sync::SH) { super } + end + + def [](key) + return @sync.synchronize(Sync::SH) { super } + end - def []=(key, value) - return @sync.synchronize(Sync::EX) { super } - end + def []=(key, value) + return @sync.synchronize(Sync::EX) { super } + end - def delete(key) - return @sync.synchronize(Sync::EX) { super } - end + def delete(key) + return @sync.synchronize(Sync::EX) { super } + end - def clear - @sync.synchronize(Sync::EX) { super } - end + def clear + @sync.synchronize(Sync::EX) { super } + end - def size - return @sync.synchronize(Sync::SH) { super } - end + def size + return @sync.synchronize(Sync::SH) { super } + end - def shift - return @sync.synchronize(::Sync::EX) { super } - end + def shift + return @sync.synchronize(::Sync::EX) { super } + end - def unshift(el) - return @sync.synchronize(::Sync::EX) { super } - end - + def unshift(el) + return @sync.synchronize(::Sync::EX) { super } + end + end end