Mixe for Privacy and Anonymity in the Internet
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CAThreadList Class Reference

#include <CAThreadList.hpp>

Collaboration diagram for CAThreadList:

Public Member Functions

 CAThreadList ()
 
 ~CAThreadList ()
 
SINT32 put (const CAThread *const thread)
 
SINT32 remove (const CAThread *const thread)
 
SINT32 waitAndRemoveAll ()
 Waits for finishing of all threads in list and removes them. More...
 
void showAll () const
 
UINT32 getSize () const
 

Private Member Functions

void removeAll ()
 

Private Attributes

UINT32 m_Size
 
thread_list_entry_tm_pHead
 
CAMutexm_pListLock
 

Detailed Description

Definition at line 44 of file CAThreadList.hpp.

Constructor & Destructor Documentation

◆ CAThreadList()

CAThreadList::CAThreadList ( )
Author
Simon Pecher, JonDos GmbH

Definition at line 40 of file CAThreadList.cpp.

41 {
42  m_pHead = NULL;
43  m_Size=0;
44  m_pListLock = new CAMutex();
45 }
thread_list_entry_t * m_pHead
CAMutex * m_pListLock

References m_pHead, m_pListLock, and m_Size.

◆ ~CAThreadList()

CAThreadList::~CAThreadList ( )

Definition at line 47 of file CAThreadList.cpp.

48 {
49  m_pListLock->lock();
50  removeAll();
52 
53  delete m_pListLock;
54  m_pListLock = NULL;
55 }
SINT32 unlock()
Definition: CAMutex.hpp:52
SINT32 lock()
Definition: CAMutex.hpp:41

References CAMutex::lock(), m_pListLock, removeAll(), and CAMutex::unlock().

Here is the call graph for this function:

Member Function Documentation

◆ getSize()

UINT32 CAThreadList::getSize ( ) const
inline

Definition at line 60 of file CAThreadList.hpp.

61  {
62  return m_Size;
63  }

References m_Size.

◆ put()

SINT32 CAThreadList::put ( const CAThread *const  thread)

Definition at line 59 of file CAThreadList.cpp.

60 {
61  m_pListLock->lock();
63 
64  new_entry->tle_thread = (CAThread* const)thread;
65  new_entry->tle_next = m_pHead;
66  m_pHead = new_entry;
67  m_Size++;
69 
70  return E_SUCCESS;
71 }
struct thread_list_entry thread_list_entry_t
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2
CAThread * tle_thread
struct thread_list_entry * tle_next

References E_SUCCESS, CAMutex::lock(), m_pHead, m_pListLock, m_Size, thread_list_entry::tle_next, thread_list_entry::tle_thread, and CAMutex::unlock().

Referenced by CACryptoBenchmark::doBenchmark().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ remove()

SINT32 CAThreadList::remove ( const CAThread *const  thread)

Definition at line 73 of file CAThreadList.cpp.

74 {
75  SINT32 ret=E_SUCCESS;
76 
77  m_pListLock->lock();
78  thread_list_entry_t* iterator=m_pHead;
79  thread_list_entry_t* prev=NULL;
80 
81  while (iterator!=NULL)
82  {
83  if(iterator->tle_thread->getID() == thread->getID())
84  {
85  if(prev != NULL)
86  {
87  //unchain
88  prev->tle_next = iterator->tle_next;
89  }
90  else
91  {
92  //Head holds the corresponding thread;
93  m_pHead = iterator->tle_next;
94  }
95  //dispose the entry
96  delete iterator;
97  iterator = NULL;
98  m_Size--;
99  break;
100  }
101  prev = iterator;
102  iterator = iterator->tle_next;
103  };
104 
105  m_pListLock->unlock();
106  return ret;
107 }
signed int SINT32
Definition: basetypedefs.h:132
UINT32 getID() const
Definition: CAThread.hpp:196

References E_SUCCESS, CAThread::getID(), CAMutex::lock(), m_pHead, m_pListLock, m_Size, thread_list_entry::tle_next, thread_list_entry::tle_thread, and CAMutex::unlock().

Here is the call graph for this function:

◆ removeAll()

void CAThreadList::removeAll ( )
private

Definition at line 152 of file CAThreadList.cpp.

153 {
154  thread_list_entry_t* iterator=NULL;
155 
156  while(m_pHead != NULL)
157  {
158  iterator=m_pHead->tle_next;
159 
160  CAMsg::printMsg(LOG_INFO, "CAThreadList::removeAll: Thread %s, id %u\n",
162  m_pHead->tle_thread->getID());
163  delete m_pHead;
164  m_pHead=iterator;
165  }
166 
167  m_pHead = NULL;
168  m_Size=0;
169  }
static SINT32 printMsg(UINT32 typ, const char *format,...)
Writes a given message to the log.
Definition: CAMsg.cpp:251
UINT8 * getName() const
Definition: CAThread.hpp:191

References CAThread::getID(), CAThread::getName(), m_pHead, m_Size, CAMsg::printMsg(), thread_list_entry::tle_next, and thread_list_entry::tle_thread.

Referenced by ~CAThreadList().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ showAll()

void CAThreadList::showAll ( ) const

Definition at line 129 of file CAThreadList.cpp.

130 {
131  m_pListLock->lock();
132 
133  if(m_pHead == NULL)
134  {
135  CAMsg::printMsg(LOG_INFO, "CAThreadList::showAll: list is empty, no threads found\n");
136  m_pListLock->unlock();
137  return;
138  }
139 
140  thread_list_entry_t *iterator = m_pHead;
141  do
142  {
143  CAMsg::printMsg(LOG_INFO, "CAThreadList::showAll: Thread %s, id %u\n",
144  iterator->tle_thread->getName(),
145  iterator->tle_thread->getID());
146  iterator = iterator->tle_next;
147  } while(iterator != NULL);
148  m_pListLock->unlock();
149 }

References CAThread::getID(), CAThread::getName(), CAMutex::lock(), m_pHead, m_pListLock, CAMsg::printMsg(), thread_list_entry::tle_next, thread_list_entry::tle_thread, and CAMutex::unlock().

Here is the call graph for this function:

◆ waitAndRemoveAll()

SINT32 CAThreadList::waitAndRemoveAll ( )

Waits for finishing of all threads in list and removes them.

The memory of each CAThread object is freed.

Definition at line 172 of file CAThreadList.cpp.

173 {
174  thread_list_entry_t* iterator = NULL;
175 
176  while (m_pHead != NULL)
177  {
178  iterator = m_pHead->tle_next;
179 #ifdef _DEBUG
180  CAMsg::printMsg(LOG_INFO, "CAThreadList::waitAndRemoveAll: Thread %s, id %u\n",
182  m_pHead->tle_thread->getID());
183 #endif
184  m_pHead->tle_thread->join();
185  delete m_pHead->tle_thread;
186  delete m_pHead;
187  m_pHead = iterator;
188  }
189 
190  m_pHead = NULL;
191  m_Size = 0;
192  return E_SUCCESS;
193 }
SINT32 join()
Waits for the main function to finish execution.
Definition: CAThread.cpp:187

References E_SUCCESS, CAThread::getID(), CAThread::getName(), CAThread::join(), m_pHead, m_Size, CAMsg::printMsg(), thread_list_entry::tle_next, and thread_list_entry::tle_thread.

Referenced by CACryptoBenchmark::doBenchmark().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_pHead

thread_list_entry_t* CAThreadList::m_pHead
private

Definition at line 70 of file CAThreadList.hpp.

Referenced by CAThreadList(), put(), remove(), removeAll(), showAll(), and waitAndRemoveAll().

◆ m_pListLock

CAMutex* CAThreadList::m_pListLock
private

Definition at line 71 of file CAThreadList.hpp.

Referenced by CAThreadList(), put(), remove(), showAll(), and ~CAThreadList().

◆ m_Size

UINT32 CAThreadList::m_Size
private

Definition at line 69 of file CAThreadList.hpp.

Referenced by CAThreadList(), getSize(), put(), remove(), removeAll(), and waitAndRemoveAll().


The documentation for this class was generated from the following files: