diff --git a/include/CachePool.h b/include/CachePool.h index a51e0dac68..c8530b0c13 100644 --- a/include/CachePool.h +++ b/include/CachePool.h @@ -1,3 +1,19 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2017, OpenNebula Project, OpenNebula Systems */ +/* */ +/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ +/* not use this file except in compliance with the License. You may obtain */ +/* a copy of the License at */ +/* */ +/* http://www.apache.org/licenses/LICENSE-2.0 */ +/* */ +/* Unless required by applicable law or agreed to in writing, software */ +/* distributed under the License is distributed on an "AS IS" BASIS, */ +/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ +/* See the License for the specific language governing permissions and */ +/* limitations under the License. */ +/* -------------------------------------------------------------------------- */ + #ifndef CACHE_POOL_H_ #define CACHE_POOL_H_ @@ -12,29 +28,30 @@ using namespace std; /** - * The Cache Pool class. + * The Cache Pool class. This class is used to store volatile pool data. */ template class CachePool { -private: - - pthread_mutex_t resource_lock; - - std::map resources; - public: - CachePool(){ - pthread_mutex_init(&resource_lock,0); + CachePool() + { + pthread_mutex_init(&resource_lock, 0); } ~CachePool() { typename std::map::iterator it; + pthread_mutex_lock(&resource_lock); + for (it=resources.begin(); it != resources.end() ; ++it) { delete it->second; } + + pthread_mutex_unlock(&resource_lock); + + pthread_mutex_destroy(&resource_lock); }; T * get_resource(int oid) @@ -77,6 +94,12 @@ public: pthread_mutex_unlock(&resource_lock); } + +private: + + pthread_mutex_t resource_lock; + + std::map resources; }; #endif /*CACHE_POOL_H_*/ \ No newline at end of file diff --git a/include/HostPool.h b/include/HostPool.h index 31b3ae5046..75d5f6a9c5 100644 --- a/include/HostPool.h +++ b/include/HostPool.h @@ -40,7 +40,7 @@ public: const string& hook_location, const string& remotes_location, time_t expire_time); - ~HostPool(); + ~HostPool(){}; /** * Function to allocate a new Host object @@ -320,15 +320,15 @@ private: set prev_rediscovered_vms; }; - pthread_mutex_t host_vm_lock; - CachePool cache; - HostVM * get_host_vm(int oid){ + HostVM * get_host_vm(int oid) + { return cache.get_resource(oid); } - void delete_host_vm(int oid){ + void delete_host_vm(int oid) + { cache.delete_resource(oid); } diff --git a/include/User.h b/include/User.h index 1f6892e50c..e998077727 100644 --- a/include/User.h +++ b/include/User.h @@ -224,16 +224,6 @@ public: return groups.contains(_group_id); } - /** - * Sets session token - * - * @param session_token the new session token - */ - void set_session(SessionToken * session_token) - { - session = session_token; - } - // ************************************************************************* // Quotas // ************************************************************************* @@ -381,7 +371,8 @@ protected: password(_password), auth_driver(_auth_driver), enabled(_enabled), - groups("GROUPS") + groups("GROUPS"), + session(0) { obj_template = new UserTemplate; }; diff --git a/include/UserPool.h b/include/UserPool.h index 5e10ad620f..363359ec7e 100644 --- a/include/UserPool.h +++ b/include/UserPool.h @@ -86,7 +86,7 @@ public: if ( u != 0 ) { - u->set_session(get_session_token(oid)); + u->session = get_session_token(oid); } return u; @@ -106,7 +106,7 @@ public: if ( u != 0 ) { - u->set_session(get_session_token(u->oid)); + u->session = get_session_token(u->oid); } return u; @@ -237,13 +237,15 @@ private: **/ static time_t _session_expiration_time; - CachePool cache; - SessionToken * get_session_token(int oid){ + + SessionToken * get_session_token(int oid) + { return cache.get_resource(oid); } - void delete_session_token(int oid){ + void delete_session_token(int oid) + { cache.delete_resource(oid); } diff --git a/src/host/HostPool.cc b/src/host/HostPool.cc index 31b06cb2f9..4174fc4b86 100644 --- a/src/host/HostPool.cc +++ b/src/host/HostPool.cc @@ -140,18 +140,11 @@ HostPool::HostPool(SqlDB* db, add_hook(hook); } - - pthread_mutex_init(&host_vm_lock,0); } /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -HostPool::~HostPool(){}; - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - int HostPool::allocate ( int * oid, const string& hostname, diff --git a/src/um/UserPool.cc b/src/um/UserPool.cc index aa497e25f5..01c0c89105 100644 --- a/src/um/UserPool.cc +++ b/src/um/UserPool.cc @@ -497,10 +497,8 @@ int UserPool::drop(PoolObjectSQL * objsql, string& error_msg) return -1; } - User * user = static_cast(objsql); - int oid = user->oid; - - int rc = PoolSQL::drop(objsql, error_msg); + int oid = (static_cast(objsql))->oid; + int rc = PoolSQL::drop(objsql, error_msg); if ( rc == 0 ) {