mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
Feature #3805: Use the new document lock in the flow server
This commit is contained in:
parent
da8ccbb0f1
commit
7e0c89b0b0
@ -19,9 +19,6 @@ module OpenNebula
|
||||
|
||||
DOCUMENT_TYPE = 100
|
||||
|
||||
@@mutex = Mutex.new
|
||||
@@mutex_hash = Hash.new
|
||||
|
||||
# Class constructor
|
||||
#
|
||||
# @param [OpenNebula::Client] client the xml-rpc client
|
||||
@ -51,42 +48,33 @@ module OpenNebula
|
||||
service_id = service_id.to_i if service_id
|
||||
service = Service.new_with_id(service_id, @client)
|
||||
|
||||
rc = service.info
|
||||
if block_given?
|
||||
locked = false
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc
|
||||
while !locked
|
||||
locked = service.lock()
|
||||
|
||||
if OpenNebula.is_error?(locked)
|
||||
return locked
|
||||
end
|
||||
|
||||
sleep 1
|
||||
end
|
||||
|
||||
rc = service.info
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc
|
||||
end
|
||||
|
||||
block.call(service)
|
||||
|
||||
service.unlock()
|
||||
else
|
||||
if block_given?
|
||||
obj_mutex = nil
|
||||
entry = nil
|
||||
rc = service.info
|
||||
|
||||
@@mutex.synchronize {
|
||||
# entry is an array of [Mutex, waiting]
|
||||
# waiting is the number of threads waiting on this mutex
|
||||
entry = @@mutex_hash[service_id]
|
||||
|
||||
if entry.nil?
|
||||
entry = [Mutex.new, 0]
|
||||
@@mutex_hash[service_id] = entry
|
||||
end
|
||||
|
||||
obj_mutex = entry[0]
|
||||
entry[1] = entry[1] + 1
|
||||
|
||||
if @@mutex_hash.size > 10000
|
||||
@@mutex_hash.delete_if { |s_id, entry|
|
||||
entry[1] == 0
|
||||
}
|
||||
end
|
||||
}
|
||||
|
||||
obj_mutex.synchronize {
|
||||
block.call(service)
|
||||
}
|
||||
|
||||
@@mutex.synchronize {
|
||||
entry[1] = entry[1] - 1
|
||||
}
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc
|
||||
end
|
||||
|
||||
return service
|
||||
|
Loading…
x
Reference in New Issue
Block a user