# A concurrent variant to the standard `Collection`
abstract class ConcurrentCollection[E]
super Collection[E]
# Type of the equivalent non thread-safe collection
type REAL: Collection[E]
# Collection wrapped by `self`
var real_collection: REAL is noinit
# `Mutex` used to synchronize access to `self`
#
# It is used by the implementation on each protected methods. It can also
# be used externally to ensure that no other `Thread` modify this object.
var mutex = new Mutex
redef fun count(e)
do
mutex.lock
var r = real_collection.count(e)
mutex.unlock
return r
end
redef fun first
do
mutex.lock
var r = real_collection.first
mutex.unlock
return r
end
redef fun has(e)
do
mutex.lock
var r = real_collection.has(e)
mutex.unlock
return r
end
redef fun has_all(e)
do
mutex.lock
var r = real_collection.has_all(e)
mutex.unlock
return r
end
redef fun has_only(e)
do
mutex.lock
var r = real_collection.has_only(e)
mutex.unlock
return r
end
redef fun is_empty
do
mutex.lock
var r = real_collection.is_empty
mutex.unlock
return r
end
redef fun iterator
do
mutex.lock
var r = real_collection.iterator
mutex.unlock
return r
end
redef fun length
do
mutex.lock
var r = real_collection.length
mutex.unlock
return r
end
redef fun to_a
do
mutex.lock
var r = real_collection.to_a
mutex.unlock
return r
end
redef fun rand
do
mutex.lock
var r = real_collection.rand
mutex.unlock
return r
end
redef fun join(sep, last_sep)
do
mutex.lock
var r = real_collection.join(sep, last_sep)
mutex.unlock
return r
end
redef fun to_s
do
mutex.lock
var r = real_collection.to_s
mutex.unlock
return r
end
end
lib/pthreads/concurrent_collections.nit:68,1--179,3