mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-30 00:32:57 -04:00
Remove unused ThreadSafePointerTo class
It seems that this was created when regular PointerTo was not yet atomic, and never used or updated.
This commit is contained in:
parent
662f28813a
commit
9e1b40bbb7
@ -2147,7 +2147,6 @@
|
|||||||
<File RelativePath="..\panda\src\express\test_types.cxx"></File>
|
<File RelativePath="..\panda\src\express\test_types.cxx"></File>
|
||||||
<File RelativePath="..\panda\src\express\weakPointerTo.I"></File>
|
<File RelativePath="..\panda\src\express\weakPointerTo.I"></File>
|
||||||
<File RelativePath="..\panda\src\express\pta_int.cxx"></File>
|
<File RelativePath="..\panda\src\express\pta_int.cxx"></File>
|
||||||
<File RelativePath="..\panda\src\express\threadSafePointerToBase.I"></File>
|
|
||||||
<File RelativePath="..\panda\src\express\namable.I"></File>
|
<File RelativePath="..\panda\src\express\namable.I"></File>
|
||||||
<File RelativePath="..\panda\src\express\vector_float.cxx"></File>
|
<File RelativePath="..\panda\src\express\vector_float.cxx"></File>
|
||||||
<File RelativePath="..\panda\src\express\pointerTo.h"></File>
|
<File RelativePath="..\panda\src\express\pointerTo.h"></File>
|
||||||
@ -2174,7 +2173,6 @@
|
|||||||
<File RelativePath="..\panda\src\express\datagramGenerator.h"></File>
|
<File RelativePath="..\panda\src\express\datagramGenerator.h"></File>
|
||||||
<File RelativePath="..\panda\src\express\weakPointerToVoid.h"></File>
|
<File RelativePath="..\panda\src\express\weakPointerToVoid.h"></File>
|
||||||
<File RelativePath="..\panda\src\express\datagram.I"></File>
|
<File RelativePath="..\panda\src\express\datagram.I"></File>
|
||||||
<File RelativePath="..\panda\src\express\threadSafePointerTo.h"></File>
|
|
||||||
<File RelativePath="..\panda\src\express\weakPointerCallback.h"></File>
|
<File RelativePath="..\panda\src\express\weakPointerCallback.h"></File>
|
||||||
<File RelativePath="..\panda\src\express\datagram.h"></File>
|
<File RelativePath="..\panda\src\express\datagram.h"></File>
|
||||||
<File RelativePath="..\panda\src\express\textEncoder.h"></File>
|
<File RelativePath="..\panda\src\express\textEncoder.h"></File>
|
||||||
@ -2215,7 +2213,6 @@
|
|||||||
<File RelativePath="..\panda\src\express\datagramIterator.I"></File>
|
<File RelativePath="..\panda\src\express\datagramIterator.I"></File>
|
||||||
<File RelativePath="..\panda\src\express\vector_uchar.h"></File>
|
<File RelativePath="..\panda\src\express\vector_uchar.h"></File>
|
||||||
<File RelativePath="..\panda\src\express\datagramIterator.h"></File>
|
<File RelativePath="..\panda\src\express\datagramIterator.h"></File>
|
||||||
<File RelativePath="..\panda\src\express\threadSafePointerTo.cxx"></File>
|
|
||||||
<File RelativePath="..\panda\src\express\datagramGenerator.cxx"></File>
|
<File RelativePath="..\panda\src\express\datagramGenerator.cxx"></File>
|
||||||
<File RelativePath="..\panda\src\express\hashGeneratorBase.h"></File>
|
<File RelativePath="..\panda\src\express\hashGeneratorBase.h"></File>
|
||||||
<File RelativePath="..\panda\src\express\patchfile.cxx"></File>
|
<File RelativePath="..\panda\src\express\patchfile.cxx"></File>
|
||||||
@ -2259,7 +2256,6 @@
|
|||||||
<File RelativePath="..\panda\src\express\namable.cxx"></File>
|
<File RelativePath="..\panda\src\express\namable.cxx"></File>
|
||||||
<File RelativePath="..\panda\src\express\trueClock.I"></File>
|
<File RelativePath="..\panda\src\express\trueClock.I"></File>
|
||||||
<File RelativePath="..\panda\src\express\config_express.cxx"></File>
|
<File RelativePath="..\panda\src\express\config_express.cxx"></File>
|
||||||
<File RelativePath="..\panda\src\express\threadSafePointerToBase.cxx"></File>
|
|
||||||
<File RelativePath="..\panda\src\express\pointerToVoid.I"></File>
|
<File RelativePath="..\panda\src\express\pointerToVoid.I"></File>
|
||||||
<File RelativePath="..\panda\src\express\vector_uchar.cxx"></File>
|
<File RelativePath="..\panda\src\express\vector_uchar.cxx"></File>
|
||||||
<File RelativePath="..\panda\src\express\vector_float.h"></File>
|
<File RelativePath="..\panda\src\express\vector_float.h"></File>
|
||||||
@ -2286,7 +2282,6 @@
|
|||||||
<File RelativePath="..\panda\src\express\datagramGenerator.I"></File>
|
<File RelativePath="..\panda\src\express\datagramGenerator.I"></File>
|
||||||
<File RelativePath="..\panda\src\express\compress_string.cxx"></File>
|
<File RelativePath="..\panda\src\express\compress_string.cxx"></File>
|
||||||
<File RelativePath="..\panda\src\express\subStreamBuf.cxx"></File>
|
<File RelativePath="..\panda\src\express\subStreamBuf.cxx"></File>
|
||||||
<File RelativePath="..\panda\src\express\threadSafePointerToBase.h"></File>
|
|
||||||
<File RelativePath="..\panda\src\express\pointerToArrayBase.cxx"></File>
|
<File RelativePath="..\panda\src\express\pointerToArrayBase.cxx"></File>
|
||||||
<File RelativePath="..\panda\src\express\express_composite.cxx"></File>
|
<File RelativePath="..\panda\src\express\express_composite.cxx"></File>
|
||||||
<File RelativePath="..\panda\src\express\virtualFileComposite.I"></File>
|
<File RelativePath="..\panda\src\express\virtualFileComposite.I"></File>
|
||||||
@ -2294,7 +2289,6 @@
|
|||||||
<File RelativePath="..\panda\src\express\multifile.I"></File>
|
<File RelativePath="..\panda\src\express\multifile.I"></File>
|
||||||
<File RelativePath="..\panda\src\express\virtualFile.I"></File>
|
<File RelativePath="..\panda\src\express\virtualFile.I"></File>
|
||||||
<File RelativePath="..\panda\src\express\patchfile.I"></File>
|
<File RelativePath="..\panda\src\express\patchfile.I"></File>
|
||||||
<File RelativePath="..\panda\src\express\threadSafePointerTo.I"></File>
|
|
||||||
<File RelativePath="..\panda\src\express\virtualFileList.h"></File>
|
<File RelativePath="..\panda\src\express\virtualFileList.h"></File>
|
||||||
</Filter>
|
</Filter>
|
||||||
<Filter Name="iphonedisplay">
|
<Filter Name="iphonedisplay">
|
||||||
|
@ -8,8 +8,6 @@
|
|||||||
#include "subStream.cxx"
|
#include "subStream.cxx"
|
||||||
#include "subStreamBuf.cxx"
|
#include "subStreamBuf.cxx"
|
||||||
#include "temporaryFile.cxx"
|
#include "temporaryFile.cxx"
|
||||||
#include "threadSafePointerTo.cxx"
|
|
||||||
#include "threadSafePointerToBase.cxx"
|
|
||||||
#include "trueClock.cxx"
|
#include "trueClock.cxx"
|
||||||
#include "typedReferenceCount.cxx"
|
#include "typedReferenceCount.cxx"
|
||||||
#include "virtualFile.cxx"
|
#include "virtualFile.cxx"
|
||||||
|
@ -1,207 +0,0 @@
|
|||||||
/**
|
|
||||||
* PANDA 3D SOFTWARE
|
|
||||||
* Copyright (c) Carnegie Mellon University. All rights reserved.
|
|
||||||
*
|
|
||||||
* All use of this software is subject to the terms of the revised BSD
|
|
||||||
* license. You should have received a copy of this license along
|
|
||||||
* with this source code in a file named "LICENSE."
|
|
||||||
*
|
|
||||||
* @file threadSafePointerTo.I
|
|
||||||
* @author drose
|
|
||||||
* @date 2006-04-28
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
template<class T>
|
|
||||||
INLINE ThreadSafePointerTo<T>::
|
|
||||||
ThreadSafePointerTo(To *ptr) : ThreadSafePointerToBase<T>(ptr) {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
template<class T>
|
|
||||||
INLINE ThreadSafePointerTo<T>::
|
|
||||||
ThreadSafePointerTo(const ThreadSafePointerTo<T> ©) :
|
|
||||||
ThreadSafePointerToBase<T>((const ThreadSafePointerToBase<T> &)copy)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
template<class T>
|
|
||||||
INLINE ThreadSafePointerTo<T>::
|
|
||||||
~ThreadSafePointerTo() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
template<class T>
|
|
||||||
INLINE typename ThreadSafePointerTo<T>::To &ThreadSafePointerTo<T>::
|
|
||||||
operator *() const {
|
|
||||||
return *((To *)AtomicAdjust::get_ptr(this->_void_ptr));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
template<class T>
|
|
||||||
INLINE typename ThreadSafePointerTo<T>::To *ThreadSafePointerTo<T>::
|
|
||||||
operator -> () const {
|
|
||||||
return (To *)AtomicAdjust::get_ptr(this->_void_ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* We also have the typecast operator to automatically convert
|
|
||||||
* ThreadSafePointerTo's to the required kind of actual pointer. This
|
|
||||||
* introduces ambiguities which the compiler will resolve one way or the
|
|
||||||
* other, but we don't care which way it goes because either will be correct.
|
|
||||||
*/
|
|
||||||
template<class T>
|
|
||||||
INLINE ThreadSafePointerTo<T>::
|
|
||||||
operator T * () const {
|
|
||||||
return (To *)AtomicAdjust::get_ptr(this->_void_ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns an ordinary pointer instead of a ThreadSafePointerTo. Useful to
|
|
||||||
* work around compiler problems, particularly for implicit upcasts.
|
|
||||||
*/
|
|
||||||
template<class T>
|
|
||||||
INLINE typename ThreadSafePointerTo<T>::To *ThreadSafePointerTo<T>::
|
|
||||||
p() const {
|
|
||||||
return (To *)AtomicAdjust::get_ptr(this->_void_ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
template<class T>
|
|
||||||
INLINE ThreadSafePointerTo<T> &ThreadSafePointerTo<T>::
|
|
||||||
operator = (To *ptr) {
|
|
||||||
this->reassign(ptr);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
template<class T>
|
|
||||||
INLINE ThreadSafePointerTo<T> &ThreadSafePointerTo<T>::
|
|
||||||
operator = (const ThreadSafePointerTo<T> ©) {
|
|
||||||
this->reassign((const ThreadSafePointerToBase<T> &)copy);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
template<class T>
|
|
||||||
INLINE ThreadSafeConstPointerTo<T>::
|
|
||||||
ThreadSafeConstPointerTo(const typename ThreadSafeConstPointerTo<T>::To *ptr) :
|
|
||||||
ThreadSafePointerToBase<T>((typename ThreadSafeConstPointerTo<T>::To *)ptr)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
template<class T>
|
|
||||||
INLINE ThreadSafeConstPointerTo<T>::
|
|
||||||
ThreadSafeConstPointerTo(const ThreadSafePointerTo<T> ©) :
|
|
||||||
ThreadSafePointerToBase<T>((const ThreadSafePointerToBase<T> &)copy)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
template<class T>
|
|
||||||
INLINE ThreadSafeConstPointerTo<T>::
|
|
||||||
~ThreadSafeConstPointerTo() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
template<class T>
|
|
||||||
INLINE ThreadSafeConstPointerTo<T>::
|
|
||||||
ThreadSafeConstPointerTo(const ThreadSafeConstPointerTo<T> ©) :
|
|
||||||
ThreadSafePointerToBase<T>((const ThreadSafePointerToBase<T> &)copy)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
template<class T>
|
|
||||||
INLINE const typename ThreadSafeConstPointerTo<T>::To &ThreadSafeConstPointerTo<T>::
|
|
||||||
operator *() const {
|
|
||||||
return *((To *)AtomicAdjust::get_ptr(this->_void_ptr));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
template<class T>
|
|
||||||
INLINE const typename ThreadSafeConstPointerTo<T>::To *ThreadSafeConstPointerTo<T>::
|
|
||||||
operator -> () const {
|
|
||||||
return (To *)AtomicAdjust::get_ptr(this->_void_ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* We also have the typecast operator to automatically convert
|
|
||||||
* ThreadSafeConstPointerTo's to the required kind of actual pointer. This
|
|
||||||
* introduces ambiguities which the compiler will resolve one way or the
|
|
||||||
* other, but we don't care which way it goes because either will be correct.
|
|
||||||
*/
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
INLINE ThreadSafeConstPointerTo<T>::
|
|
||||||
operator const T * () const {
|
|
||||||
return (To *)AtomicAdjust::get_ptr(this->_void_ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns an ordinary pointer instead of a ThreadSafeConstPointerTo. Useful
|
|
||||||
* to work around compiler problems, particularly for implicit upcasts.
|
|
||||||
*/
|
|
||||||
template<class T>
|
|
||||||
INLINE const typename ThreadSafeConstPointerTo<T>::To *ThreadSafeConstPointerTo<T>::
|
|
||||||
p() const {
|
|
||||||
return (To *)AtomicAdjust::get_ptr(this->_void_ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
template<class T>
|
|
||||||
INLINE ThreadSafeConstPointerTo<T> &ThreadSafeConstPointerTo<T>::
|
|
||||||
operator = (const To *ptr) {
|
|
||||||
this->reassign((To *)ptr);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
template<class T>
|
|
||||||
INLINE ThreadSafeConstPointerTo<T> &ThreadSafeConstPointerTo<T>::
|
|
||||||
operator = (const ThreadSafePointerTo<T> ©) {
|
|
||||||
this->reassign((const ThreadSafePointerToBase<T> &)copy);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
template<class T>
|
|
||||||
INLINE ThreadSafeConstPointerTo<T> &ThreadSafeConstPointerTo<T>::
|
|
||||||
operator = (const ThreadSafeConstPointerTo<T> ©) {
|
|
||||||
this->reassign((const ThreadSafePointerToBase<T> &)copy);
|
|
||||||
return *this;
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
/**
|
|
||||||
* PANDA 3D SOFTWARE
|
|
||||||
* Copyright (c) Carnegie Mellon University. All rights reserved.
|
|
||||||
*
|
|
||||||
* All use of this software is subject to the terms of the revised BSD
|
|
||||||
* license. You should have received a copy of this license along
|
|
||||||
* with this source code in a file named "LICENSE."
|
|
||||||
*
|
|
||||||
* @file threadSafePointerTo.cxx
|
|
||||||
* @author drose
|
|
||||||
* @date 2006-04-28
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "threadSafePointerTo.h"
|
|
@ -1,105 +0,0 @@
|
|||||||
/**
|
|
||||||
* PANDA 3D SOFTWARE
|
|
||||||
* Copyright (c) Carnegie Mellon University. All rights reserved.
|
|
||||||
*
|
|
||||||
* All use of this software is subject to the terms of the revised BSD
|
|
||||||
* license. You should have received a copy of this license along
|
|
||||||
* with this source code in a file named "LICENSE."
|
|
||||||
*
|
|
||||||
* @file threadSafePointerTo.h
|
|
||||||
* @author drose
|
|
||||||
* @date 2006-04-28
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef THREADSAFEPOINTERTO_H
|
|
||||||
#define THREADSAFEPOINTERTO_H
|
|
||||||
|
|
||||||
#include "pandabase.h"
|
|
||||||
#include "threadSafePointerToBase.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This works exactly like PointerTo, except that the object is designed to be
|
|
||||||
* thread-safe: it is generally safe to make unprotected assignments to this
|
|
||||||
* pointer, in the sense that the last assignment will win and the reference
|
|
||||||
* counts will be properly maintained.
|
|
||||||
*/
|
|
||||||
template <class T>
|
|
||||||
class ThreadSafePointerTo : public ThreadSafePointerToBase<T> {
|
|
||||||
public:
|
|
||||||
typedef typename ThreadSafePointerToBase<T>::To To;
|
|
||||||
PUBLISHED:
|
|
||||||
INLINE ThreadSafePointerTo(To *ptr = nullptr);
|
|
||||||
INLINE ThreadSafePointerTo(const ThreadSafePointerTo<T> ©);
|
|
||||||
INLINE ~ThreadSafePointerTo();
|
|
||||||
|
|
||||||
public:
|
|
||||||
INLINE To &operator *() const;
|
|
||||||
INLINE To *operator -> () const;
|
|
||||||
// MSVC.NET 2005 insists that we use T *, and not To *, here.
|
|
||||||
INLINE operator T *() const;
|
|
||||||
|
|
||||||
PUBLISHED:
|
|
||||||
// When downcasting to a derived class from a
|
|
||||||
// ThreadSafePointerTo<BaseClass>, C++ would normally require you to cast
|
|
||||||
// twice: once to an actual BaseClass pointer, and then again to your
|
|
||||||
// desired pointer. You can use the handy function p() to avoid this first
|
|
||||||
// cast and make your code look a bit cleaner.
|
|
||||||
|
|
||||||
// e.g. instead of (MyType *)(BaseClass *)ptr, use (MyType *)ptr.p()
|
|
||||||
|
|
||||||
// If your base class is a derivative of TypedObject, you might want to use
|
|
||||||
// the DCAST macro defined in typedObject.h instead, e.g. DCAST(MyType,
|
|
||||||
// ptr). This provides a clean downcast that doesn't require .p() or any
|
|
||||||
// double-casting, and it can be run-time checked for correctness.
|
|
||||||
INLINE To *p() const;
|
|
||||||
|
|
||||||
INLINE ThreadSafePointerTo<T> &operator = (To *ptr);
|
|
||||||
INLINE ThreadSafePointerTo<T> &operator = (const ThreadSafePointerTo<T> ©);
|
|
||||||
|
|
||||||
// These functions normally wouldn't need to be redefined here, but we do so
|
|
||||||
// anyway just to help out interrogate (which doesn't seem to want to
|
|
||||||
// automatically export the ThreadSafePointerToBase class). When this works
|
|
||||||
// again in interrogate, we can remove these.
|
|
||||||
INLINE bool is_null() const { return ThreadSafePointerToBase<T>::is_null(); }
|
|
||||||
INLINE void clear() { ThreadSafePointerToBase<T>::clear(); }
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
template <class T>
|
|
||||||
class ThreadSafeConstPointerTo : public ThreadSafePointerToBase<T> {
|
|
||||||
public:
|
|
||||||
typedef typename ThreadSafePointerToBase<T>::To To;
|
|
||||||
PUBLISHED:
|
|
||||||
INLINE ThreadSafeConstPointerTo(const To *ptr = nullptr);
|
|
||||||
INLINE ThreadSafeConstPointerTo(const ThreadSafePointerTo<T> ©);
|
|
||||||
INLINE ThreadSafeConstPointerTo(const ThreadSafeConstPointerTo<T> ©);
|
|
||||||
INLINE ~ThreadSafeConstPointerTo();
|
|
||||||
|
|
||||||
public:
|
|
||||||
INLINE const To &operator *() const;
|
|
||||||
INLINE const To *operator -> () const;
|
|
||||||
INLINE operator const T *() const;
|
|
||||||
|
|
||||||
PUBLISHED:
|
|
||||||
INLINE const To *p() const;
|
|
||||||
|
|
||||||
INLINE ThreadSafeConstPointerTo<T> &operator = (const To *ptr);
|
|
||||||
INLINE ThreadSafeConstPointerTo<T> &operator = (const ThreadSafePointerTo<T> ©);
|
|
||||||
INLINE ThreadSafeConstPointerTo<T> &operator = (const ThreadSafeConstPointerTo<T> ©);
|
|
||||||
|
|
||||||
// This functions normally wouldn't need to be redefined here, but we do so
|
|
||||||
// anyway just to help out interrogate (which doesn't seem to want to
|
|
||||||
// automatically export the ThreadSafePointerToBase class). When this works
|
|
||||||
// again in interrogate, we can remove this.
|
|
||||||
INLINE void clear() { ThreadSafePointerToBase<T>::clear(); }
|
|
||||||
};
|
|
||||||
|
|
||||||
#define TSPT(type) ThreadSafePointerTo< type >
|
|
||||||
#define TSCPT(type) ThreadSafeConstPointerTo< type >
|
|
||||||
|
|
||||||
#include "threadSafePointerTo.I"
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,132 +0,0 @@
|
|||||||
/**
|
|
||||||
* PANDA 3D SOFTWARE
|
|
||||||
* Copyright (c) Carnegie Mellon University. All rights reserved.
|
|
||||||
*
|
|
||||||
* All use of this software is subject to the terms of the revised BSD
|
|
||||||
* license. You should have received a copy of this license along
|
|
||||||
* with this source code in a file named "LICENSE."
|
|
||||||
*
|
|
||||||
* @file threadSafePointerToBase.I
|
|
||||||
* @author drose
|
|
||||||
* @date 2006-04-28
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
template<class T>
|
|
||||||
INLINE ThreadSafePointerToBase<T>::
|
|
||||||
ThreadSafePointerToBase(To *ptr) {
|
|
||||||
reassign(ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
template<class T>
|
|
||||||
INLINE ThreadSafePointerToBase<T>::
|
|
||||||
ThreadSafePointerToBase(const ThreadSafePointerToBase<T> ©) {
|
|
||||||
reassign(copy);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
template<class T>
|
|
||||||
INLINE ThreadSafePointerToBase<T>::
|
|
||||||
~ThreadSafePointerToBase() {
|
|
||||||
reassign(nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is the main work of the ThreadSafePointerTo family. When the pointer
|
|
||||||
* is reassigned, decrement the old reference count and increment the new one.
|
|
||||||
*/
|
|
||||||
template<class T>
|
|
||||||
INLINE void ThreadSafePointerToBase<T>::
|
|
||||||
reassign(To *ptr) {
|
|
||||||
To *old_ptr = (To *)AtomicAdjust::get_ptr(_void_ptr);
|
|
||||||
if (ptr == old_ptr) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef HAVE_THREADS
|
|
||||||
void *orig_ptr = AtomicAdjust::compare_and_exchange_ptr(_void_ptr, old_ptr, ptr);
|
|
||||||
while (orig_ptr != old_ptr) {
|
|
||||||
// Some other thread assigned it first. Try again.
|
|
||||||
old_ptr = (To *)AtomicAdjust::get_ptr(_void_ptr);
|
|
||||||
if (ptr == old_ptr) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
orig_ptr = AtomicAdjust::compare_and_exchange_ptr(_void_ptr, old_ptr, ptr);
|
|
||||||
}
|
|
||||||
#else // HAVE_THREADS
|
|
||||||
_void_ptr = ptr;
|
|
||||||
#endif // HAVE_THREADS
|
|
||||||
|
|
||||||
if (ptr != nullptr) {
|
|
||||||
ptr->ref();
|
|
||||||
#ifdef DO_MEMORY_USAGE
|
|
||||||
if (MemoryUsage::get_track_memory_usage()) {
|
|
||||||
update_type(ptr);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now delete the old pointer.
|
|
||||||
if (old_ptr != nullptr) {
|
|
||||||
unref_delete(old_ptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
template<class T>
|
|
||||||
INLINE void ThreadSafePointerToBase<T>::
|
|
||||||
reassign(const ThreadSafePointerToBase<To> ©) {
|
|
||||||
reassign((To *)copy._void_ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ensures that the MemoryUsage record for the pointer has the right type of
|
|
||||||
* object, if we know the type ourselves.
|
|
||||||
*/
|
|
||||||
template<class T>
|
|
||||||
void ThreadSafePointerToBase<T>::
|
|
||||||
update_type(To *ptr) {
|
|
||||||
#ifdef DO_MEMORY_USAGE
|
|
||||||
TypeHandle type = get_type_handle(To);
|
|
||||||
if (type == TypeHandle::none()) {
|
|
||||||
do_init_type(To);
|
|
||||||
type = get_type_handle(To);
|
|
||||||
}
|
|
||||||
if (type != TypeHandle::none()) {
|
|
||||||
MemoryUsage::update_type(ptr, type);
|
|
||||||
}
|
|
||||||
#endif // DO_MEMORY_USAGE
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A convenient way to set the ThreadSafePointerTo object to NULL. (Assignment
|
|
||||||
* to a NULL pointer also works, of course.)
|
|
||||||
*/
|
|
||||||
template<class T>
|
|
||||||
INLINE void ThreadSafePointerToBase<T>::
|
|
||||||
clear() {
|
|
||||||
reassign(nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A handy function to output ThreadSafePointerTo's as a hex pointer followed
|
|
||||||
* by a reference count.
|
|
||||||
*/
|
|
||||||
template<class T>
|
|
||||||
INLINE void ThreadSafePointerToBase<T>::
|
|
||||||
output(std::ostream &out) const {
|
|
||||||
out << _void_ptr;
|
|
||||||
if (_void_ptr != nullptr) {
|
|
||||||
out << ":" << ((To *)_void_ptr)->get_ref_count();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
/**
|
|
||||||
* PANDA 3D SOFTWARE
|
|
||||||
* Copyright (c) Carnegie Mellon University. All rights reserved.
|
|
||||||
*
|
|
||||||
* All use of this software is subject to the terms of the revised BSD
|
|
||||||
* license. You should have received a copy of this license along
|
|
||||||
* with this source code in a file named "LICENSE."
|
|
||||||
*
|
|
||||||
* @file threadSafePointerToBase.cxx
|
|
||||||
* @author drose
|
|
||||||
* @date 2006-04-28
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "threadSafePointerToBase.h"
|
|
@ -1,63 +0,0 @@
|
|||||||
/**
|
|
||||||
* PANDA 3D SOFTWARE
|
|
||||||
* Copyright (c) Carnegie Mellon University. All rights reserved.
|
|
||||||
*
|
|
||||||
* All use of this software is subject to the terms of the revised BSD
|
|
||||||
* license. You should have received a copy of this license along
|
|
||||||
* with this source code in a file named "LICENSE."
|
|
||||||
*
|
|
||||||
* @file threadSafePointerToBase.h
|
|
||||||
* @author drose
|
|
||||||
* @date 2006-04-28
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef THREADSAFEPOINTERTOBASE_H
|
|
||||||
#define THREADSAFEPOINTERTOBASE_H
|
|
||||||
|
|
||||||
#include "pandabase.h"
|
|
||||||
#include "pointerToVoid.h"
|
|
||||||
#include "referenceCount.h"
|
|
||||||
#include "typedef.h"
|
|
||||||
#include "memoryUsage.h"
|
|
||||||
#include "config_express.h"
|
|
||||||
#include "atomicAdjust.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is the base class for ThreadSafePointerTo and
|
|
||||||
* ThreadSafeConstPointerTo. Don't try to use it directly; use either derived
|
|
||||||
* class instead.
|
|
||||||
*/
|
|
||||||
template <class T>
|
|
||||||
class ThreadSafePointerToBase : public PointerToVoid {
|
|
||||||
public:
|
|
||||||
typedef T To;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
INLINE ThreadSafePointerToBase(To *ptr);
|
|
||||||
INLINE ThreadSafePointerToBase(const ThreadSafePointerToBase<T> ©);
|
|
||||||
INLINE ~ThreadSafePointerToBase();
|
|
||||||
|
|
||||||
INLINE void reassign(To *ptr);
|
|
||||||
INLINE void reassign(const ThreadSafePointerToBase<To> ©);
|
|
||||||
|
|
||||||
void update_type(To *ptr);
|
|
||||||
|
|
||||||
// No assignment or retrieval functions are declared in
|
|
||||||
// ThreadSafePointerToBase, because we will have to specialize on const vs.
|
|
||||||
// non-const later.
|
|
||||||
|
|
||||||
PUBLISHED:
|
|
||||||
INLINE void clear();
|
|
||||||
|
|
||||||
void output(std::ostream &out) const;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
INLINE std::ostream &operator <<(std::ostream &out, const ThreadSafePointerToBase<T> &pointer) {
|
|
||||||
pointer.output(out);
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "threadSafePointerToBase.I"
|
|
||||||
|
|
||||||
#endif
|
|
Loading…
x
Reference in New Issue
Block a user