#include <safecoll.h>
Public Member Functions | |
Construction | |
PSafeCollection (PCollection *collection) | |
~PSafeCollection () | |
Protected Member Functions | |
void | SafeRemoveObject (PSafeObject *obj) |
PDECLARE_NOTIFIER (PTimer, PSafeCollection, DeleteObjectsTimeout) | |
Protected Attributes | |
PCollection * | collection |
PMutex | collectionMutex |
BOOL | deleteObjects |
PList< PSafeObject > | toBeRemoved |
PMutex | removalMutex |
PTimer | deleteObjectsTimer |
Friends | |
class | PSafePtrBase |
Operations | |
| |
virtual void | RemoveAll (BOOL synchronous=FALSE) |
void | AllowDeleteObjects (BOOL yes=TRUE) |
void | DisallowDeleteObjects () |
virtual BOOL | DeleteObjectsToBeRemoved () |
virtual void | DeleteObject (PObject *object) const |
virtual void | SetAutoDeleteObjects () |
PINDEX | GetSize () const |
BOOL | IsEmpty () const |
const PMutex & | GetMutex () const |
virtual BOOL | SafeRemove (PSafeObject *obj) |
virtual BOOL | SafeRemoveAt (PINDEX idx) |
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.
void PSafeCollection::AllowDeleteObjects | ( | BOOL | yes = TRUE |
) | [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.
virtual void PSafeCollection::DeleteObject | ( | PObject * | object | ) | const [virtual] |
Delete an objects that has been removed.
virtual BOOL PSafeCollection::DeleteObjectsToBeRemoved | ( | ) | [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.
void PSafeCollection::DisallowDeleteObjects | ( | ) | [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.
const PMutex& PSafeCollection::GetMutex | ( | ) | const [inline] |
Get the mutex for the collection.
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().
BOOL PSafeCollection::IsEmpty | ( | ) | const [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().
PSafeCollection::PDECLARE_NOTIFIER | ( | PTimer | , | |
PSafeCollection | , | |||
DeleteObjectsTimeout | ||||
) | [protected] |
virtual void PSafeCollection::RemoveAll | ( | BOOL | synchronous = FALSE |
) | [virtual] |
Remove all objects in collection.
synchronous | Wait till objects are deleted before returning |
virtual BOOL PSafeCollection::SafeRemove | ( | PSafeObject * | obj | ) | [protected, virtual] |
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(), PSafeDictionaryBase< PDictionary< Key, Base >, Key, Base >::RemoveAt(), and PSafeDictionaryBase< PDictionary< Key, Base >, Key, Base >::SetAt().
virtual BOOL PSafeCollection::SafeRemoveAt | ( | PINDEX | idx | ) | [protected, virtual] |
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().
void PSafeCollection::SafeRemoveObject | ( | PSafeObject * | obj | ) | [protected] |
virtual void PSafeCollection::SetAutoDeleteObjects | ( | ) | [virtual] |
Start a timer to automatically call DeleteObjectsToBeRemoved().
friend class PSafePtrBase [friend] |
PCollection* PSafeCollection::collection [protected] |
Referenced by PSafeColl< PArray< Base >, Base >::Append(), PSafeDictionaryBase< PDictionary< Key, Base >, Key, Base >::Contains(), PSafeDictionaryBase< PDictionary< Key, Base >, Key, Base >::FindWithLock(), PSafeColl< PArray< Base >, Base >::FindWithLock(), PSafeDictionaryBase< PDictionary< Key, Base >, Key, Base >::RemoveAt(), and PSafeDictionaryBase< PDictionary< Key, Base >, Key, Base >::SetAt().
PMutex PSafeCollection::collectionMutex [mutable, protected] |
Referenced by PSafeColl< PArray< Base >, Base >::Append(), PSafeDictionaryBase< PDictionary< Key, Base >, Key, Base >::Contains(), PSafeDictionaryBase< PDictionary< Key, Base >, Key, Base >::FindWithLock(), PSafeColl< PArray< Base >, Base >::FindWithLock(), GetMutex(), PSafeDictionaryBase< PDictionary< Key, Base >, Key, Base >::RemoveAt(), and PSafeDictionaryBase< PDictionary< Key, Base >, Key, Base >::SetAt().
BOOL PSafeCollection::deleteObjects [protected] |
Referenced by AllowDeleteObjects(), and DisallowDeleteObjects().
PTimer PSafeCollection::deleteObjectsTimer [protected] |
PMutex PSafeCollection::removalMutex [protected] |
PList<PSafeObject> PSafeCollection::toBeRemoved [protected] |