diff options
Diffstat (limited to 'core/rid.h')
-rw-r--r-- | core/rid.h | 76 |
1 files changed, 38 insertions, 38 deletions
diff --git a/core/rid.h b/core/rid.h index 85ae1b15d3..2de6956096 100644 --- a/core/rid.h +++ b/core/rid.h @@ -44,19 +44,19 @@ class RID_OwnerBase; typedef uint32_t ID; -class RID { -friend class RID_OwnerBase; +class RID { +friend class RID_OwnerBase; ID _id; RID_OwnerBase *owner; public: _FORCE_INLINE_ ID get_id() const { return _id; } bool operator==(const RID& p_rid) const { - + return _id==p_rid._id; } _FORCE_INLINE_ bool operator<(const RID& p_rid) const { - + return _id < p_rid._id; } _FORCE_INLINE_ bool operator<=(const RID& p_rid) const { @@ -64,11 +64,11 @@ public: return _id <= p_rid._id; } _FORCE_INLINE_ bool operator>(const RID& p_rid) const { - + return _id > p_rid._id; } bool operator!=(const RID& p_rid) const { - + return _id!=p_rid._id; } _FORCE_INLINE_ bool is_valid() const { return _id>0; } @@ -91,7 +91,7 @@ friend class RID; void set_ownage(RID& p_rid) const { p_rid.owner=const_cast<RID_OwnerBase*>(this); } ID new_ID(); public: - + virtual bool owns(const RID& p_rid) const=0; virtual void get_owned_list(List<RID> *p_owned) const=0; @@ -105,67 +105,67 @@ class RID_Owner : public RID_OwnerBase { public: typedef void (*ReleaseNotifyFunc)(void*user,T *p_data); -private: +private: Mutex *mutex; mutable HashMap<ID,T*> id_map; - + public: RID make_rid(T * p_data) { - + if (thread_safe) { mutex->lock(); } - + ID id = new_ID(); id_map[id]=p_data; RID rid; set_id(rid,id); set_ownage(rid); - + if (thread_safe) { mutex->unlock(); } - + return rid; } - + _FORCE_INLINE_ T * get(const RID& p_rid) { - + if (thread_safe) { mutex->lock(); } - + T**elem = id_map.getptr(p_rid.get_id()); - + if (thread_safe) { mutex->unlock(); } ERR_FAIL_COND_V(!elem,NULL); - + return *elem; } - + virtual bool owns(const RID& p_rid) const { - + if (thread_safe) { mutex->lock(); } - + T**elem = id_map.getptr(p_rid.get_id()); - + if (thread_safe) { mutex->lock(); } - + return elem!=NULL; } - - virtual void free(RID p_rid) { - + + virtual void free(RID p_rid) { + if (thread_safe) { mutex->lock(); } @@ -173,40 +173,40 @@ public: id_map.erase(p_rid.get_id()); } virtual void get_owned_list(List<RID> *p_owned) const { - + if (thread_safe) { mutex->lock(); } - + const ID*id=NULL; while((id=id_map.next(id))) { - + RID rid; set_id(rid,*id); set_ownage(rid); p_owned->push_back(rid); - + } - + if (thread_safe) { mutex->lock(); } } RID_Owner() { - + if (thread_safe) { - + mutex = Mutex::create(); } - + } - - + + ~RID_Owner() { - + if (thread_safe) { - + memdelete(mutex); } } |