PTLib
Version 2.14.3
|
This class defines a thread-safe collection of objects. More...
#include <safecoll.h>
Public Member Functions | |
Construction | |
PSafeCollection (PCollection *collection) | |
Create a thread safe collection of objects. More... | |
~PSafeCollection () | |
Destroy the thread safe collection. More... | |
![]() | |
unsigned | GetTraceContextIdentifier () const |
Get PTRACE context identifier. More... | |
void | SetTraceContextIdentifier (unsigned id) |
void | GetTraceContextIdentifier (PObject &obj) |
void | GetTraceContextIdentifier (PObject *obj) |
void | SetTraceContextIdentifier (const PObject &obj) |
void | SetTraceContextIdentifier (const PObject *obj) |
virtual | ~PObject () |
virtual PObject * | Clone () const |
Create a copy of the class on the heap. More... | |
template<class CLS > | |
CLS * | CloneAs () const |
As for Clone() but converts to specified type. More... | |
virtual PINDEX | HashFunction () const |
This function yields a hash value required by the PDictionary class. More... | |
virtual const char * | GetClass (unsigned ancestor=0) const |
Get the current dynamic type of the object instance. More... | |
PBoolean | IsClass (const char *cls) const |
virtual PBoolean | InternalIsDescendant (const char *clsName) const |
Determine if the dynamic type of the current instance is a descendent of the specified class. More... | |
__inline const PObject * | PTraceObjectInstance () const |
virtual Comparison | Compare (const PObject &obj) const |
Compare the two objects and return their relative rank. More... | |
virtual Comparison | CompareObjectMemoryDirect (const PObject &obj) const |
Determine the byte wise comparison of two objects. More... | |
bool | operator== (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator!= (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator< (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator> (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator<= (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator>= (const PObject &obj) const |
Compare the two objects. More... | |
virtual void | ReadFrom (istream &strm) |
Input the contents of the object from the stream. More... | |
Protected Member Functions | |
void | CopySafeCollection (PCollection *other) |
void | CopySafeDictionary (PAbstractDictionary *other) |
bool | SafeAddObject (PSafeObject *obj, PSafeObject *old) |
void | SafeRemoveObject (PSafeObject *obj) |
PDECLARE_NOTIFIER (PTimer, PSafeCollection, DeleteObjectsTimeout) | |
![]() | |
PObject () | |
Constructor for PObject, made protected so cannot ever create one on its own. More... | |
Protected Attributes | |
PCollection * | collection |
PMutex | collectionMutex |
bool | deleteObjects |
PList< PSafeObject > | toBeRemoved |
PMutex | removalMutex |
PTimer * | m_deleteObjectsTimer |
![]() | |
unsigned | m_traceContextIdentifier |
Operations | |
virtual void | PrintOn (ostream &strm) const |
Output the contents of the object to the stream. More... | |
virtual void | RemoveAll (PBoolean synchronous=false) |
Remove all objects in collection. More... | |
void | AllowDeleteObjects (PBoolean yes=true) |
Disallow the automatic delete any objects that have been removed. More... | |
void | DisallowDeleteObjects () |
Disallow the automatic delete any objects that have been removed. More... | |
virtual PBoolean | DeleteObjectsToBeRemoved () |
Delete any objects that have been removed. More... | |
virtual void | DeleteObject (PObject *object) const |
Delete an objects that has been removed. More... | |
virtual void | SetAutoDeleteObjects () |
Start a timer to automatically call DeleteObjectsToBeRemoved(). More... | |
PINDEX | GetSize () const |
Get the current size of the collection. More... | |
PBoolean | IsEmpty () const |
Determine if the collection is empty. More... | |
const PMutex & | GetMutex () const |
Get the mutex for the collection. More... | |
PMutex & | GetMutex () |
virtual PBoolean | SafeRemove (PSafeObject *obj) |
Remove an object to the collection. More... | |
virtual PBoolean | SafeRemoveAt (PINDEX idx) |
Remove an object to the collection. More... | |
Additional Inherited Members | |
![]() | |
enum | Comparison { LessThan = -1, EqualTo = 0, GreaterThan = 1 } |
Result of the comparison operation performed by the Compare() function. More... | |
![]() | |
static const char * | Class () |
Get the name of the class as a C string. More... | |
static __inline const PObject * | PTraceObjectInstance (const char *) |
static __inline const PObject * | PTraceObjectInstance (const PObject *obj) |
static Comparison | InternalCompareObjectMemoryDirect (const PObject *obj1, const PObject *obj2, PINDEX size) |
Internal function caled from CompareObjectMemoryDirect() More... | |
![]() |
This class defines a thread-safe collection of objects.
This class is a wrapper around a standard PCollection class which allows only safe, mutexed, access to the collection.
This is part of a set of classes to solve the general problem of a collection (eg a PList or PDictionary) of objects that needs to be a made thread safe. Any thread can add, read, write or remove an object with both the object and the database of objects itself kept thread safe.
See the PSafeObject class for more details. Especially in regard to enumeration of collections.
PSafeCollection::PSafeCollection | ( | PCollection * | collection | ) |
Create a thread safe collection of objects.
Note the collection is automatically deleted on destruction.
collection | Actual collection of objects |
PSafeCollection::~PSafeCollection | ( | ) |
Destroy the thread safe collection.
The will delete the collection object provided in the constructor.
|
inline |
Disallow the automatic delete any objects that have been removed.
Objects are simply removed from the collection and not marked for deletion using PSafeObject::SafeRemove() and DeleteObject().
yes | New value for flag for deleting objects |
References deleteObjects.
|
protected |
|
protected |
|
virtual |
Delete an objects that has been removed.
|
virtual |
Delete any objects that have been removed.
Returns true if all objects in the collection have been removed and their pending deletions carried out.
|
inline |
Disallow the automatic delete any objects that have been removed.
Objects are simply removed from the collection and not marked for deletion using PSafeObject::SafeRemove() and DeleteObject().
References deleteObjects.
|
inline |
Get the mutex for the collection.
References collectionMutex.
|
inline |
References collectionMutex.
PINDEX PSafeCollection::GetSize | ( | ) | const |
Get the current size of the collection.
Note that usefulness of this function is limited as it is merely an instantaneous snapshot of the state of the collection.
Referenced by IsEmpty().
|
inline |
Determine if the collection is empty.
Note that usefulness of this function is limited as it is merely an instantaneous snapshot of the state of the collection.
References GetSize().
|
protected |
|
virtual |
Output the contents of the object to the stream.
The exact output is dependent on the exact semantics of the descendent class. This is primarily used by the standard operator<<
function.
The default behaviour is to print the class name.
Reimplemented from PObject.
|
virtual |
Remove all objects in collection.
synchronous | Wait till objects are deleted before returning |
Referenced by PSafeColl< PArray< Base >, Base >::operator=(), and PSafeDictionaryBase< PDictionary< K, D >, K, D >::operator=().
|
protected |
|
protectedvirtual |
Remove an object to the collection.
This function removes the object from the collection itself, but does not actually delete the object. It simply moves the object to a list of objects to be garbage collected at a later time.
As for Append() full mutual exclusion locking on the collection itself is maintained.
obj | Object to remove from collection |
Referenced by PSafeColl< PArray< Base >, Base >::Remove(), and PSafeDictionaryBase< PDictionary< K, D >, K, D >::RemoveAt().
|
protectedvirtual |
Remove an object to the collection.
This function removes the object from the collection itself, but does not actually delete the object. It simply moves the object to a list of objects to be garbage collected at a later time.
As for Append() full mutual exclusion locking on the collection itself is maintained.
idx | Object index to remove |
Referenced by PSafeColl< PArray< Base >, Base >::RemoveAt().
|
protected |
|
virtual |
Start a timer to automatically call DeleteObjectsToBeRemoved().
|
protected |
Referenced by PSafeColl< PArray< Base >, Base >::Append(), PSafeColl< PArray< Base >, Base >::FindWithLock(), PSafeColl< PArray< Base >, Base >::operator=(), PSafeDictionaryBase< PDictionary< K, D >, K, D >::operator=(), PSafeColl< PArray< Base >, Base >::PSafeColl(), and PSafeDictionaryBase< PDictionary< K, D >, K, D >::PSafeDictionaryBase().
|
mutableprotected |
Referenced by PSafeColl< PArray< Base >, Base >::Append(), PSafeDictionaryBase< PDictionary< K, D >, K, D >::Contains(), PSafeColl< PArray< Base >, Base >::FindWithLock(), PSafeDictionaryBase< PDictionary< K, D >, K, D >::FindWithLock(), PSafeDictionaryBase< PDictionary< K, D >, K, D >::GetKeys(), GetMutex(), PSafeDictionaryBase< PDictionary< K, D >, K, D >::Move(), PSafeColl< PArray< Base >, Base >::operator=(), PSafeDictionaryBase< PDictionary< K, D >, K, D >::operator=(), PSafeColl< PArray< Base >, Base >::PSafeColl(), PSafeDictionaryBase< PDictionary< K, D >, K, D >::PSafeDictionaryBase(), PSafeDictionaryBase< PDictionary< K, D >, K, D >::RemoveAt(), and PSafeDictionaryBase< PDictionary< K, D >, K, D >::SetAt().
|
protected |
Referenced by AllowDeleteObjects(), and DisallowDeleteObjects().
|
protected |
|
protected |
|
protected |