Changeset 13041 for OpenSceneGraph/trunk/include/osg/Referenced
- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/include/osg/Referenced (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/include/osg/Referenced
r12897 r13041 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 2 2 * 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 46 46 47 47 48 Referenced(); 49 50 explicit Referenced(bool threadSafeRefUnref); 48 Referenced(); 49 50 explicit Referenced(bool threadSafeRefUnref); 51 51 52 52 Referenced(const Referenced&); … … 75 75 static OpenThreads::Mutex* getGlobalReferencedMutex(); 76 76 77 /** Increment the reference count by one, indicating that 77 /** Increment the reference count by one, indicating that 78 78 this object has another pointer which is referencing it.*/ 79 79 inline int ref() const; 80 81 /** Decrement the reference count by one, indicating that 80 81 /** Decrement the reference count by one, indicating that 82 82 a pointer to this object is no longer referencing it. If the 83 83 reference count goes to zero, it is assumed that this object 84 84 is no longer referenced and is automatically deleted.*/ 85 85 inline int unref() const; 86 87 /** Decrement the reference count by one, indicating that 86 87 /** Decrement the reference count by one, indicating that 88 88 a pointer to this object is no longer referencing it. However, do 89 not delete it, even if ref count goes to 0. Warning, unref_nodelete() 89 not delete it, even if ref count goes to 0. Warning, unref_nodelete() 90 90 should only be called if the user knows exactly who will 91 be responsible for, one should prefer unref() over unref_nodelete() 91 be responsible for, one should prefer unref() over unref_nodelete() 92 92 as the latter can lead to memory leaks.*/ 93 93 int unref_nodelete() const; 94 94 95 95 /** Return the number of pointers currently referencing this object. */ 96 96 inline int referenceCount() const { return _refCount; } … … 120 120 /** Set whether reference counting should use a mutex for thread safe reference counting.*/ 121 121 static void setThreadSafeReferenceCounting(bool enableThreadSafeReferenceCounting); 122 122 123 123 /** Get whether reference counting is active.*/ 124 124 static bool getThreadSafeReferenceCounting(); … … 133 133 static DeleteHandler* getDeleteHandler(); 134 134 135 135 136 136 protected: 137 137 138 138 virtual ~Referenced(); 139 139 … … 147 147 mutable OpenThreads::Atomic _refCount; 148 148 #else 149 149 150 150 mutable OpenThreads::Mutex* _refMutex; 151 151 152 152 mutable int _refCount; 153 153 154 154 mutable void* _observerSet; 155 155 #endif … … 163 163 if (_refMutex) 164 164 { 165 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(*_refMutex); 165 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(*_refMutex); 166 166 return ++_refCount; 167 167 } … … 183 183 if (_refMutex) 184 184 { 185 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(*_refMutex); 185 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(*_refMutex); 186 186 newRef = --_refCount; 187 187 needDelete = newRef==0;
