#include <casgarbage.h>
Public Member Functions | |
| CASGarbage (const CASGarbage &wdc) | |
| Copy constructor. | |
| CASGarbage () | |
| Constructor. | |
| CASGarbage & | operator= (const CASGarbage &wdc) |
| Assignment operator. | |
| void | Put (const std::list< CASObject * > &l) |
Adds the CASObject listed in a list to the garbage. | |
| void | Put (const std::vector< CASObject * > &v) |
Adds the CASObject listed in a vector to the garbage. | |
| void | Put (CASObject *o) |
Adds a single object CASObject to the garbage. | |
| void * | Trasher () |
| The function which is called from the thread wrapper function. | |
| ~CASGarbage () | |
| Destructor. | |
Private Member Functions | |
| void | CheckRetVal (int rv, std::string fname) |
| Throws an exception according to the return value. | |
| void | CreateTrasherThread () |
| Creates the trasher thread. | |
| void | RemoveDuplicate () |
| Removes duplicate object addresses from the garbage vector. | |
| void | TerminateTrasherThread () |
| Signals the termination of the thread. | |
Private Attributes | |
| pthread_cond_t | cond_var |
| Conditional variable for garbage processing. | |
| std::vector< CASObject * > | list |
Vector holding the CASObject to be trashed. | |
| const unsigned long | min_casobjects |
The threshold of CASObject in the garbage vector. | |
| pthread_mutex_t | mutex |
| Mutex. | |
| pthread_mutexattr_t | mutex_attr |
| Mutex attribute. | |
| pthread_attr_t | pattr |
| Stores the thread attribute. | |
| pthread_t | tid |
| Holds the thread ID. | |
| bool | time_to_die |
| Indicates whether the thread has to end. | |
| bool | trasher_thread_created |
| Indicates whether or not the trasher thread has been created. | |
CASObject must not call CASGarbage::Put(). Deadlocks would occur.
The approach is fairly simple: It has a vector which holds the CASObject which are no longer used and have been put to the garbage. A thread will be signaled by putting the objects to the garbage to check the garbage. After reaching a certain threshold of objects on the garbage, the thread will delete them from memory when signalled.
CASGarbage is intended to be used as a static class, since each instance will create a new thread. This is avoided by making it a static class.
EDoesNotApply when called.
Definition at line 81 of file casgarbage.h.
pthread_cond_t CASGarbage::cond_var [private] |
Conditional variable for garbage processing.
Definition at line 119 of file casgarbage.h.
std::vector<CASObject*> CASGarbage::list [private] |
Vector holding the CASObject to be trashed.
Definition at line 139 of file casgarbage.h.
const unsigned long CASGarbage::min_casobjects [private] |
Defines the threshold of CASObject which have to be in the garbage vector, in order to trash them.
Definition at line 89 of file casgarbage.h.
pthread_mutex_t CASGarbage::mutex [private] |
Mutex to preserve integrity of list.
Definition at line 113 of file casgarbage.h.
pthread_mutexattr_t CASGarbage::mutex_attr [private] |
Mutex attribute.
Definition at line 107 of file casgarbage.h.
pthread_attr_t CASGarbage::pattr [private] |
Stores the thread attribute.
Definition at line 101 of file casgarbage.h.
pthread_t CASGarbage::tid [private] |
Holds the thread ID.
Definition at line 95 of file casgarbage.h.
bool CASGarbage::time_to_die [private] |
Indicates whether the thread has to end.
Definition at line 125 of file casgarbage.h.
bool CASGarbage::trasher_thread_created [private] |
Indicates whether or not the trasher thread has been created.
Definition at line 133 of file casgarbage.h.
1.4.7