Sha256: c150b33be50d65fd79194f21f105496c4fd6f5a586c1f4ad0f0b55bb3d4e7dde
Contents?: true
Size: 1.08 KB
Versions: 6
Compression:
Stored size: 1.08 KB
Contents
# * George Moschovitis <gm@navel.gr> # (c) 2002-2005 Navel, all rights reserved. # $Id: array.rb 1 2005-04-11 11:04:30Z 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 # 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 []=(key, value) 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 size return @sync.synchronize(Sync::SH) { super } end def shift return @sync.synchronize(::Sync::EX) { super } end def unshift(el) return @sync.synchronize(::Sync::EX) { super } end end end
Version data entries
6 entries across 6 versions & 1 rubygems
Version | Path |
---|---|
glue-0.16.0 | lib/glue/array.rb |
glue-0.17.0 | lib/glue/array.rb |
glue-0.18.0 | lib/glue/array.rb |
glue-0.18.1 | lib/glue/array.rb |
glue-0.19.0 | lib/glue/array.rb |
glue-0.20.0 | lib/glue/array.rb |