Use LeakChecked throughout Beast

This commit is contained in:
Vinnie Falco
2013-06-29 22:59:07 -07:00
parent f881ee96f9
commit a3325d4e1f
109 changed files with 359 additions and 654 deletions

View File

@@ -63,8 +63,7 @@
/** Config: BEAST_CHECK_MEMORY_LEAKS /** Config: BEAST_CHECK_MEMORY_LEAKS
Enables a memory-leak check for certain objects when the app terminates. Enables a memory-leak check for certain objects when the app terminates.
See the LeakedObjectDetector and LeakChecked classes, and the See the LeakChecked class for more details about enabling leak checking for
BEAST_LEAK_DETECTOR macro for more details about enabling leak checking for
specific classes. specific classes.
*/ */
#ifndef BEAST_CHECK_MEMORY_LEAKS #ifndef BEAST_CHECK_MEMORY_LEAKS

View File

@@ -1632,7 +1632,6 @@
<ClInclude Include="..\..\modules\ripple_data\protocol\ripple_TxFlags.h" /> <ClInclude Include="..\..\modules\ripple_data\protocol\ripple_TxFlags.h" />
<ClInclude Include="..\..\modules\ripple_data\protocol\ripple_TxFormats.h" /> <ClInclude Include="..\..\modules\ripple_data\protocol\ripple_TxFormats.h" />
<ClInclude Include="..\..\modules\ripple_data\ripple_data.h" /> <ClInclude Include="..\..\modules\ripple_data\ripple_data.h" />
<ClInclude Include="..\..\modules\ripple_data\utility\ripple_JSONCache.h" />
<ClInclude Include="..\..\modules\ripple_data\utility\ripple_UptimeTimerAdapter.h" /> <ClInclude Include="..\..\modules\ripple_data\utility\ripple_UptimeTimerAdapter.h" />
<ClInclude Include="..\..\modules\ripple_json\json\json_autolink.h" /> <ClInclude Include="..\..\modules\ripple_json\json\json_autolink.h" />
<ClInclude Include="..\..\modules\ripple_json\json\json_batchallocator.h" /> <ClInclude Include="..\..\modules\ripple_json\json\json_batchallocator.h" />

View File

@@ -1788,7 +1788,6 @@
<ClInclude Include="..\..\modules\ripple_app\basics\ripple_BuildVersion.h"> <ClInclude Include="..\..\modules\ripple_app\basics\ripple_BuildVersion.h">
<Filter>1. Modules\ripple_app\basics</Filter> <Filter>1. Modules\ripple_app\basics</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\modules\ripple_data\utility\ripple_JSONCache.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="..\..\src\cpp\protobuf\src\google\protobuf\descriptor.proto"> <None Include="..\..\src\cpp\protobuf\src\google\protobuf\descriptor.proto">

View File

@@ -63,8 +63,7 @@
/** Config: BEAST_CHECK_MEMORY_LEAKS /** Config: BEAST_CHECK_MEMORY_LEAKS
Enables a memory-leak check for certain objects when the app terminates. Enables a memory-leak check for certain objects when the app terminates.
See the LeakedObjectDetector and LeakChecked classes, and the See the LeakChecked class for more details about enabling leak checking for
BEAST_LEAK_DETECTOR macro for more details about enabling leak checking for
specific classes. specific classes.
*/ */
#ifndef BEAST_CHECK_MEMORY_LEAKS #ifndef BEAST_CHECK_MEMORY_LEAKS

View File

@@ -143,7 +143,6 @@
<ClInclude Include="..\..\modules\beast_core\memory\beast_ByteOrder.h" /> <ClInclude Include="..\..\modules\beast_core\memory\beast_ByteOrder.h" />
<ClInclude Include="..\..\modules\beast_core\memory\beast_CacheLine.h" /> <ClInclude Include="..\..\modules\beast_core\memory\beast_CacheLine.h" />
<ClInclude Include="..\..\modules\beast_core\memory\beast_HeapBlock.h" /> <ClInclude Include="..\..\modules\beast_core\memory\beast_HeapBlock.h" />
<ClInclude Include="..\..\modules\beast_core\memory\beast_LeakedObjectDetector.h" />
<ClInclude Include="..\..\modules\beast_core\memory\beast_Memory.h" /> <ClInclude Include="..\..\modules\beast_core\memory\beast_Memory.h" />
<ClInclude Include="..\..\modules\beast_core\memory\beast_MemoryAlignment.h" /> <ClInclude Include="..\..\modules\beast_core\memory\beast_MemoryAlignment.h" />
<ClInclude Include="..\..\modules\beast_core\memory\beast_MemoryBlock.h" /> <ClInclude Include="..\..\modules\beast_core\memory\beast_MemoryBlock.h" />
@@ -152,6 +151,7 @@
<ClInclude Include="..\..\modules\beast_core\memory\beast_ScopedPointer.h" /> <ClInclude Include="..\..\modules\beast_core\memory\beast_ScopedPointer.h" />
<ClInclude Include="..\..\modules\beast_core\memory\beast_Singleton.h" /> <ClInclude Include="..\..\modules\beast_core\memory\beast_Singleton.h" />
<ClInclude Include="..\..\modules\beast_core\memory\beast_StaticObject.h" /> <ClInclude Include="..\..\modules\beast_core\memory\beast_StaticObject.h" />
<ClInclude Include="..\..\modules\beast_core\memory\beast_Uncopyable.h" />
<ClInclude Include="..\..\modules\beast_core\memory\beast_WeakReference.h" /> <ClInclude Include="..\..\modules\beast_core\memory\beast_WeakReference.h" />
<ClInclude Include="..\..\modules\beast_core\misc\beast_Result.h" /> <ClInclude Include="..\..\modules\beast_core\misc\beast_Result.h" />
<ClInclude Include="..\..\modules\beast_core\misc\beast_Uuid.h" /> <ClInclude Include="..\..\modules\beast_core\misc\beast_Uuid.h" />
@@ -749,6 +749,12 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\modules\beast_core\threads\beast_SpinDelay.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\modules\beast_core\threads\beast_Thread.cpp"> <ClCompile Include="..\..\modules\beast_core\threads\beast_Thread.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>

View File

@@ -226,9 +226,6 @@
<ClInclude Include="..\..\modules\beast_core\memory\beast_HeapBlock.h"> <ClInclude Include="..\..\modules\beast_core\memory\beast_HeapBlock.h">
<Filter>beast_core\memory</Filter> <Filter>beast_core\memory</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\modules\beast_core\memory\beast_LeakedObjectDetector.h">
<Filter>beast_core\memory</Filter>
</ClInclude>
<ClInclude Include="..\..\modules\beast_core\memory\beast_Memory.h"> <ClInclude Include="..\..\modules\beast_core\memory\beast_Memory.h">
<Filter>beast_core\memory</Filter> <Filter>beast_core\memory</Filter>
</ClInclude> </ClInclude>
@@ -617,6 +614,9 @@
<ClInclude Include="..\..\modules\beast_core\diagnostic\beast_Throw.h"> <ClInclude Include="..\..\modules\beast_core\diagnostic\beast_Throw.h">
<Filter>beast_core\diagnostic</Filter> <Filter>beast_core\diagnostic</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\modules\beast_core\memory\beast_Uncopyable.h">
<Filter>beast_core\memory</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\..\modules\beast_core\beast_core.cpp"> <ClCompile Include="..\..\modules\beast_core\beast_core.cpp">
@@ -952,5 +952,8 @@
<ClCompile Include="..\..\modules\beast_core\diagnostic\beast_LeakChecked.cpp"> <ClCompile Include="..\..\modules\beast_core\diagnostic\beast_LeakChecked.cpp">
<Filter>beast_core\diagnostic</Filter> <Filter>beast_core\diagnostic</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\modules\beast_core\threads\beast_SpinDelay.cpp">
<Filter>beast_core\threads</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -24,7 +24,12 @@
@ingroup beast_concurrent @ingroup beast_concurrent
*/ */
#if 0//BEAST_BOOST_IS_AVAILABLE // VFALCO NOTE Disabled this because it seems that the TLS
// implementation has a leak. Although the other
// one also seems to have a leak.
//
//#if BEAST_BOOST_IS_AVAILABLE
#if 0
typedef FifoFreeStoreWithTLS FifoFreeStoreType; typedef FifoFreeStoreWithTLS FifoFreeStoreType;
#else #else
typedef FifoFreeStoreWithoutTLS FifoFreeStoreType; typedef FifoFreeStoreWithoutTLS FifoFreeStoreType;

View File

@@ -20,24 +20,28 @@
#ifndef BEAST_REFERENCECOUNTEDSINGLETON_BEASTHEADER #ifndef BEAST_REFERENCECOUNTEDSINGLETON_BEASTHEADER
#define BEAST_REFERENCECOUNTEDSINGLETON_BEASTHEADER #define BEAST_REFERENCECOUNTEDSINGLETON_BEASTHEADER
/** /** Thread-safe singleton which comes into existence on first use. Use this
Thread-safe singleton which comes into existence on first use. Use this instead of creating objects with static storage duration. These singletons
instead of creating objects with static storage duration. These singletons are automatically reference counted, so if you hold a pointer to it in every
are automatically reference counted, so if you hold a pointer to it in every object that depends on it, the order of destruction of objects is assured
object that depends on it, the order of destruction of objects is assured to be correct.
to be correct.
class Object must provide the function `Object* Object::createInstance()` class Object must provide the function `Object* Object::createInstance()`
@class RefCountedSingleton @class RefCountedSingleton
@ingroup beast_core @ingroup beast_core
*/ */
/** @{ */ /** @{ */
class BEAST_API SingletonLifetime class BEAST_API SingletonLifetime
{ {
// "base classes dependent on a template parameter
// aren't part of lookup." - ville
public: public:
// It would be nice if we didn't have to qualify the enumeration but
// Argument Dependent Lookup is inapplicable here because:
//
// "Base classes dependent on a template parameter aren't part of lookup."
// - ville
//
/** Construction options for RefCountedSingleton /** Construction options for RefCountedSingleton
@ingroup beast_core @ingroup beast_core
@@ -59,6 +63,8 @@ public:
}; };
}; };
//------------------------------------------------------------------------------
template <class Object> template <class Object>
class RefCountedSingleton class RefCountedSingleton
: public SingletonLifetime : public SingletonLifetime

View File

@@ -183,6 +183,7 @@ namespace beast
#include "streams/beast_MemoryOutputStream.cpp" #include "streams/beast_MemoryOutputStream.cpp"
#include "streams/beast_OutputStream.cpp" #include "streams/beast_OutputStream.cpp"
#include "streams/beast_SubregionStream.cpp" #include "streams/beast_SubregionStream.cpp"
#include "system/beast_SystemStats.cpp" #include "system/beast_SystemStats.cpp"
#include "text/beast_CharacterFunctions.cpp" #include "text/beast_CharacterFunctions.cpp"
@@ -197,6 +198,7 @@ namespace beast
#include "threads/beast_ChildProcess.cpp" #include "threads/beast_ChildProcess.cpp"
#include "threads/beast_ReadWriteLock.cpp" #include "threads/beast_ReadWriteLock.cpp"
#include "threads/beast_SpinDelay.cpp"
#include "threads/beast_Thread.cpp" #include "threads/beast_Thread.cpp"
#include "threads/beast_ThreadPool.cpp" #include "threads/beast_ThreadPool.cpp"
#include "threads/beast_TimeSliceThread.cpp" #include "threads/beast_TimeSliceThread.cpp"

View File

@@ -198,17 +198,24 @@ namespace beast
// Order matters, since headers don't have their own #include lines. // Order matters, since headers don't have their own #include lines.
// Add new includes to the bottom. // Add new includes to the bottom.
#include "threads/beast_Thread.h" #include "memory/beast_Uncopyable.h"
#include "threads/beast_SpinDelay.h" #include "maths/beast_MathsFunctions.h"
#include "memory/beast_Atomic.h" #include "memory/beast_Atomic.h"
#include "memory/beast_AtomicCounter.h" #include "memory/beast_AtomicCounter.h"
#include "memory/beast_AtomicFlag.h" #include "memory/beast_AtomicFlag.h"
#include "memory/beast_AtomicPointer.h" #include "memory/beast_AtomicPointer.h"
#include "memory/beast_AtomicState.h" #include "memory/beast_AtomicState.h"
#include "containers/beast_LockFreeStack.h" #include "containers/beast_LockFreeStack.h"
#include "threads/beast_SpinDelay.h"
#include "memory/beast_StaticObject.h" #include "memory/beast_StaticObject.h"
#include "diagnostic/beast_LeakChecked.h" #include "diagnostic/beast_LeakChecked.h"
#include "memory/beast_Memory.h"
#include "memory/beast_ByteOrder.h"
#include "logging/beast_Logger.h"
#include "threads/beast_Thread.h"
#include "diagnostic/beast_Debug.h" #include "diagnostic/beast_Debug.h"
#include "diagnostic/beast_SafeBool.h" #include "diagnostic/beast_SafeBool.h"
#include "diagnostic/beast_Error.h" #include "diagnostic/beast_Error.h"
@@ -251,7 +258,6 @@ namespace beast
#include "maths/beast_Range.h" #include "maths/beast_Range.h"
#include "memory/beast_ByteOrder.h" #include "memory/beast_ByteOrder.h"
#include "memory/beast_HeapBlock.h" #include "memory/beast_HeapBlock.h"
#include "memory/beast_LeakedObjectDetector.h"
#include "memory/beast_Memory.h" #include "memory/beast_Memory.h"
#include "memory/beast_MemoryBlock.h" #include "memory/beast_MemoryBlock.h"
#include "memory/beast_OptionalScopedPointer.h" #include "memory/beast_OptionalScopedPointer.h"

View File

@@ -81,7 +81,7 @@
}; };
@endcode @endcode
*/ */
class BEAST_API AbstractFifo class BEAST_API AbstractFifo : LeakChecked <AbstractFifo>, Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -206,8 +206,6 @@ private:
//============================================================================== //==============================================================================
int bufferSize; int bufferSize;
Atomic <int> validStart, validEnd; Atomic <int> validStart, validEnd;
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AbstractFifo)
}; };
#endif #endif

View File

@@ -40,7 +40,8 @@
@see Array, OwnedArray, ReferenceCountedArray @see Array, OwnedArray, ReferenceCountedArray
*/ */
template <class ElementType, class TypeOfCriticalSectionToUse> template <class ElementType, class TypeOfCriticalSectionToUse>
class ArrayAllocationBase : public TypeOfCriticalSectionToUse class ArrayAllocationBase
: public TypeOfCriticalSectionToUse
{ {
public: public:
//============================================================================== //==============================================================================
@@ -126,9 +127,6 @@ public:
//============================================================================== //==============================================================================
HeapBlock <ElementType> elements; HeapBlock <ElementType> elements;
int numAllocated; int numAllocated;
private:
BEAST_DECLARE_NON_COPYABLE (ArrayAllocationBase)
}; };
#endif // BEAST_ARRAYALLOCATIONBASE_BEASTHEADER #endif // BEAST_ARRAYALLOCATIONBASE_BEASTHEADER

View File

@@ -39,7 +39,9 @@
by subclassing hasMethod() and invokeMethod(), you can give your object by subclassing hasMethod() and invokeMethod(), you can give your object
methods. methods.
*/ */
class BEAST_API DynamicObject : public ReferenceCountedObject class BEAST_API DynamicObject
: public ReferenceCountedObject
, LeakChecked <DynamicObject>
{ {
public: public:
//============================================================================== //==============================================================================
@@ -112,8 +114,6 @@ public:
private: private:
//============================================================================== //==============================================================================
NamedValueSet properties; NamedValueSet properties;
BEAST_LEAK_DETECTOR (DynamicObject)
}; };

View File

@@ -95,6 +95,11 @@ template <typename KeyType,
class HashFunctionToUse = DefaultHashFunctions, class HashFunctionToUse = DefaultHashFunctions,
class TypeOfCriticalSectionToUse = DummyCriticalSection> class TypeOfCriticalSectionToUse = DummyCriticalSection>
class HashMap class HashMap
: Uncopyable
, LeakChecked <HashMap <KeyType,
ValueType,
HashFunctionToUse,
TypeOfCriticalSectionToUse> >
{ {
private: private:
typedef PARAMETER_TYPE (KeyType) KeyTypeParameter; typedef PARAMETER_TYPE (KeyType) KeyTypeParameter;
@@ -333,7 +338,7 @@ public:
private: private:
//============================================================================== //==============================================================================
class HashEntry class HashEntry : Uncopyable
{ {
public: public:
HashEntry (KeyTypeParameter k, ValueTypeParameter val, HashEntry* const next) HashEntry (KeyTypeParameter k, ValueTypeParameter val, HashEntry* const next)
@@ -343,8 +348,6 @@ private:
const KeyType key; const KeyType key;
ValueType value; ValueType value;
HashEntry* nextEntry; HashEntry* nextEntry;
BEAST_DECLARE_NON_COPYABLE (HashEntry)
}; };
public: public:
@@ -371,7 +374,7 @@ public:
@see HashMap @see HashMap
*/ */
class Iterator class Iterator : LeakChecked <Iterator>, Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -420,8 +423,6 @@ public:
const HashMap& hashMap; const HashMap& hashMap;
HashEntry* entry; HashEntry* entry;
int index; int index;
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Iterator)
}; };
private: private:
@@ -439,8 +440,6 @@ private:
bassert (isPositiveAndBelow (hash, getNumSlots())); // your hash function is generating out-of-range numbers! bassert (isPositiveAndBelow (hash, getNumSlots())); // your hash function is generating out-of-range numbers!
return hash; return hash;
} }
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (HashMap)
}; };

View File

@@ -53,7 +53,7 @@
@endcode @endcode
*/ */
template <class ObjectType> template <class ObjectType>
class LinkedListPointer class LinkedListPointer : Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -330,7 +330,7 @@ public:
list, and then repeatedly call Appender::append() to add items to the end list, and then repeatedly call Appender::append() to add items to the end
of the list in O(1) time. of the list in O(1) time.
*/ */
class Appender class Appender : Uncopyable
{ {
public: public:
/** Creates an appender which will add items to the given list. /** Creates an appender which will add items to the given list.
@@ -351,15 +351,11 @@ public:
private: private:
LinkedListPointer* endOfList; LinkedListPointer* endOfList;
BEAST_DECLARE_NON_COPYABLE (Appender)
}; };
private: private:
//============================================================================== //==============================================================================
ObjectType* item; ObjectType* item;
BEAST_DECLARE_NON_COPYABLE (LinkedListPointer)
}; };

View File

@@ -132,7 +132,7 @@ public:
private: private:
//============================================================================== //==============================================================================
class NamedValue class NamedValue : LeakChecked <NamedValue>
{ {
public: public:
NamedValue() noexcept; NamedValue() noexcept;
@@ -151,7 +151,6 @@ private:
var value; var value;
private: private:
BEAST_LEAK_DETECTOR (NamedValue)
}; };
friend class LinkedListPointer<NamedValue>; friend class LinkedListPointer<NamedValue>;

View File

@@ -51,7 +51,7 @@
template <class ObjectClass, template <class ObjectClass,
class TypeOfCriticalSectionToUse = DummyCriticalSection> class TypeOfCriticalSectionToUse = DummyCriticalSection>
class OwnedArray class OwnedArray : LeakChecked <OwnedArray <ObjectClass, TypeOfCriticalSectionToUse> >, Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -907,8 +907,6 @@ private:
while (numUsed > 0) while (numUsed > 0)
delete data.elements [--numUsed]; delete data.elements [--numUsed];
} }
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OwnedArray)
}; };
#endif // BEAST_OWNEDARRAY_BEASTHEADER #endif // BEAST_OWNEDARRAY_BEASTHEADER

View File

@@ -39,7 +39,7 @@
See the PropertiesFile class for a subclass of this, which automatically broadcasts change See the PropertiesFile class for a subclass of this, which automatically broadcasts change
messages and saves/loads the list from a file. messages and saves/loads the list from a file.
*/ */
class BEAST_API PropertySet class BEAST_API PropertySet : LeakChecked <PropertySet>
{ {
public: public:
//============================================================================== //==============================================================================
@@ -206,8 +206,6 @@ private:
PropertySet* fallbackProperties; PropertySet* fallbackProperties;
CriticalSection lock; CriticalSection lock;
bool ignoreCaseOfKeys; bool ignoreCaseOfKeys;
BEAST_LEAK_DETECTOR (PropertySet)
}; };

View File

@@ -52,7 +52,7 @@
*/ */
template <typename ValueType> template <typename ValueType>
class ScopedValueSetter class ScopedValueSetter : Uncopyable
{ {
public: public:
/** Creates a ScopedValueSetter that will immediately change the specified value to the /** Creates a ScopedValueSetter that will immediately change the specified value to the
@@ -87,8 +87,6 @@ private:
//============================================================================== //==============================================================================
ValueType& value; ValueType& value;
const ValueType originalValue; const ValueType originalValue;
BEAST_DECLARE_NON_COPYABLE (ScopedValueSetter)
}; };

View File

@@ -19,8 +19,6 @@
#if BEAST_USE_LEAKCHECKED #if BEAST_USE_LEAKCHECKED
/*============================================================================*/
// Type-independent portion of Counter
class LeakCheckedBase::CounterBase::Singleton class LeakCheckedBase::CounterBase::Singleton
{ {
public: public:
@@ -76,8 +74,18 @@ void LeakCheckedBase::CounterBase::detectLeaks ()
if (count > 0) if (count > 0)
{ {
/** If you hit this, then you've leaked one or more objects of the
specified class; the name should have been printed by the line
below.
If you're leaking, it's probably because you're using old-fashioned,
non-RAII techniques for your object management. Tut, tut. Always,
always use ScopedPointers, OwnedArrays, ReferenceCountedObjects,
etc, and avoid the 'delete' operator at all costs!
*/
DBG ("Leaked objects: " << count << " of " << getClassName ());
//bassertfalse; //bassertfalse;
DBG ("[LEAK] " << count << " of " << getClassName ());
} }
} }

View File

@@ -78,28 +78,37 @@ class LeakChecked : private LeakCheckedBase
protected: protected:
LeakChecked () noexcept LeakChecked () noexcept
{ {
if (getLeakCheckedCounter ().increment () == 0) getCounter ().increment ();
{
DBG ("[LOGIC] " << getLeakCheckedName ());
Throw (Error ().fail (__FILE__, __LINE__));
}
} }
LeakChecked (const LeakChecked&) noexcept LeakChecked (const LeakChecked&) noexcept
{ {
if (getLeakCheckedCounter ().increment () == 0) getCounter ().increment ();
{
DBG ("[LOGIC] " << getLeakCheckedName ());
Throw (Error ().fail (__FILE__, __LINE__));
}
} }
~LeakChecked () ~LeakChecked ()
{ {
if (getLeakCheckedCounter ().decrement () < 0) if (getCounter ().decrement () < 0)
{ {
DBG ("[LOGIC] " << getLeakCheckedName ()); /* If you hit this, then you've managed to delete more instances
Throw (Error ().fail (__FILE__, __LINE__)); of this class than you've created. That indicates that you're
deleting some dangling pointers.
Note that although this assertion will have been triggered
during a destructor, it might not be this particular deletion
that's at fault - the incorrect one may have happened at an
earlier point in the program, and simply not been detected
until now.
Most errors like this are caused by using old-fashioned,
non-RAII techniques for your object management. Tut, tut.
Always, always use ScopedPointers, OwnedArrays,
ReferenceCountedObjects, etc, and avoid the 'delete' operator
at all costs!
*/
DBG ("Dangling pointer deletion: " << getLeakCheckedName ());
bassertfalse;
} }
} }
@@ -130,16 +139,17 @@ private:
return typeid (Object).name (); return typeid (Object).name ();
} }
static Counter& getLeakCheckedCounter () noexcept static Counter& getCounter () noexcept
{ {
static Counter* volatile s_instance; static Counter* volatile s_instance;
static Static::Initializer s_initializer; static Static::Initializer s_initializer;
if (s_initializer.begin ()) if (s_initializer.beginConstruction ())
{ {
static char s_storage [sizeof (Counter)]; static char s_storage [sizeof (Counter)];
s_instance = new (s_storage) Counter; s_instance = new (s_storage) Counter;
s_initializer.end ();
s_initializer.endConstruction ();
} }
return *s_instance; return *s_instance;

View File

@@ -41,7 +41,7 @@
It can also guess how far it's got using a wildly inaccurate algorithm. It can also guess how far it's got using a wildly inaccurate algorithm.
*/ */
class BEAST_API DirectoryIterator class BEAST_API DirectoryIterator : LeakChecked <DirectoryIterator>, Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -116,7 +116,7 @@ public:
private: private:
//============================================================================== //==============================================================================
class NativeIterator class NativeIterator : LeakChecked <NativeIterator>, Uncopyable
{ {
public: public:
NativeIterator (const File& directory, const String& wildCard); NativeIterator (const File& directory, const String& wildCard);
@@ -132,8 +132,6 @@ private:
friend class DirectoryIterator; friend class DirectoryIterator;
friend class ScopedPointer<Pimpl>; friend class ScopedPointer<Pimpl>;
ScopedPointer<Pimpl> pimpl; ScopedPointer<Pimpl> pimpl;
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NativeIterator)
}; };
friend class ScopedPointer<NativeIterator::Pimpl>; friend class ScopedPointer<NativeIterator::Pimpl>;
@@ -147,8 +145,6 @@ private:
bool hasBeenAdvanced; bool hasBeenAdvanced;
ScopedPointer <DirectoryIterator> subIterator; ScopedPointer <DirectoryIterator> subIterator;
File currentFile; File currentFile;
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DirectoryIterator)
}; };
#endif // BEAST_DIRECTORYITERATOR_BEASTHEADER #endif // BEAST_DIRECTORYITERATOR_BEASTHEADER

View File

@@ -26,6 +26,15 @@ File::File (const String& fullPathName)
{ {
} }
File::File (const File& other)
: fullPath (other.fullPath)
{
}
File::~File() noexcept
{
}
File File::createFileWithoutCheckingPath (const String& path) noexcept File File::createFileWithoutCheckingPath (const String& path) noexcept
{ {
File f; File f;
@@ -33,11 +42,6 @@ File File::createFileWithoutCheckingPath (const String& path) noexcept
return f; return f;
} }
File::File (const File& other)
: fullPath (other.fullPath)
{
}
File& File::operator= (const String& newPath) File& File::operator= (const String& newPath)
{ {
fullPath = parseAbsolutePath (newPath); fullPath = parseAbsolutePath (newPath);

View File

@@ -46,7 +46,7 @@ class FileOutputStream;
@see FileInputStream, FileOutputStream @see FileInputStream, FileOutputStream
*/ */
class BEAST_API File class BEAST_API File : LeakChecked <File>
{ {
public: public:
//============================================================================== //==============================================================================
@@ -76,7 +76,7 @@ public:
File (const File& other); File (const File& other);
/** Destructor. */ /** Destructor. */
~File() noexcept {} ~File() noexcept;
/** Sets the file based on an absolute pathname. /** Sets the file based on an absolute pathname.
@@ -948,8 +948,6 @@ private:
bool setFileTimesInternal (int64 m, int64 a, int64 c) const; bool setFileTimesInternal (int64 m, int64 a, int64 c) const;
void getFileTimesInternal (int64& m, int64& a, int64& c) const; void getFileTimesInternal (int64& m, int64& a, int64& c) const;
bool setFileReadOnlyInternal (bool) const; bool setFileReadOnlyInternal (bool) const;
BEAST_LEAK_DETECTOR (File)
}; };
#endif // BEAST_FILE_BEASTHEADER #endif // BEAST_FILE_BEASTHEADER

View File

@@ -34,7 +34,9 @@
@see InputStream, FileOutputStream, File::createInputStream @see InputStream, FileOutputStream, File::createInputStream
*/ */
class BEAST_API FileInputStream : public InputStream class BEAST_API FileInputStream
: public InputStream
, LeakChecked <FileInputStream>
{ {
public: public:
//============================================================================== //==============================================================================
@@ -87,8 +89,6 @@ private:
void openHandle(); void openHandle();
void closeHandle(); void closeHandle();
size_t readInternal (void* buffer, size_t numBytes); size_t readInternal (void* buffer, size_t numBytes);
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FileInputStream)
}; };
#endif // BEAST_FILEINPUTSTREAM_BEASTHEADER #endif // BEAST_FILEINPUTSTREAM_BEASTHEADER

View File

@@ -34,7 +34,9 @@
@see OutputStream, FileInputStream, File::createOutputStream @see OutputStream, FileInputStream, File::createOutputStream
*/ */
class BEAST_API FileOutputStream : public OutputStream class BEAST_API FileOutputStream
: public OutputStream
, LeakChecked <FileOutputStream>
{ {
public: public:
//============================================================================== //==============================================================================
@@ -107,8 +109,6 @@ private:
bool flushBuffer(); bool flushBuffer();
int64 setPositionInternal (int64); int64 setPositionInternal (int64);
ssize_t writeInternal (const void*, size_t); ssize_t writeInternal (const void*, size_t);
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FileOutputStream)
}; };
#endif // BEAST_FILEOUTPUTSTREAM_BEASTHEADER #endif // BEAST_FILEOUTPUTSTREAM_BEASTHEADER

View File

@@ -34,7 +34,7 @@
@see File @see File
*/ */
class BEAST_API FileSearchPath class BEAST_API FileSearchPath : LeakChecked <FileSearchPath>
{ {
public: public:
//============================================================================== //==============================================================================
@@ -157,8 +157,6 @@ private:
StringArray directories; StringArray directories;
void init (const String& path); void init (const String& path);
BEAST_LEAK_DETECTOR (FileSearchPath)
}; };
#endif // BEAST_FILESEARCHPATH_BEASTHEADER #endif // BEAST_FILESEARCHPATH_BEASTHEADER

View File

@@ -30,7 +30,7 @@
/** /**
Maps a file into virtual memory for easy reading and/or writing. Maps a file into virtual memory for easy reading and/or writing.
*/ */
class BEAST_API MemoryMappedFile class BEAST_API MemoryMappedFile : LeakChecked <MemoryMappedFile>, Uncopyable
{ {
public: public:
/** The read/write flags used when opening a memory mapped file. */ /** The read/write flags used when opening a memory mapped file. */
@@ -103,8 +103,6 @@ private:
#endif #endif
void openInternal (const File&, AccessMode); void openInternal (const File&, AccessMode);
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MemoryMappedFile)
}; };

View File

@@ -65,7 +65,7 @@
@see File, FileOutputStream @see File, FileOutputStream
*/ */
class BEAST_API TemporaryFile class BEAST_API TemporaryFile : LeakChecked <TemporaryFile>, Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -159,8 +159,6 @@ public:
private: private:
//============================================================================== //==============================================================================
const File temporaryFile, targetFile; const File temporaryFile, targetFile;
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TemporaryFile)
}; };
#endif // BEAST_TEMPORARYFILE_BEASTHEADER #endif // BEAST_TEMPORARYFILE_BEASTHEADER

View File

@@ -35,7 +35,10 @@
@see Logger @see Logger
*/ */
class BEAST_API FileLogger : public Logger class BEAST_API FileLogger
: public Logger
, LeakChecked <FileLogger>
, Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -126,8 +129,6 @@ private:
CriticalSection logLock; CriticalSection logLock;
void trimFileSize (int64 maxFileSizeBytes) const; void trimFileSize (int64 maxFileSizeBytes) const;
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FileLogger)
}; };

View File

@@ -39,7 +39,7 @@ class MemoryBlock;
Negative values are possible, but the value isn't stored as 2s-complement, so Negative values are possible, but the value isn't stored as 2s-complement, so
be careful if you use negative values and look at the values of individual bits. be careful if you use negative values and look at the values of individual bits.
*/ */
class BEAST_API BigInteger class BEAST_API BigInteger : LeakChecked <BigInteger>
{ {
public: public:
//============================================================================== //==============================================================================
@@ -312,8 +312,6 @@ private:
void ensureSize (size_t numVals); void ensureSize (size_t numVals);
void shiftLeft (int bits, int startBit); void shiftLeft (int bits, int startBit);
void shiftRight (int bits, int startBit); void shiftRight (int bits, int startBit);
BEAST_LEAK_DETECTOR (BigInteger)
}; };
/** Writes a BigInteger to an OutputStream as a UTF8 decimal string. */ /** Writes a BigInteger to an OutputStream as a UTF8 decimal string. */

View File

@@ -21,7 +21,8 @@
*/ */
//============================================================================== //==============================================================================
class Expression::Term : public SingleThreadedReferenceCountedObject class Expression::Term
: public SingleThreadedReferenceCountedObject
{ {
public: public:
Term() {} Term() {}
@@ -69,9 +70,6 @@ public:
for (int i = getNumInputs(); --i >= 0;) for (int i = getNumInputs(); --i >= 0;)
getInput(i)->visitAllSymbols (visitor, scope, recursionDepth); getInput(i)->visitAllSymbols (visitor, scope, recursionDepth);
} }
private:
BEAST_DECLARE_NON_COPYABLE (Term)
}; };
@@ -295,7 +293,8 @@ struct Expression::Helpers
}; };
//============================================================================== //==============================================================================
class DotOperator : public BinaryTerm class DotOperator
: public BinaryTerm
{ {
public: public:
DotOperator (SymbolTerm* const l, Term* const r) : BinaryTerm (l, r) {} DotOperator (SymbolTerm* const l, Term* const r) : BinaryTerm (l, r) {}
@@ -345,7 +344,9 @@ struct Expression::Helpers
private: private:
//============================================================================== //==============================================================================
class EvaluationVisitor : public Scope::Visitor class EvaluationVisitor
: public Scope::Visitor
, Uncopyable
{ {
public: public:
EvaluationVisitor (const TermPtr& t, const int recursion) EvaluationVisitor (const TermPtr& t, const int recursion)
@@ -356,12 +357,11 @@ struct Expression::Helpers
const TermPtr input; const TermPtr input;
TermPtr output; TermPtr output;
const int recursionCount; const int recursionCount;
private:
BEAST_DECLARE_NON_COPYABLE (EvaluationVisitor)
}; };
class SymbolVisitingVisitor : public Scope::Visitor class SymbolVisitingVisitor
: public Scope::Visitor
, Uncopyable
{ {
public: public:
SymbolVisitingVisitor (const TermPtr& t, SymbolVisitor& v, const int recursion) SymbolVisitingVisitor (const TermPtr& t, SymbolVisitor& v, const int recursion)
@@ -373,11 +373,11 @@ struct Expression::Helpers
const TermPtr input; const TermPtr input;
SymbolVisitor& visitor; SymbolVisitor& visitor;
const int recursionCount; const int recursionCount;
BEAST_DECLARE_NON_COPYABLE (SymbolVisitingVisitor)
}; };
class SymbolRenamingVisitor : public Scope::Visitor class SymbolRenamingVisitor
: public Scope::Visitor
, Uncopyable
{ {
public: public:
SymbolRenamingVisitor (const TermPtr& t, const Expression::Symbol& symbol_, const String& newName_, const int recursionCount_) SymbolRenamingVisitor (const TermPtr& t, const Expression::Symbol& symbol_, const String& newName_, const int recursionCount_)
@@ -390,13 +390,9 @@ struct Expression::Helpers
const Symbol& symbol; const Symbol& symbol;
const String newName; const String newName;
const int recursionCount; const int recursionCount;
BEAST_DECLARE_NON_COPYABLE (SymbolRenamingVisitor)
}; };
SymbolTerm* getSymbol() const { return static_cast <SymbolTerm*> (left.get()); } SymbolTerm* getSymbol() const { return static_cast <SymbolTerm*> (left.get()); }
BEAST_DECLARE_NON_COPYABLE (DotOperator)
}; };
//============================================================================== //==============================================================================
@@ -446,7 +442,7 @@ struct Expression::Helpers
}; };
//============================================================================== //==============================================================================
class Add : public BinaryTerm class Add : public BinaryTerm
{ {
public: public:
Add (Term* const l, Term* const r) : BinaryTerm (l, r) {} Add (Term* const l, Term* const r) : BinaryTerm (l, r) {}
@@ -465,13 +461,10 @@ struct Expression::Helpers
return new Subtract (newDest, (input == left ? right : left)->clone()); return new Subtract (newDest, (input == left ? right : left)->clone());
} }
private:
BEAST_DECLARE_NON_COPYABLE (Add)
}; };
//============================================================================== //==============================================================================
class Subtract : public BinaryTerm class Subtract : public BinaryTerm
{ {
public: public:
Subtract (Term* const l, Term* const r) : BinaryTerm (l, r) {} Subtract (Term* const l, Term* const r) : BinaryTerm (l, r) {}
@@ -493,13 +486,10 @@ struct Expression::Helpers
return new Subtract (left->clone(), newDest); return new Subtract (left->clone(), newDest);
} }
private:
BEAST_DECLARE_NON_COPYABLE (Subtract)
}; };
//============================================================================== //==============================================================================
class Multiply : public BinaryTerm class Multiply : public BinaryTerm
{ {
public: public:
Multiply (Term* const l, Term* const r) : BinaryTerm (l, r) {} Multiply (Term* const l, Term* const r) : BinaryTerm (l, r) {}
@@ -518,13 +508,10 @@ struct Expression::Helpers
return new Divide (newDest, (input == left ? right : left)->clone()); return new Divide (newDest, (input == left ? right : left)->clone());
} }
private:
BEAST_DECLARE_NON_COPYABLE (Multiply)
}; };
//============================================================================== //==============================================================================
class Divide : public BinaryTerm class Divide : public BinaryTerm
{ {
public: public:
Divide (Term* const l, Term* const r) : BinaryTerm (l, r) {} Divide (Term* const l, Term* const r) : BinaryTerm (l, r) {}
@@ -546,9 +533,6 @@ struct Expression::Helpers
return new Divide (left->clone(), newDest); return new Divide (left->clone(), newDest);
} }
private:
BEAST_DECLARE_NON_COPYABLE (Divide)
}; };
//============================================================================== //==============================================================================
@@ -621,7 +605,9 @@ struct Expression::Helpers
} }
//============================================================================== //==============================================================================
class SymbolCheckVisitor : public Term::SymbolVisitor class SymbolCheckVisitor
: public Term::SymbolVisitor
, Uncopyable
{ {
public: public:
SymbolCheckVisitor (const Symbol& symbol_) : wasFound (false), symbol (symbol_) {} SymbolCheckVisitor (const Symbol& symbol_) : wasFound (false), symbol (symbol_) {}
@@ -631,12 +617,12 @@ struct Expression::Helpers
private: private:
const Symbol& symbol; const Symbol& symbol;
BEAST_DECLARE_NON_COPYABLE (SymbolCheckVisitor)
}; };
//============================================================================== //==============================================================================
class SymbolListVisitor : public Term::SymbolVisitor class SymbolListVisitor
: public Term::SymbolVisitor
, Uncopyable
{ {
public: public:
SymbolListVisitor (Array<Symbol>& list_) : list (list_) {} SymbolListVisitor (Array<Symbol>& list_) : list (list_) {}
@@ -644,12 +630,10 @@ struct Expression::Helpers
private: private:
Array<Symbol>& list; Array<Symbol>& list;
BEAST_DECLARE_NON_COPYABLE (SymbolListVisitor)
}; };
//============================================================================== //==============================================================================
class Parser class Parser : Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -908,8 +892,6 @@ struct Expression::Helpers
return e; return e;
} }
BEAST_DECLARE_NON_COPYABLE (Parser)
}; };
}; };

View File

@@ -33,7 +33,7 @@
You can create a Random object and use it to generate a sequence of random numbers. You can create a Random object and use it to generate a sequence of random numbers.
*/ */
class BEAST_API Random class BEAST_API Random : LeakChecked <Random>
{ {
public: public:
//============================================================================== //==============================================================================
@@ -127,8 +127,6 @@ public:
private: private:
//============================================================================== //==============================================================================
int64 seed; int64 seed;
BEAST_LEAK_DETECTOR (Random)
}; };

View File

@@ -29,7 +29,7 @@
/** Contains static methods for converting the byte order between different /** Contains static methods for converting the byte order between different
endiannesses. endiannesses.
*/ */
class BEAST_API ByteOrder class BEAST_API ByteOrder : Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -93,8 +93,6 @@ public:
private: private:
ByteOrder(); ByteOrder();
BEAST_DECLARE_NON_COPYABLE (ByteOrder)
}; };

View File

@@ -82,7 +82,7 @@ namespace HeapBlockHelper
@see Array, OwnedArray, MemoryBlock @see Array, OwnedArray, MemoryBlock
*/ */
template <class ElementType, bool throwOnFailure = false> template <class ElementType, bool throwOnFailure = false>
class HeapBlock class HeapBlock : Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -294,7 +294,6 @@ private:
} }
#if ! (defined (BEAST_DLL) || defined (BEAST_DLL_BUILD)) #if ! (defined (BEAST_DLL) || defined (BEAST_DLL_BUILD))
BEAST_DECLARE_NON_COPYABLE (HeapBlock)
BEAST_PREVENT_HEAP_ALLOCATION // Creating a 'new HeapBlock' would be missing the point! BEAST_PREVENT_HEAP_ALLOCATION // Creating a 'new HeapBlock' would be missing the point!
#endif #endif
}; };

View File

@@ -1,144 +0,0 @@
//------------------------------------------------------------------------------
/*
This file is part of Beast: https://github.com/vinniefalco/Beast
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
Portions of this file are from JUCE.
Copyright (c) 2013 - Raw Material Software Ltd.
Please visit http://www.juce.com
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef BEAST_LEAKEDOBJECTDETECTOR_BEASTHEADER
#define BEAST_LEAKEDOBJECTDETECTOR_BEASTHEADER
#include "../text/beast_String.h"
#include "beast_Atomic.h"
//==============================================================================
/**
Embedding an instance of this class inside another class can be used as a low-overhead
way of detecting leaked instances.
This class keeps an internal static count of the number of instances that are
active, so that when the app is shutdown and the static destructors are called,
it can check whether there are any left-over instances that may have been leaked.
To use it, use the BEAST_LEAK_DETECTOR macro as a simple way to put one in your
class declaration. Have a look through the beast codebase for examples, it's used
in most of the classes.
*/
template <class OwnerClass>
class LeakedObjectDetector
{
public:
//==============================================================================
LeakedObjectDetector() noexcept { ++(getCounter().numObjects); }
LeakedObjectDetector (const LeakedObjectDetector&) noexcept { ++(getCounter().numObjects); }
~LeakedObjectDetector()
{
if (--(getCounter().numObjects) < 0)
{
DBG ("*** Dangling pointer deletion! Class: " << getLeakedObjectClassName());
/** If you hit this, then you've managed to delete more instances of this class than you've
created.. That indicates that you're deleting some dangling pointers.
Note that although this assertion will have been triggered during a destructor, it might
not be this particular deletion that's at fault - the incorrect one may have happened
at an earlier point in the program, and simply not been detected until now.
Most errors like this are caused by using old-fashioned, non-RAII techniques for
your object management. Tut, tut. Always, always use ScopedPointers, OwnedArrays,
ReferenceCountedObjects, etc, and avoid the 'delete' operator at all costs!
*/
bassertfalse;
}
}
private:
//==============================================================================
class LeakCounter
{
public:
LeakCounter() noexcept {}
~LeakCounter()
{
if (numObjects.value > 0)
{
DBG ("*** Leaked objects detected: " << numObjects.value << " instance(s) of class " << getLeakedObjectClassName());
/** If you hit this, then you've leaked one or more objects of the type specified by
the 'OwnerClass' template parameter - the name should have been printed by the line above.
If you're leaking, it's probably because you're using old-fashioned, non-RAII techniques for
your object management. Tut, tut. Always, always use ScopedPointers, OwnedArrays,
ReferenceCountedObjects, etc, and avoid the 'delete' operator at all costs!
*/
//bassertfalse;
}
}
Atomic<int> numObjects;
};
static const char* getLeakedObjectClassName()
{
return OwnerClass::getLeakedObjectClassName();
}
static LeakCounter& getCounter() noexcept
{
static LeakCounter counter;
return counter;
}
};
//==============================================================================
#if DOXYGEN || ! defined (BEAST_LEAK_DETECTOR)
#if (DOXYGEN || BEAST_CHECK_MEMORY_LEAKS)
/** This macro lets you embed a leak-detecting object inside a class.
To use it, simply declare a BEAST_LEAK_DETECTOR(YourClassName) inside a private section
of the class declaration. E.g.
@code
class MyClass
{
public:
MyClass();
void blahBlah();
private:
BEAST_LEAK_DETECTOR (MyClass)
};
@endcode
@see BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR, LeakedObjectDetector
*/
#define BEAST_LEAK_DETECTOR(OwnerClass) \
friend class beast::LeakedObjectDetector<OwnerClass>; \
static const char* getLeakedObjectClassName() noexcept { return #OwnerClass; } \
beast::LeakedObjectDetector<OwnerClass> BEAST_JOIN_MACRO (leakDetector, __LINE__);
#else
#define BEAST_LEAK_DETECTOR(OwnerClass)
#endif
#endif
#endif // BEAST_LEAKEDOBJECTDETECTOR_BEASTHEADER

View File

@@ -65,7 +65,7 @@ inline Type* createCopyIfNotNull (const Type* pointer) { return pointer != n
/** A handy C++ wrapper that creates and deletes an NSAutoreleasePool object using RAII. /** A handy C++ wrapper that creates and deletes an NSAutoreleasePool object using RAII.
You should use the BEAST_AUTORELEASEPOOL macro to create a local auto-release pool on the stack. You should use the BEAST_AUTORELEASEPOOL macro to create a local auto-release pool on the stack.
*/ */
class BEAST_API ScopedAutoReleasePool class BEAST_API ScopedAutoReleasePool : Uncopyable
{ {
public: public:
ScopedAutoReleasePool(); ScopedAutoReleasePool();
@@ -73,8 +73,6 @@ inline Type* createCopyIfNotNull (const Type* pointer) { return pointer != n
private: private:
void* pool; void* pool;
BEAST_DECLARE_NON_COPYABLE (ScopedAutoReleasePool)
}; };
/** A macro that can be used to easily declare a local ScopedAutoReleasePool /** A macro that can be used to easily declare a local ScopedAutoReleasePool
@@ -92,30 +90,5 @@ inline Type* createCopyIfNotNull (const Type* pointer) { return pointer != n
#define BEAST_AUTORELEASEPOOL #define BEAST_AUTORELEASEPOOL
#endif #endif
//==============================================================================
/* In a Windows DLL build, we'll expose some malloc/free functions that live inside the DLL, and use these for
allocating all the objects - that way all beast objects in the DLL and in the host will live in the same heap,
avoiding problems when an object is created in one module and passed across to another where it is deleted.
By piggy-backing on the BEAST_LEAK_DETECTOR macro, these allocators can be injected into most beast classes.
*/
#if BEAST_MSVC && (defined (BEAST_DLL) || defined (BEAST_DLL_BUILD)) && ! (BEAST_DISABLE_DLL_ALLOCATORS || DOXYGEN)
extern BEAST_API void* beastDLL_malloc (size_t);
extern BEAST_API void beastDLL_free (void*);
#define BEAST_LEAK_DETECTOR(OwnerClass) public:\
static void* operator new (size_t sz) { return beast::beastDLL_malloc (sz); } \
static void* operator new (size_t, void* p) { return p; } \
static void operator delete (void* p) { beast::beastDLL_free (p); } \
static void operator delete (void*, void*) {}
#endif #endif
//==============================================================================
/** (Deprecated) This was a Windows-specific way of checking for object leaks - now please
use the BEAST_LEAK_DETECTOR instead.
*/
#ifndef beast_UseDebuggingNewOperator
#define beast_UseDebuggingNewOperator
#endif
#endif // BEAST_MEMORY_BEASTHEADER

View File

@@ -33,7 +33,7 @@
A class to hold a resizable block of raw data. A class to hold a resizable block of raw data.
*/ */
class BEAST_API MemoryBlock class BEAST_API MemoryBlock : LeakChecked <MemoryBlock>
{ {
public: public:
//============================================================================== //==============================================================================
@@ -247,8 +247,6 @@ private:
HeapBlock <char> data; HeapBlock <char> data;
size_t size; size_t size;
static const char* const encodingTable; static const char* const encodingTable;
BEAST_LEAK_DETECTOR (MemoryBlock)
}; };

View File

@@ -59,7 +59,7 @@
@see ReferenceCountedObjectPtr, ReferenceCountedArray, SingleThreadedReferenceCountedObject @see ReferenceCountedObjectPtr, ReferenceCountedArray, SingleThreadedReferenceCountedObject
*/ */
class BEAST_API ReferenceCountedObject class BEAST_API ReferenceCountedObject : Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -114,8 +114,6 @@ protected:
private: private:
//============================================================================== //==============================================================================
Atomic <int> refCount; Atomic <int> refCount;
BEAST_DECLARE_NON_COPYABLE (ReferenceCountedObject)
}; };
@@ -130,7 +128,7 @@ private:
@see ReferenceCountedObject, ReferenceCountedObjectPtr, ReferenceCountedArray @see ReferenceCountedObject, ReferenceCountedObjectPtr, ReferenceCountedArray
*/ */
class BEAST_API SingleThreadedReferenceCountedObject class BEAST_API SingleThreadedReferenceCountedObject : public Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -175,8 +173,6 @@ protected:
private: private:
//============================================================================== //==============================================================================
int refCount; int refCount;
BEAST_DECLARE_NON_COPYABLE (SingleThreadedReferenceCountedObject)
}; };

View File

@@ -62,7 +62,7 @@
you'd need to return a raw pointer (or use a std::auto_ptr instead). you'd need to return a raw pointer (or use a std::auto_ptr instead).
*/ */
template <class ObjectType> template <class ObjectType>
class ScopedPointer class ScopedPointer : Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -215,7 +215,6 @@ private:
It's probably best to use the latter form when writing your object declarations anyway, as It's probably best to use the latter form when writing your object declarations anyway, as
this is a better representation of the code that you actually want the compiler to produce. this is a better representation of the code that you actually want the compiler to produce.
*/ */
BEAST_DECLARE_NON_COPYABLE (ScopedPointer)
#endif #endif
}; };

View File

@@ -120,26 +120,19 @@ char Storage <ObjectType, Tag>::s_storage [sizeof (ObjectType)];
class Initializer class Initializer
{ {
public: public:
/*
bool inited () const
{
return m_state.get () == stateInitialized;
}
*/
// If the condition is not initialized, the first caller will // If the condition is not initialized, the first caller will
// receive true, while concurrent callers get blocked until // receive true, while concurrent callers get blocked until
// initialization completes. // initialization completes.
// //
bool begin () bool beginConstruction ()
{ {
bool shouldInitialize; bool needsInitialization = false;
if (m_state.get () == stateUninitialized) if (m_state.get () != stateInitialized)
{ {
if (m_state.compareAndSetBool (stateInitializing, stateUninitialized)) if (m_state.compareAndSetBool (stateInitializing, stateUninitialized))
{ {
shouldInitialize = true; needsInitialization = true;
} }
else else
{ {
@@ -150,21 +143,15 @@ public:
delay.pause (); delay.pause ();
} }
while (m_state.get () != stateInitialized); while (m_state.get () != stateInitialized);
shouldInitialize = false;
} }
} }
else
{
shouldInitialize = false;
}
return shouldInitialize; return needsInitialization;
} }
// Called to signal that the initialization is complete // Called to signal that the initialization is complete
// //
void end () void endConstruction ()
{ {
m_state.set (stateInitialized); m_state.set (stateInitialized);
} }

View File

@@ -20,10 +20,39 @@
#ifndef BEAST_UNCOPYABLE_BEASTHEADER #ifndef BEAST_UNCOPYABLE_BEASTHEADER
#define BEAST_UNCOPYABLE_BEASTHEADER #define BEAST_UNCOPYABLE_BEASTHEADER
// Prevents warnings about missing copy /** Prevent copy construction and assignment.
// constructors and assignment operators.
// Ideas based on boost This is used to suppress warnings and prevent unsafe operations on
objects which cannot be passed by value. Ideas based on Boost.
For example, instead of
@code
class MyClass
{
public:
//...
private:
MyClass (const MyClass&);
MyClass& operator= (const MyClass&);
};
@endcode
..you can just write:
@code
class MyClass : Uncopyable
{
public:
//...
};
@endcode
*/
class Uncopyable class Uncopyable
{ {
protected: protected:

View File

@@ -128,7 +128,9 @@ public:
in your code! in your code!
@see WeakReference @see WeakReference
*/ */
class SharedPointer : public ReferenceCountingType class SharedPointer
: public ReferenceCountingType
, Uncopyable
{ {
public: public:
explicit SharedPointer (ObjectType* const obj) noexcept : owner (obj) {} explicit SharedPointer (ObjectType* const obj) noexcept : owner (obj) {}
@@ -138,8 +140,6 @@ public:
private: private:
ObjectType* volatile owner; ObjectType* volatile owner;
BEAST_DECLARE_NON_COPYABLE (SharedPointer)
}; };
typedef ReferenceCountedObjectPtr<SharedPointer> SharedRef; typedef ReferenceCountedObjectPtr<SharedPointer> SharedRef;
@@ -150,7 +150,7 @@ public:
See the WeakReference class notes for an example of how to use this class. See the WeakReference class notes for an example of how to use this class.
@see WeakReference @see WeakReference
*/ */
class Master class Master : Uncopyable
{ {
public: public:
Master() noexcept {} Master() noexcept {}
@@ -192,8 +192,6 @@ public:
private: private:
SharedRef sharedPointer; SharedRef sharedPointer;
BEAST_DECLARE_NON_COPYABLE (Master)
}; };
private: private:

View File

@@ -37,7 +37,7 @@
The class includes methods for saving the ID as a string or as raw binary data. The class includes methods for saving the ID as a string or as raw binary data.
*/ */
class BEAST_API Uuid class BEAST_API Uuid : LeakChecked <Uuid>
{ {
public: public:
//============================================================================== //==============================================================================
@@ -101,8 +101,6 @@ public:
private: private:
//============================================================================== //==============================================================================
uint8 uuid[16]; uint8 uuid[16];
BEAST_LEAK_DETECTOR (Uuid)
}; };

View File

@@ -30,7 +30,7 @@
Contains some static helper functions for manipulating the MS Windows registry Contains some static helper functions for manipulating the MS Windows registry
(Only available on Windows, of course!) (Only available on Windows, of course!)
*/ */
class WindowsRegistry class WindowsRegistry : Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -112,7 +112,6 @@ public:
private: private:
WindowsRegistry(); WindowsRegistry();
BEAST_DECLARE_NON_COPYABLE (WindowsRegistry)
}; };
#endif #endif

View File

@@ -148,7 +148,7 @@ bool File::moveToTrash() const
} }
//============================================================================== //==============================================================================
class DirectoryIterator::NativeIterator::Pimpl class DirectoryIterator::NativeIterator::Pimpl : Uncopyable
{ {
public: public:
Pimpl (const File& directory, const String& wildCard_) Pimpl (const File& directory, const String& wildCard_)
@@ -202,8 +202,6 @@ public:
private: private:
String parentDir, wildCard; String parentDir, wildCard;
DIR* dir; DIR* dir;
BEAST_DECLARE_NON_COPYABLE (Pimpl)
}; };

View File

@@ -167,7 +167,7 @@ namespace
} }
//============================================================================== //==============================================================================
class JNIClassBase class JNIClassBase : Uncopyable
{ {
public: public:
explicit JNIClassBase (const char* classPath); explicit JNIClassBase (const char* classPath);
@@ -193,8 +193,6 @@ private:
static Array<JNIClassBase*>& getClasses(); static Array<JNIClassBase*>& getClasses();
void initialise (JNIEnv*); void initialise (JNIEnv*);
void release (JNIEnv*); void release (JNIEnv*);
BEAST_DECLARE_NON_COPYABLE (JNIClassBase)
}; };
//============================================================================== //==============================================================================

View File

@@ -60,7 +60,10 @@ bool Process::openEmailWithAttachments (const String& targetEmailAddress,
//============================================================================== //==============================================================================
class WebInputStream : public InputStream class WebInputStream
: public InputStream
, LeakChecked <WebInputStream>
, Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -154,9 +157,6 @@ public:
//============================================================================== //==============================================================================
GlobalRef stream; GlobalRef stream;
private:
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WebInputStream)
}; };
InputStream* URL::createNativeStream (const String& address, bool isPost, const MemoryBlock& postData, InputStream* URL::createNativeStream (const String& address, bool isPost, const MemoryBlock& postData,

View File

@@ -241,7 +241,7 @@ bool File::moveToTrash() const
} }
//============================================================================== //==============================================================================
class DirectoryIterator::NativeIterator::Pimpl class DirectoryIterator::NativeIterator::Pimpl : Uncopyable
{ {
public: public:
Pimpl (const File& directory, const String& wildCard_) Pimpl (const File& directory, const String& wildCard_)
@@ -295,8 +295,6 @@ public:
private: private:
String parentDir, wildCard; String parentDir, wildCard;
DIR* dir; DIR* dir;
BEAST_DECLARE_NON_COPYABLE (Pimpl)
}; };
DirectoryIterator::NativeIterator::NativeIterator (const File& directory, const String& wildCard) DirectoryIterator::NativeIterator::NativeIterator (const File& directory, const String& wildCard)

View File

@@ -60,7 +60,9 @@ bool Process::openEmailWithAttachments (const String& /* targetEmailAddress */,
//============================================================================== //==============================================================================
class WebInputStream : public InputStream class WebInputStream
: public InputStream
, LeakChecked <WebInputStream>
{ {
public: public:
WebInputStream (const String& address_, bool isPost_, const MemoryBlock& postData_, WebInputStream (const String& address_, bool isPost_, const MemoryBlock& postData_,
@@ -439,8 +441,6 @@ private:
return String::empty; return String::empty;
} }
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WebInputStream)
}; };
InputStream* URL::createNativeStream (const String& address, bool isPost, const MemoryBlock& postData, InputStream* URL::createNativeStream (const String& address, bool isPost, const MemoryBlock& postData,

View File

@@ -241,7 +241,7 @@ bool File::moveToTrash() const
} }
//============================================================================== //==============================================================================
class DirectoryIterator::NativeIterator::Pimpl class DirectoryIterator::NativeIterator::Pimpl : Uncopyable
{ {
public: public:
Pimpl (const File& directory, const String& wildCard_) Pimpl (const File& directory, const String& wildCard_)
@@ -295,8 +295,6 @@ public:
private: private:
String parentDir, wildCard; String parentDir, wildCard;
DIR* dir; DIR* dir;
BEAST_DECLARE_NON_COPYABLE (Pimpl)
}; };
DirectoryIterator::NativeIterator::NativeIterator (const File& directory, const String& wildCard) DirectoryIterator::NativeIterator::NativeIterator (const File& directory, const String& wildCard)

View File

@@ -62,7 +62,10 @@ bool Process::openEmailWithAttachments (const String& /* targetEmailAddress */,
//============================================================================== //==============================================================================
class WebInputStream : public InputStream class WebInputStream
: public InputStream
, LeakChecked <WebInputStream>
, Uncopyable
{ {
public: public:
WebInputStream (const String& address_, bool isPost_, const MemoryBlock& postData_, WebInputStream (const String& address_, bool isPost_, const MemoryBlock& postData_,
@@ -441,8 +444,6 @@ private:
return String::empty; return String::empty;
} }
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WebInputStream)
}; };
InputStream* URL::createNativeStream (const String& address, bool isPost, const MemoryBlock& postData, InputStream* URL::createNativeStream (const String& address, bool isPost, const MemoryBlock& postData,

View File

@@ -308,7 +308,7 @@ bool File::moveToTrash() const
} }
//============================================================================== //==============================================================================
class DirectoryIterator::NativeIterator::Pimpl class DirectoryIterator::NativeIterator::Pimpl : Uncopyable
{ {
public: public:
Pimpl (const File& directory, const String& wildCard_) Pimpl (const File& directory, const String& wildCard_)
@@ -364,8 +364,6 @@ public:
private: private:
String parentDir, wildCard; String parentDir, wildCard;
NSDirectoryEnumerator* enumerator; NSDirectoryEnumerator* enumerator;
BEAST_DECLARE_NON_COPYABLE (Pimpl)
}; };
DirectoryIterator::NativeIterator::NativeIterator (const File& directory, const String& wildcard) DirectoryIterator::NativeIterator::NativeIterator (const File& directory, const String& wildcard)

View File

@@ -97,7 +97,10 @@ bool Process::openEmailWithAttachments (const String& targetEmailAddress,
} }
//============================================================================== //==============================================================================
class URLConnectionState : public Thread class URLConnectionState
: public Thread
, LeakChecked <URLConnectionState>
, Uncopyable
{ {
public: public:
URLConnectionState (NSURLRequest* req) URLConnectionState (NSURLRequest* req)
@@ -290,13 +293,14 @@ private:
getState (self)->finishedLoading(); getState (self)->finishedLoading();
} }
}; };
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (URLConnectionState)
}; };
//============================================================================== //==============================================================================
class WebInputStream : public InputStream class WebInputStream
: public InputStream
, LeakChecked <WebInputStream>
, Uncopyable
{ {
public: public:
WebInputStream (const String& address_, bool isPost_, const MemoryBlock& postData_, WebInputStream (const String& address_, bool isPost_, const MemoryBlock& postData_,
@@ -411,8 +415,6 @@ private:
connection = nullptr; connection = nullptr;
} }
} }
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WebInputStream)
}; };
InputStream* URL::createNativeStream (const String& address, bool isPost, const MemoryBlock& postData, InputStream* URL::createNativeStream (const String& address, bool isPost, const MemoryBlock& postData,

View File

@@ -64,7 +64,7 @@ struct NSObjectRetainer
//============================================================================== //==============================================================================
template <typename SuperclassType> template <typename SuperclassType>
struct ObjCClass struct ObjCClass : Uncopyable
{ {
ObjCClass (const char* nameRoot) ObjCClass (const char* nameRoot)
: cls (objc_allocateClassPair ([SuperclassType class], getRandomisedName (nameRoot).toUTF8(), 0)) : cls (objc_allocateClassPair ([SuperclassType class], getRandomisedName (nameRoot).toUTF8(), 0))
@@ -145,8 +145,6 @@ private:
{ {
return root + String::toHexString (beast::Random::getSystemRandom().nextInt64()); return root + String::toHexString (beast::Random::getSystemRandom().nextInt64());
} }
BEAST_DECLARE_NON_COPYABLE (ObjCClass)
}; };

View File

@@ -21,7 +21,7 @@
*/ */
//============================================================================== //==============================================================================
class NamedPipe::Pimpl class NamedPipe::Pimpl : LeakChecked <Pimpl>, Uncopyable
{ {
public: public:
Pimpl (const String& pipePath, bool createPipe) Pimpl (const String& pipePath, bool createPipe)
@@ -164,8 +164,6 @@ private:
select (handle + 1, &rset, nullptr, 0, &timeout); select (handle + 1, &rset, nullptr, 0, &timeout);
} }
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Pimpl)
}; };
void NamedPipe::close() void NamedPipe::close()

View File

@@ -973,7 +973,7 @@ void* DynamicLibrary::getFunction (const String& functionName) noexcept
//============================================================================== //==============================================================================
class ChildProcess::ActiveProcess class ChildProcess::ActiveProcess : LeakChecked <ActiveProcess>, Uncopyable
{ {
public: public:
ActiveProcess (const StringArray& arguments) ActiveProcess (const StringArray& arguments)
@@ -1066,8 +1066,6 @@ public:
private: private:
int pipeHandle; int pipeHandle;
FILE* readHandle; FILE* readHandle;
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ActiveProcess)
}; };
bool ChildProcess::start (const String& command) bool ChildProcess::start (const String& command)
@@ -1104,7 +1102,7 @@ bool ChildProcess::kill()
} }
//============================================================================== //==============================================================================
struct HighResolutionTimer::Pimpl struct HighResolutionTimer::Pimpl : Uncopyable
{ {
Pimpl (HighResolutionTimer& t) : owner (t), thread (0), shouldStop (false) Pimpl (HighResolutionTimer& t) : owner (t), thread (0), shouldStop (false)
{ {
@@ -1250,6 +1248,4 @@ private:
#endif #endif
} }
BEAST_DECLARE_NON_COPYABLE (Pimpl)
}; };

View File

@@ -628,6 +628,8 @@ bool File::createLink (const String& description, const File& linkFileToCreate)
//============================================================================== //==============================================================================
class DirectoryIterator::NativeIterator::Pimpl class DirectoryIterator::NativeIterator::Pimpl
: LeakChecked <DirectoryIterator::NativeIterator::Pimpl>
, Uncopyable
{ {
public: public:
Pimpl (const File& directory, const String& wildCard) Pimpl (const File& directory, const String& wildCard)
@@ -677,8 +679,6 @@ public:
private: private:
const String directoryWithWildCard; const String directoryWithWildCard;
HANDLE handle; HANDLE handle;
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Pimpl)
}; };
DirectoryIterator::NativeIterator::NativeIterator (const File& directory, const String& wildCard) DirectoryIterator::NativeIterator::NativeIterator (const File& directory, const String& wildCard)
@@ -731,7 +731,7 @@ void File::revealToUser() const
} }
//============================================================================== //==============================================================================
class NamedPipe::Pimpl class NamedPipe::Pimpl : LeakChecked <NamedPipe::Pimpl>, Uncopyable
{ {
public: public:
Pimpl (const String& pipeName, const bool createPipe) Pimpl (const String& pipeName, const bool createPipe)
@@ -914,8 +914,6 @@ private:
CancelIo (pipeH); CancelIo (pipeH);
return false; return false;
} }
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Pimpl)
}; };
void NamedPipe::close() void NamedPipe::close()

View File

@@ -30,7 +30,9 @@
#endif #endif
//============================================================================== //==============================================================================
class WebInputStream : public InputStream class WebInputStream
: public InputStream
, LeakChecked <WebInputStream>
{ {
public: public:
WebInputStream (const String& address_, bool isPost_, const MemoryBlock& postData_, WebInputStream (const String& address_, bool isPost_, const MemoryBlock& postData_,
@@ -296,8 +298,6 @@ private:
close(); close();
} }
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WebInputStream)
}; };
InputStream* URL::createNativeStream (const String& address, bool isPost, const MemoryBlock& postData, InputStream* URL::createNativeStream (const String& address, bool isPost, const MemoryBlock& postData,

View File

@@ -21,7 +21,7 @@
*/ */
//============================================================================== //==============================================================================
struct RegistryKeyWrapper struct RegistryKeyWrapper : Uncopyable
{ {
RegistryKeyWrapper (String name, const bool createForWriting, const DWORD wow64Flags) RegistryKeyWrapper (String name, const bool createForWriting, const DWORD wow64Flags)
: key (0), wideCharValueName (nullptr) : key (0), wideCharValueName (nullptr)
@@ -130,8 +130,6 @@ struct RegistryKeyWrapper
HKEY key; HKEY key;
const wchar_t* wideCharValueName; const wchar_t* wideCharValueName;
String valueName; String valueName;
BEAST_DECLARE_NON_COPYABLE (RegistryKeyWrapper)
}; };
uint32 WindowsRegistry::getBinaryValue (const String& regValuePath, MemoryBlock& result) uint32 WindowsRegistry::getBinaryValue (const String& regValuePath, MemoryBlock& result)

View File

@@ -459,7 +459,7 @@ void InterProcessLock::exit()
} }
//============================================================================== //==============================================================================
class ChildProcess::ActiveProcess class ChildProcess::ActiveProcess : LeakChecked <ChildProcess::ActiveProcess>, Uncopyable
{ {
public: public:
ActiveProcess (const String& command) ActiveProcess (const String& command)
@@ -549,8 +549,6 @@ public:
private: private:
HANDLE readPipe, writePipe; HANDLE readPipe, writePipe;
PROCESS_INFORMATION processInfo; PROCESS_INFORMATION processInfo;
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ActiveProcess)
}; };
bool ChildProcess::start (const String& command) bool ChildProcess::start (const String& command)
@@ -584,7 +582,7 @@ bool ChildProcess::kill()
} }
//============================================================================== //==============================================================================
struct HighResolutionTimer::Pimpl struct HighResolutionTimer::Pimpl : Uncopyable
{ {
Pimpl (HighResolutionTimer& t) noexcept : owner (t), periodMs (0) Pimpl (HighResolutionTimer& t) noexcept : owner (t), periodMs (0)
{ {
@@ -631,6 +629,4 @@ private:
if (timer->periodMs != 0) if (timer->periodMs != 0)
timer->owner.hiResTimerCallback(); timer->owner.hiResTimerCallback();
} }
BEAST_DECLARE_NON_COPYABLE (Pimpl)
}; };

View File

@@ -34,7 +34,7 @@
@see InterprocessConnection @see InterprocessConnection
*/ */
class BEAST_API NamedPipe class BEAST_API NamedPipe : LeakChecked <NamedPipe>, Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -92,8 +92,6 @@ private:
ReadWriteLock lock; ReadWriteLock lock;
bool openInternal (const String& pipeName, const bool createPipe); bool openInternal (const String& pipeName, const bool createPipe);
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NamedPipe)
}; };

View File

@@ -36,7 +36,7 @@
@see DatagramSocket, InterprocessConnection, InterprocessConnectionServer @see DatagramSocket, InterprocessConnection, InterprocessConnectionServer
*/ */
class BEAST_API StreamingSocket class BEAST_API StreamingSocket : LeakChecked <StreamingSocket>, Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -163,8 +163,6 @@ private:
bool connected, isListener; bool connected, isListener;
StreamingSocket (const String& hostname, int portNumber, int handle); StreamingSocket (const String& hostname, int portNumber, int handle);
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (StreamingSocket)
}; };
@@ -177,7 +175,7 @@ private:
@see StreamingSocket, InterprocessConnection, InterprocessConnectionServer @see StreamingSocket, InterprocessConnection, InterprocessConnectionServer
*/ */
class BEAST_API DatagramSocket class BEAST_API DatagramSocket : LeakChecked <DatagramSocket>, Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -294,8 +292,6 @@ private:
void* serverAddress; void* serverAddress;
DatagramSocket (const String& hostname, int portNumber, int handle, int localPortNumber); DatagramSocket (const String& hostname, int portNumber, int handle, int localPortNumber);
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DatagramSocket)
}; };

View File

@@ -37,7 +37,7 @@ class XmlElement;
This class can be used to launch URLs in browsers, and also to create This class can be used to launch URLs in browsers, and also to create
InputStreams that can read from remote http or ftp sources. InputStreams that can read from remote http or ftp sources.
*/ */
class BEAST_API URL class BEAST_API URL : LeakChecked <URL>
{ {
public: public:
//============================================================================== //==============================================================================
@@ -338,7 +338,6 @@ private:
OpenStreamProgressCallback* progressCallback, OpenStreamProgressCallback* progressCallback,
void* progressCallbackContext, const String& headers, void* progressCallbackContext, const String& headers,
const int timeOutMs, StringPairArray* responseHeaders); const int timeOutMs, StringPairArray* responseHeaders);
BEAST_LEAK_DETECTOR (URL)
}; };

View File

@@ -37,7 +37,9 @@
so that the source stream gets accessed in larger chunk sizes, meaning less so that the source stream gets accessed in larger chunk sizes, meaning less
work for the underlying stream. work for the underlying stream.
*/ */
class BEAST_API BufferedInputStream : public InputStream class BEAST_API BufferedInputStream
: public InputStream
, LeakChecked <BufferedInputStream>
{ {
public: public:
//============================================================================== //==============================================================================
@@ -84,8 +86,6 @@ private:
int64 position, lastReadPos, bufferStart, bufferOverlap; int64 position, lastReadPos, bufferStart, bufferOverlap;
HeapBlock <char> buffer; HeapBlock <char> buffer;
void ensureBuffered(); void ensureBuffered();
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BufferedInputStream)
}; };
#endif // BEAST_BUFFEREDINPUTSTREAM_BEASTHEADER #endif // BEAST_BUFFEREDINPUTSTREAM_BEASTHEADER

View File

@@ -34,7 +34,10 @@
@see InputSource @see InputSource
*/ */
class BEAST_API FileInputSource : public InputSource class BEAST_API FileInputSource
: public InputSource
, LeakChecked <FileInputSource>
, Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -56,8 +59,6 @@ private:
//============================================================================== //==============================================================================
const File file; const File file;
bool useFileTimeInHashGeneration; bool useFileTimeInHashGeneration;
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FileInputSource)
}; };

View File

@@ -35,7 +35,7 @@
@see FileInputSource @see FileInputSource
*/ */
class BEAST_API InputSource class BEAST_API InputSource : LeakChecked <InputSource>
{ {
public: public:
//============================================================================== //==============================================================================
@@ -63,11 +63,6 @@ public:
/** Returns a hash code that uniquely represents this item. /** Returns a hash code that uniquely represents this item.
*/ */
virtual int64 hashCode() const = 0; virtual int64 hashCode() const = 0;
private:
//==============================================================================
BEAST_LEAK_DETECTOR (InputSource)
}; };

View File

@@ -37,6 +37,8 @@ class MemoryBlock;
@see OutputStream, MemoryInputStream, BufferedInputStream, FileInputStream @see OutputStream, MemoryInputStream, BufferedInputStream, FileInputStream
*/ */
class BEAST_API InputStream class BEAST_API InputStream
: public Uncopyable
, LeakChecked <InputStream>
{ {
public: public:
/** Destructor. */ /** Destructor. */
@@ -285,9 +287,6 @@ public:
protected: protected:
//============================================================================== //==============================================================================
InputStream() noexcept {} InputStream() noexcept {}
private:
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (InputStream)
}; };
#endif // BEAST_INPUTSTREAM_BEASTHEADER #endif // BEAST_INPUTSTREAM_BEASTHEADER

View File

@@ -35,7 +35,9 @@
This can either be used to refer to a shared block of memory, or can make its This can either be used to refer to a shared block of memory, or can make its
own internal copy of the data when the MemoryInputStream is created. own internal copy of the data when the MemoryInputStream is created.
*/ */
class BEAST_API MemoryInputStream : public InputStream class BEAST_API MemoryInputStream
: public InputStream
, LeakChecked <MemoryInputStream>
{ {
public: public:
//============================================================================== //==============================================================================
@@ -88,8 +90,6 @@ private:
HeapBlock<char> internalCopy; HeapBlock<char> internalCopy;
void createInternalCopy(); void createInternalCopy();
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MemoryInputStream)
}; };
#endif // BEAST_MEMORYINPUTSTREAM_BEASTHEADER #endif // BEAST_MEMORYINPUTSTREAM_BEASTHEADER

View File

@@ -36,7 +36,9 @@
The data that was written into the stream can then be accessed later as The data that was written into the stream can then be accessed later as
a contiguous block of memory. a contiguous block of memory.
*/ */
class BEAST_API MemoryOutputStream : public OutputStream class BEAST_API MemoryOutputStream
: public OutputStream
, LeakChecked <MemoryOutputStream>
{ {
public: public:
//============================================================================== //==============================================================================
@@ -120,8 +122,6 @@ private:
void trimExternalBlockSize(); void trimExternalBlockSize();
char* prepareToWrite (size_t); char* prepareToWrite (size_t);
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MemoryOutputStream)
}; };
/** Copies all the data that has been written to a MemoryOutputStream into another stream. */ /** Copies all the data that has been written to a MemoryOutputStream into another stream. */

View File

@@ -41,6 +41,8 @@ class File;
@see InputStream, MemoryOutputStream, FileOutputStream @see InputStream, MemoryOutputStream, FileOutputStream
*/ */
class BEAST_API OutputStream class BEAST_API OutputStream
: public Uncopyable
, LeakChecked <OutputStream>
{ {
protected: protected:
//============================================================================== //==============================================================================
@@ -220,8 +222,6 @@ public:
private: private:
//============================================================================== //==============================================================================
String newLineString; String newLineString;
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OutputStream)
}; };
//============================================================================== //==============================================================================

View File

@@ -34,7 +34,9 @@
This lets you take a subsection of a stream and present it as an entire This lets you take a subsection of a stream and present it as an entire
stream in its own right. stream in its own right.
*/ */
class BEAST_API SubregionStream : public InputStream class BEAST_API SubregionStream
: public InputStream
, LeakChecked <SubregionStream>
{ {
public: public:
//============================================================================== //==============================================================================
@@ -80,8 +82,6 @@ public:
private: private:
OptionalScopedPointer<InputStream> source; OptionalScopedPointer<InputStream> source;
const int64 startPositionInSourceStream, lengthOfSourceStream; const int64 startPositionInSourceStream, lengthOfSourceStream;
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SubregionStream)
}; };
#endif // BEAST_SUBREGIONSTREAM_BEASTHEADER #endif // BEAST_SUBREGIONSTREAM_BEASTHEADER

View File

@@ -141,41 +141,6 @@ template <> struct BeastStaticAssert <true> { static void dummy() {} };
*/ */
#define static_bassert(expression) beast::BeastStaticAssert<expression>::dummy(); #define static_bassert(expression) beast::BeastStaticAssert<expression>::dummy();
/** This is a shorthand macro for declaring stubs for a class's copy constructor and operator=.
For example, instead of
@code
class MyClass
{
etc..
private:
MyClass (const MyClass&);
MyClass& operator= (const MyClass&);
};@endcode
..you can just write:
@code
class MyClass
{
etc..
private:
BEAST_DECLARE_NON_COPYABLE (MyClass)
};@endcode
*/
#define BEAST_DECLARE_NON_COPYABLE(className) \
className (const className&);\
className& operator= (const className&);
/** This is a shorthand way of writing both a BEAST_DECLARE_NON_COPYABLE and
BEAST_LEAK_DETECTOR macro for a class.
*/
#define BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className) \
BEAST_DECLARE_NON_COPYABLE(className) \
BEAST_LEAK_DETECTOR(className)
/** This macro can be added to class definitions to disable the use of new/delete to /** This macro can be added to class definitions to disable the use of new/delete to
allocate the object on the heap, forcing it to only be used as a stack or member variable. allocate the object on the heap, forcing it to only be used as a stack or member variable.
*/ */

View File

@@ -58,6 +58,7 @@
#include <algorithm> #include <algorithm>
#include <cfloat> #include <cfloat>
#include <climits> #include <climits>
#include <cmath>
#include <cstdarg> #include <cstdarg>
#include <cstddef> #include <cstddef>
#include <cstdio> #include <cstdio>
@@ -178,14 +179,7 @@ extern BEAST_API bool BEAST_CALLTYPE beast_isRunningUnderDebugger();
extern BEAST_API void BEAST_CALLTYPE logAssertion (char const* file, int line) noexcept; extern BEAST_API void BEAST_CALLTYPE logAssertion (char const* file, int line) noexcept;
// These are so common that we include them early // These are so common that we include them early
// ?
#include "../memory/beast_Uncopyable.h"
#include "../memory/beast_Memory.h"
#include "../maths/beast_MathsFunctions.h"
#include "../memory/beast_ByteOrder.h"
#include "../logging/beast_Logger.h"
#include "../memory/beast_LeakedObjectDetector.h"
} }
#endif #endif

View File

@@ -30,7 +30,7 @@
/** /**
Contains methods for finding out about the current hardware and OS configuration. Contains methods for finding out about the current hardware and OS configuration.
*/ */
class BEAST_API SystemStats class BEAST_API SystemStats : Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -194,8 +194,6 @@ private:
SystemStats(); SystemStats();
static const CPUFlags& getCPUFlags(); static const CPUFlags& getCPUFlags();
BEAST_DECLARE_NON_COPYABLE (SystemStats)
}; };

View File

@@ -70,7 +70,7 @@
get a list of all the messages by searching for the TRANS() macro in the Beast source get a list of all the messages by searching for the TRANS() macro in the Beast source
code). code).
*/ */
class BEAST_API LocalisedStrings class BEAST_API LocalisedStrings : LeakChecked <LocalisedStrings>
{ {
public: public:
//============================================================================== //==============================================================================
@@ -176,8 +176,6 @@ private:
StringPairArray translations; StringPairArray translations;
void loadFromText (const String&, bool ignoreCase); void loadFromText (const String&, bool ignoreCase);
BEAST_LEAK_DETECTOR (LocalisedStrings)
}; };
//============================================================================== //==============================================================================

View File

@@ -34,7 +34,7 @@
@see String, StringPairArray @see String, StringPairArray
*/ */
class BEAST_API StringArray class BEAST_API StringArray : LeakChecked <StringArray>
{ {
public: public:
//============================================================================== //==============================================================================
@@ -396,10 +396,7 @@ public:
private: private:
//==============================================================================
Array <String> strings; Array <String> strings;
BEAST_LEAK_DETECTOR (StringArray)
}; };

View File

@@ -33,7 +33,7 @@
@see StringArray @see StringArray
*/ */
class BEAST_API StringPairArray class BEAST_API StringPairArray : LeakChecked <StringPairArray>
{ {
public: public:
//============================================================================== //==============================================================================
@@ -150,8 +150,6 @@ private:
//============================================================================== //==============================================================================
StringArray keys, values; StringArray keys, values;
bool ignoreCase; bool ignoreCase;
BEAST_LEAK_DETECTOR (StringPairArray)
}; };

View File

@@ -32,7 +32,7 @@
This class lets you launch an executable, and read its output. You can also This class lets you launch an executable, and read its output. You can also
use it to check whether the child process has finished. use it to check whether the child process has finished.
*/ */
class BEAST_API ChildProcess class BEAST_API ChildProcess : LeakChecked <ChildProcess>, Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -92,8 +92,6 @@ private:
class ActiveProcess; class ActiveProcess;
friend class ScopedPointer<ActiveProcess>; friend class ScopedPointer<ActiveProcess>;
ScopedPointer<ActiveProcess> activeProcess; ScopedPointer<ActiveProcess> activeProcess;
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ChildProcess)
}; };

View File

@@ -37,7 +37,7 @@
@see ScopedLock, ScopedTryLock, ScopedUnlock, SpinLock, ReadWriteLock, Thread, InterProcessLock @see ScopedLock, ScopedTryLock, ScopedUnlock, SpinLock, ReadWriteLock, Thread, InterProcessLock
*/ */
class BEAST_API CriticalSection class BEAST_API CriticalSection : Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -111,8 +111,6 @@ private:
#else #else
mutable pthread_mutex_t internal; mutable pthread_mutex_t internal;
#endif #endif
BEAST_DECLARE_NON_COPYABLE (CriticalSection)
}; };
@@ -126,7 +124,7 @@ private:
@see CriticalSection, Array, OwnedArray, ReferenceCountedArray @see CriticalSection, Array, OwnedArray, ReferenceCountedArray
*/ */
class BEAST_API DummyCriticalSection class BEAST_API DummyCriticalSection : Uncopyable
{ {
public: public:
inline DummyCriticalSection() noexcept {} inline DummyCriticalSection() noexcept {}
@@ -145,9 +143,6 @@ public:
/** A dummy scoped-unlocker type to use with a dummy critical section. */ /** A dummy scoped-unlocker type to use with a dummy critical section. */
typedef ScopedLockType ScopedUnlockType; typedef ScopedLockType ScopedUnlockType;
private:
BEAST_DECLARE_NON_COPYABLE (DummyCriticalSection)
}; };
//============================================================================== //==============================================================================

View File

@@ -31,7 +31,7 @@
Since the DLL is freed when this object is deleted, it's handy for managing Since the DLL is freed when this object is deleted, it's handy for managing
library lifetimes using RAII. library lifetimes using RAII.
*/ */
class BEAST_API DynamicLibrary class BEAST_API DynamicLibrary : LeakChecked <DynamicLibrary>, Uncopyable
{ {
public: public:
/** Creates an unopened DynamicLibrary object. /** Creates an unopened DynamicLibrary object.
@@ -72,8 +72,6 @@ public:
private: private:
void* handle; void* handle;
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DynamicLibrary)
}; };

View File

@@ -38,7 +38,7 @@
@see Timer @see Timer
*/ */
class BEAST_API HighResolutionTimer class BEAST_API HighResolutionTimer : LeakChecked <HighResolutionTimer>, Uncopyable
{ {
protected: protected:
/** Creates a HighResolutionTimer. /** Creates a HighResolutionTimer.
@@ -96,8 +96,6 @@ private:
friend struct Pimpl; friend struct Pimpl;
friend class ScopedPointer<Pimpl>; friend class ScopedPointer<Pimpl>;
ScopedPointer<Pimpl> pimpl; ScopedPointer<Pimpl> pimpl;
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (HighResolutionTimer)
}; };

View File

@@ -34,7 +34,7 @@
@see CriticalSection @see CriticalSection
*/ */
class BEAST_API InterProcessLock class BEAST_API InterProcessLock : Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -71,7 +71,7 @@ public:
@see ScopedLock @see ScopedLock
*/ */
class ScopedLockType class ScopedLockType : Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -106,8 +106,6 @@ public:
//============================================================================== //==============================================================================
InterProcessLock& ipLock; InterProcessLock& ipLock;
bool lockWasSuccessful; bool lockWasSuccessful;
BEAST_DECLARE_NON_COPYABLE (ScopedLockType)
}; };
private: private:
@@ -118,8 +116,6 @@ private:
CriticalSection lock; CriticalSection lock;
String name; String name;
BEAST_DECLARE_NON_COPYABLE (InterProcessLock)
}; };

View File

@@ -35,7 +35,7 @@
@see Thread, BEASTApplication @see Thread, BEASTApplication
*/ */
class BEAST_API Process class BEAST_API Process : Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -138,7 +138,6 @@ public:
private: private:
Process(); Process();
BEAST_DECLARE_NON_COPYABLE (Process)
}; };

View File

@@ -50,7 +50,7 @@
@see ScopedReadLock, ScopedWriteLock, CriticalSection @see ScopedReadLock, ScopedWriteLock, CriticalSection
*/ */
class BEAST_API ReadWriteLock class BEAST_API ReadWriteLock : Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -146,8 +146,6 @@ private:
}; };
mutable Array <ThreadRecursionCount> readerThreads; mutable Array <ThreadRecursionCount> readerThreads;
BEAST_DECLARE_NON_COPYABLE (ReadWriteLock)
}; };

View File

@@ -51,7 +51,7 @@
@see GenericScopedUnlock, CriticalSection, SpinLock, ScopedLock, ScopedUnlock @see GenericScopedUnlock, CriticalSection, SpinLock, ScopedLock, ScopedUnlock
*/ */
template <class LockType> template <class LockType>
class GenericScopedLock class GenericScopedLock : Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -76,8 +76,6 @@ public:
private: private:
//============================================================================== //==============================================================================
const LockType& lock_; const LockType& lock_;
BEAST_DECLARE_NON_COPYABLE (GenericScopedLock)
}; };
@@ -120,7 +118,7 @@ private:
@see GenericScopedLock, CriticalSection, ScopedLock, ScopedUnlock @see GenericScopedLock, CriticalSection, ScopedLock, ScopedUnlock
*/ */
template <class LockType> template <class LockType>
class GenericScopedUnlock class GenericScopedUnlock : Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -149,8 +147,6 @@ public:
private: private:
//============================================================================== //==============================================================================
const LockType& lock_; const LockType& lock_;
BEAST_DECLARE_NON_COPYABLE (GenericScopedUnlock)
}; };
@@ -190,7 +186,7 @@ private:
@see CriticalSection::tryEnter, GenericScopedLock, GenericScopedUnlock @see CriticalSection::tryEnter, GenericScopedLock, GenericScopedUnlock
*/ */
template <class LockType> template <class LockType>
class GenericScopedTryLock class GenericScopedTryLock : Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -224,8 +220,6 @@ private:
//============================================================================== //==============================================================================
const LockType& lock_; const LockType& lock_;
const bool lockWasSuccessful; const bool lockWasSuccessful;
BEAST_DECLARE_NON_COPYABLE (GenericScopedTryLock)
}; };

View File

@@ -50,7 +50,7 @@
@see ReadWriteLock, ScopedWriteLock @see ReadWriteLock, ScopedWriteLock
*/ */
class BEAST_API ScopedReadLock class BEAST_API ScopedReadLock : Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -79,8 +79,6 @@ public:
private: private:
//============================================================================== //==============================================================================
const ReadWriteLock& lock_; const ReadWriteLock& lock_;
BEAST_DECLARE_NON_COPYABLE (ScopedReadLock)
}; };

View File

@@ -50,7 +50,7 @@
@see ReadWriteLock, ScopedReadLock @see ReadWriteLock, ScopedReadLock
*/ */
class BEAST_API ScopedWriteLock class BEAST_API ScopedWriteLock : Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -79,8 +79,6 @@ public:
private: private:
//============================================================================== //==============================================================================
const ReadWriteLock& lock_; const ReadWriteLock& lock_;
BEAST_DECLARE_NON_COPYABLE (ScopedWriteLock)
}; };

View File

@@ -0,0 +1,29 @@
//------------------------------------------------------------------------------
/*
This file is part of Beast: https://github.com/vinniefalco/Beast
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
SpinDelay::SpinDelay ()
: m_count (0)
{
}
void SpinDelay::pause ()
{
if (++m_count > 20)
Thread::yield ();
}

View File

@@ -20,22 +20,14 @@
#ifndef BEAST_SPINDELAY_BEASTHEADER #ifndef BEAST_SPINDELAY_BEASTHEADER
#define BEAST_SPINDELAY_BEASTHEADER #define BEAST_SPINDELAY_BEASTHEADER
// /** A simple delay used to synchronize threads.
// Synchronization element */
//
class BEAST_API SpinDelay class BEAST_API SpinDelay
{ {
public: public:
SpinDelay () : m_count (0) SpinDelay ();
{
}
inline void pause () void pause ();
{
if (++m_count > 20)
Thread::yield ();
}
private: private:
int m_count; int m_count;

View File

@@ -40,7 +40,7 @@
@see CriticalSection @see CriticalSection
*/ */
class BEAST_API SpinLock class BEAST_API SpinLock : Uncopyable
{ {
public: public:
inline SpinLock() noexcept {} inline SpinLock() noexcept {}
@@ -80,8 +80,6 @@ public:
private: private:
//============================================================================== //==============================================================================
mutable Atomic<int> lock; mutable Atomic<int> lock;
BEAST_DECLARE_NON_COPYABLE (SpinLock)
}; };

View File

@@ -48,14 +48,12 @@ Thread::~Thread()
//============================================================================== //==============================================================================
// Use a ref-counted object to hold this shared data, so that it can outlive its static // Use a ref-counted object to hold this shared data, so that it can outlive its static
// shared pointer when threads are still running during static shutdown. // shared pointer when threads are still running during static shutdown.
struct CurrentThreadHolder : public ReferenceCountedObject struct CurrentThreadHolder : public ReferenceCountedObject
{ {
CurrentThreadHolder() noexcept {} CurrentThreadHolder() noexcept {}
typedef ReferenceCountedObjectPtr <CurrentThreadHolder> Ptr; typedef ReferenceCountedObjectPtr <CurrentThreadHolder> Ptr;
ThreadLocalValue<Thread*> value; ThreadLocalValue<Thread*> value;
BEAST_DECLARE_NON_COPYABLE (CurrentThreadHolder)
}; };
static char currentThreadHolderLock [sizeof (SpinLock)]; // (statically initialised to zeros). static char currentThreadHolderLock [sizeof (SpinLock)]; // (statically initialised to zeros).

View File

@@ -42,7 +42,7 @@
@see CriticalSection, WaitableEvent, Process, ThreadWithProgressWindow, @see CriticalSection, WaitableEvent, Process, ThreadWithProgressWindow,
MessageManagerLock MessageManagerLock
*/ */
class BEAST_API Thread class BEAST_API Thread : LeakChecked <Thread>, Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -280,8 +280,6 @@ private:
void killThread(); void killThread();
void threadEntryPoint(); void threadEntryPoint();
static bool setThreadPriority (void*, int); static bool setThreadPriority (void*, int);
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Thread)
}; };
#endif // BEAST_THREAD_BEASTHEADER #endif // BEAST_THREAD_BEASTHEADER

View File

@@ -51,7 +51,7 @@
is deleted. is deleted.
*/ */
template <typename Type> template <typename Type>
class ThreadLocalValue class ThreadLocalValue : Uncopyable
{ {
public: public:
/** */ /** */
@@ -170,7 +170,7 @@ public:
private: private:
//============================================================================== //==============================================================================
#if BEAST_NO_COMPILER_THREAD_LOCAL #if BEAST_NO_COMPILER_THREAD_LOCAL
struct ObjectHolder struct ObjectHolder : Uncopyable
{ {
ObjectHolder (const Thread::ThreadID& tid) ObjectHolder (const Thread::ThreadID& tid)
: threadId (tid), object() : threadId (tid), object()
@@ -179,15 +179,11 @@ private:
Thread::ThreadID threadId; Thread::ThreadID threadId;
ObjectHolder* next; ObjectHolder* next;
Type object; Type object;
BEAST_DECLARE_NON_COPYABLE (ObjectHolder)
}; };
mutable Atomic<ObjectHolder*> first; mutable Atomic<ObjectHolder*> first;
SpinLock lock; SpinLock lock;
#endif #endif
BEAST_DECLARE_NON_COPYABLE (ThreadLocalValue)
}; };

View File

@@ -53,7 +53,9 @@ void ThreadPoolJob::signalJobShouldExit()
} }
//============================================================================== //==============================================================================
class ThreadPool::ThreadPoolThread : public Thread class ThreadPool::ThreadPoolThread
: public Thread
, LeakChecked <ThreadPoolThread>
{ {
public: public:
ThreadPoolThread (ThreadPool& pool_) ThreadPoolThread (ThreadPool& pool_)
@@ -73,8 +75,6 @@ public:
private: private:
ThreadPool& pool; ThreadPool& pool;
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ThreadPoolThread)
}; };
//============================================================================== //==============================================================================

View File

@@ -46,7 +46,7 @@ class ThreadPoolThread;
@see ThreadPool, Thread @see ThreadPool, Thread
*/ */
class BEAST_API ThreadPoolJob class BEAST_API ThreadPoolJob : LeakChecked <ThreadPoolJob>, Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -125,8 +125,6 @@ private:
String jobName; String jobName;
ThreadPool* pool; ThreadPool* pool;
bool shouldStop, isActive, shouldBeDeleted; bool shouldStop, isActive, shouldBeDeleted;
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ThreadPoolJob)
}; };
@@ -139,7 +137,7 @@ private:
@see ThreadPoolJob, Thread @see ThreadPoolJob, Thread
*/ */
class BEAST_API ThreadPool class BEAST_API ThreadPool : LeakChecked <ThreadPool>, Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -305,8 +303,6 @@ private:
// Note that this method has changed, and no longer has a parameter to indicate // Note that this method has changed, and no longer has a parameter to indicate
// whether the jobs should be deleted - see the new method for details. // whether the jobs should be deleted - see the new method for details.
void removeAllJobs (bool, int, bool); void removeAllJobs (bool, int, bool);
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ThreadPool)
}; };

View File

@@ -79,7 +79,9 @@ private:
@see TimeSliceClient, Thread @see TimeSliceClient, Thread
*/ */
class BEAST_API TimeSliceThread : public Thread class BEAST_API TimeSliceThread
: public Thread
, LeakChecked <TimeSliceThread>
{ {
public: public:
//============================================================================== //==============================================================================
@@ -139,8 +141,6 @@ private:
TimeSliceClient* clientBeingCalled; TimeSliceClient* clientBeingCalled;
TimeSliceClient* getNextClient (int index) const; TimeSliceClient* getNextClient (int index) const;
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TimeSliceThread)
}; };

View File

@@ -35,7 +35,7 @@
calling thread until another thread wakes it up by calling the signal() calling thread until another thread wakes it up by calling the signal()
method. method.
*/ */
class BEAST_API WaitableEvent class BEAST_API WaitableEvent : LeakChecked <WaitableEvent>, Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -106,8 +106,6 @@ private:
mutable pthread_mutex_t mutex; mutable pthread_mutex_t mutex;
mutable bool triggered, manualReset; mutable bool triggered, manualReset;
#endif #endif
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WaitableEvent)
}; };

View File

@@ -67,7 +67,7 @@ class UnitTestRunner;
@see UnitTestRunner @see UnitTestRunner
*/ */
class BEAST_API UnitTest class BEAST_API UnitTest : Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -164,8 +164,6 @@ private:
//============================================================================== //==============================================================================
const String name; const String name;
UnitTestRunner* runner; UnitTestRunner* runner;
BEAST_DECLARE_NON_COPYABLE (UnitTest)
}; };
@@ -181,7 +179,7 @@ private:
@see UnitTest @see UnitTest
*/ */
class BEAST_API UnitTestRunner class BEAST_API UnitTestRunner : Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -277,8 +275,6 @@ private:
void addPass(); void addPass();
void addFail (const String& failureMessage); void addFail (const String& failureMessage);
BEAST_DECLARE_NON_COPYABLE (UnitTestRunner)
}; };

View File

@@ -67,7 +67,7 @@ class InputSource;
@see XmlElement @see XmlElement
*/ */
class BEAST_API XmlDocument class BEAST_API XmlDocument : LeakChecked <XmlDocument>, Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -173,8 +173,6 @@ private:
String expandEntity (const String& entity); String expandEntity (const String& entity);
String expandExternalEntity (const String& entity); String expandExternalEntity (const String& entity);
String getParameterEntity (const String& entity); String getParameterEntity (const String& entity);
BEAST_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (XmlDocument)
}; };

Some files were not shown because too many files have changed in this diff Show More