Mixe for Privacy and Anonymity in the Internet
CAThreadList.cpp
Go to the documentation of this file.
1
/*
2
Copyright (c) The JAP-Team, JonDos GmbH
3
4
All rights reserved.
5
6
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7
8
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9
* Redistributions in binary form must reproduce the above copyright notice,
10
this list of conditions and the following disclaimer in the documentation and/or
11
other materials provided with the distribution.
12
* Neither the name of the University of Technology Dresden, Germany, nor the name of
13
the JonDos GmbH, nor the names of their contributors may be used to endorse or
14
promote products derived from this software without specific prior written permission.
15
16
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
20
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
*/
28
#include "
StdAfx.h
"
29
30
#if ! defined (ONLY_LOCAL_PROXY)
31
32
#include "
CAThread.hpp
"
33
#include "
CAThreadList.hpp
"
34
#include "
CAMsg.hpp
"
35
40
CAThreadList::CAThreadList
()
41
{
42
m_pHead
= NULL;
43
m_Size
=0;
44
m_pListLock
=
new
CAMutex
();
45
}
46
47
CAThreadList::~CAThreadList
()
48
{
49
m_pListLock
->
lock
();
50
removeAll
();
51
m_pListLock
->
unlock
();
52
53
delete
m_pListLock
;
54
m_pListLock
= NULL;
55
}
56
57
58
/* safe functions */
59
SINT32
CAThreadList::put
(
const
CAThread
*
const
thread)
60
{
61
m_pListLock
->
lock
();
62
thread_list_entry_t
*new_entry =
new
thread_list_entry_t
;
63
64
new_entry->
tle_thread
= (
CAThread
*
const
)thread;
65
new_entry->
tle_next
=
m_pHead
;
66
m_pHead
= new_entry;
67
m_Size
++;
68
m_pListLock
->
unlock
();
69
70
return
E_SUCCESS
;
71
}
72
73
SINT32
CAThreadList::remove
(
const
CAThread
*
const
thread)
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
}
108
109
/*
110
CAThread *CAThreadList::get(CAThread *thread)
111
{
112
CAThread *ret=NULL;
113
m_pListLock->lock();
114
thread_list_entry_t *iterator=m_pHead;
115
while(iterator!=NULL)
116
{
117
if(thread->getID()==iterator->tle_thread->getID())
118
{
119
ret=iterator->tle_thread;
120
break;
121
}
122
iterator = iterator->tle_next;
123
}
124
m_pListLock->unlock();
125
return ret;
126
}
127
*/
128
129
void
CAThreadList::showAll
()
const
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
}
150
151
// This only deletes the list entries not the corresponding threads!
152
void
CAThreadList::removeAll
()
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"
,
161
m_pHead
->
tle_thread
->
getName
(),
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
}
170
171
// This only deletes the list entries not the corresponding threads!
172
SINT32
CAThreadList::waitAndRemoveAll
()
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"
,
181
m_pHead
->
tle_thread
->
getName
(),
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
}
194
195
196
197
#endif
CAMsg.hpp
CAThread.hpp
CAThreadList.hpp
thread_list_entry_t
struct thread_list_entry thread_list_entry_t
Definition:
CAThreadList.hpp:41
StdAfx.h
SINT32
signed int SINT32
Definition:
basetypedefs.h:132
CAMsg::printMsg
static SINT32 printMsg(UINT32 typ, const char *format,...)
Writes a given message to the log.
Definition:
CAMsg.cpp:251
CAMutex
Definition:
CAMutex.hpp:36
CAMutex::unlock
SINT32 unlock()
Definition:
CAMutex.hpp:52
CAMutex::lock
SINT32 lock()
Definition:
CAMutex.hpp:41
CAThread
Definition:
CAThread.hpp:115
CAThread::getName
UINT8 * getName() const
Definition:
CAThread.hpp:191
CAThread::getID
UINT32 getID() const
Definition:
CAThread.hpp:196
CAThread::join
SINT32 join()
Waits for the main function to finish execution.
Definition:
CAThread.cpp:187
CAThreadList::remove
SINT32 remove(const CAThread *const thread)
Definition:
CAThreadList.cpp:73
CAThreadList::m_Size
UINT32 m_Size
Definition:
CAThreadList.hpp:69
CAThreadList::m_pHead
thread_list_entry_t * m_pHead
Definition:
CAThreadList.hpp:70
CAThreadList::removeAll
void removeAll()
Definition:
CAThreadList.cpp:152
CAThreadList::~CAThreadList
~CAThreadList()
Definition:
CAThreadList.cpp:47
CAThreadList::showAll
void showAll() const
Definition:
CAThreadList.cpp:129
CAThreadList::waitAndRemoveAll
SINT32 waitAndRemoveAll()
Waits for finishing of all threads in list and removes them.
Definition:
CAThreadList.cpp:172
CAThreadList::CAThreadList
CAThreadList()
Definition:
CAThreadList.cpp:40
CAThreadList::m_pListLock
CAMutex * m_pListLock
Definition:
CAThreadList.hpp:71
CAThreadList::put
SINT32 put(const CAThread *const thread)
Definition:
CAThreadList.cpp:59
E_SUCCESS
const SINT32 E_SUCCESS
Definition:
errorcodes.hpp:2
thread_list_entry
Definition:
CAThreadList.hpp:36
thread_list_entry::tle_thread
CAThread * tle_thread
Definition:
CAThreadList.hpp:37
thread_list_entry::tle_next
struct thread_list_entry * tle_next
Definition:
CAThreadList.hpp:38
Generated on Sat Jul 22 2023 00:20:12 for Mixe for Privacy and Anonymity in the Internet by
1.9.1