Panda3D
copyOnWriteObject.cxx
1 // Filename: copyOnWriteObject.cxx
2 // Created by: drose (09Apr07)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "copyOnWriteObject.h"
16 #include "mutexHolder.h"
17 #include "pnotify.h"
18 
19 TypeHandle CopyOnWriteObject::_type_handle;
20 
21 #ifdef COW_THREADED
22 ////////////////////////////////////////////////////////////////////
23 // Function: CopyOnWriteObject::unref
24 // Access: Public, Virtual
25 // Description: Explicitly decrements the reference count. See
26 // ReferenceCount::unref().
27 //
28 // In the case of a CopyOnWriteObject, when the
29 // reference count decrements down to the cache
30 // reference count, the object is implicitly unlocked.
31 ////////////////////////////////////////////////////////////////////
33 unref() const {
34  MutexHolder holder(_lock_mutex);
37  ((CopyOnWriteObject *)this)->_lock_status = LS_unlocked;
38  ((CopyOnWriteObject *)this)->_locking_thread = NULL;
39  ((CopyOnWriteObject *)this)->_lock_cvar.notify();
40  }
41  return is_zero;
42 }
43 #endif // COW_THREADED
A lightweight C++ object whose constructor calls acquire() and whose destructor calls release() on a ...
Definition: mutexHolder.h:29
int get_cache_ref_count() const
Returns the current reference count.
int get_ref_count() const
Returns the current reference count.
This base class provides basic reference counting, but also can be used with a CopyOnWritePointer to ...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
virtual bool unref() const
Explicitly decrements the reference count.