Panda3D
|
00001 // Filename: copyOnWriteObject.cxx 00002 // Created by: drose (09Apr07) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "copyOnWriteObject.h" 00016 #include "mutexHolder.h" 00017 #include "pnotify.h" 00018 00019 TypeHandle CopyOnWriteObject::_type_handle; 00020 00021 #ifdef COW_THREADED 00022 //////////////////////////////////////////////////////////////////// 00023 // Function: CopyOnWriteObject::unref 00024 // Access: Public, Virtual 00025 // Description: Explicitly decrements the reference count. See 00026 // ReferenceCount::unref(). 00027 // 00028 // In the case of a CopyOnWriteObject, when the 00029 // reference count decrements down to the cache 00030 // reference count, the object is implicitly unlocked. 00031 //////////////////////////////////////////////////////////////////// 00032 bool CopyOnWriteObject:: 00033 unref() const { 00034 MutexHolder holder(_lock_mutex); 00035 bool is_zero = CachedTypedWritableReferenceCount::unref(); 00036 if (get_ref_count() == get_cache_ref_count()) { 00037 ((CopyOnWriteObject *)this)->_lock_status = LS_unlocked; 00038 ((CopyOnWriteObject *)this)->_locking_thread = NULL; 00039 ((CopyOnWriteObject *)this)->_lock_cvar.notify(); 00040 } 00041 return is_zero; 00042 } 00043 #endif // COW_THREADED