From 2ab83e1abbf5ee6d00e16056a9e9394114026f28 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sat, 7 Jan 2017 18:25:37 -0300 Subject: Memory pool vectors (DVector) have been enormously simplified in code, and renamed to PoolVector --- core/object.cpp | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) (limited to 'core/object.cpp') diff --git a/core/object.cpp b/core/object.cpp index 82377013e1..0f9b112ad2 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -1112,9 +1112,9 @@ Array Object::_get_method_list_bind() const { } -DVector Object::_get_meta_list_bind() const { +PoolVector Object::_get_meta_list_bind() const { - DVector _metaret; + PoolVector _metaret; List keys; metadata.get_key_list(&keys); @@ -1942,27 +1942,37 @@ uint32_t ObjectDB::instance_counter=1; HashMap ObjectDB::instance_checks; uint32_t ObjectDB::add_instance(Object *p_object) { - GLOBAL_LOCK_FUNCTION; + ERR_FAIL_COND_V( p_object->get_instance_ID()!=0, 0 ); + + rw_lock->write_lock(); instances[++instance_counter]=p_object; #ifdef DEBUG_ENABLED instance_checks[p_object]=instance_counter; #endif + rw_lock->write_unlock(); + return instance_counter; } void ObjectDB::remove_instance(Object *p_object) { - GLOBAL_LOCK_FUNCTION; + + rw_lock->write_lock(); + instances.erase( p_object->get_instance_ID() ); #ifdef DEBUG_ENABLED instance_checks.erase(p_object); #endif + + rw_lock->write_unlock(); } Object *ObjectDB::get_instance(uint32_t p_instance_ID) { - GLOBAL_LOCK_FUNCTION; + rw_lock->read_lock(); Object**obj=instances.getptr(p_instance_ID); + rw_lock->read_unlock(); + if (!obj) return NULL; return *obj; @@ -1970,13 +1980,16 @@ Object *ObjectDB::get_instance(uint32_t p_instance_ID) { void ObjectDB::debug_objects(DebugFunc p_func) { - GLOBAL_LOCK_FUNCTION; + rw_lock->read_lock(); const uint32_t *K=NULL; while((K=instances.next(K))) { p_func(instances[*K]); } + + rw_lock->read_unlock(); + } @@ -1987,15 +2000,26 @@ void Object::get_argument_options(const StringName& p_function,int p_idx,Listread_lock(); + int count =instances.size(); + rw_lock->read_unlock(); + + return count; + +} + +RWLock *ObjectDB::rw_lock=NULL; + +void ObjectDB::setup() { + + rw_lock = RWLock::create(); } void ObjectDB::cleanup() { - GLOBAL_LOCK_FUNCTION; + rw_lock->write_lock(); if (instances.size()) { WARN_PRINT("ObjectDB Instances still exist!"); @@ -2014,4 +2038,7 @@ void ObjectDB::cleanup() { } instances.clear(); instance_checks.clear(); + rw_lock->write_unlock(); + + memdelete(rw_lock); } -- cgit v1.2.3