1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-12 08:58:17 +03:00

B: Prevents race condition when updating host monitoring

Signed-off-by: Ruben S. Montero <rsmontero@opennebula.org>
(cherry picked from commit 9246e2ff036d17380152df86974efc13ee9dfc6c)
This commit is contained in:
Ruben S. Montero 2017-09-27 21:02:21 +00:00
parent 68139ea586
commit 58dd54079b
2 changed files with 12 additions and 0 deletions

View File

@ -318,6 +318,8 @@ private:
set<int> prev_rediscovered_vms;
};
pthread_mutex_t host_vm_lock;
map<int, HostVM *> host_vms;
HostVM * get_host_vm(int oid);

View File

@ -140,6 +140,8 @@ HostPool::HostPool(SqlDB* db,
add_hook(hook);
}
pthread_mutex_init(&host_vm_lock,0);
}
/* -------------------------------------------------------------------------- */
@ -343,6 +345,8 @@ HostPool::HostVM * HostPool::get_host_vm(int oid)
{
HostVM * hvm;
pthread_mutex_lock(&host_vm_lock);
map<int, HostVM *>::iterator it = host_vms.find(oid);
if ( it == host_vms.end() )
@ -356,11 +360,15 @@ HostPool::HostVM * HostPool::get_host_vm(int oid)
hvm = it->second;
}
pthread_mutex_unlock(&host_vm_lock);
return hvm;
}
void HostPool::delete_host_vm(int oid)
{
pthread_mutex_lock(&host_vm_lock);
map<int, HostVM *>::iterator it = host_vms.find(oid);
if ( it != host_vms.end() )
@ -369,5 +377,7 @@ void HostPool::delete_host_vm(int oid)
host_vms.erase(it);
}
pthread_mutex_unlock(&host_vm_lock);
}