Allow Thread::killall() to work from any thread.

git-svn-id: http://voip.null.ro/svn/yate@4986 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
oana 2012-04-04 09:27:29 +00:00
parent e38c90a808
commit 241e65a97f
1 changed files with 17 additions and 5 deletions

View File

@ -429,13 +429,19 @@ void ThreadPrivate::killall()
ThreadPrivate *t; ThreadPrivate *t;
bool sledgehammer = false; bool sledgehammer = false;
s_tmutex.lock(); s_tmutex.lock();
ThreadPrivate* crt = ThreadPrivate::current();
int c = s_threads.count(); int c = s_threads.count();
Debug(DebugNote,"Soft cancelling %d running threads",c); if (crt)
Debug(DebugNote,"Thread '%s' is soft cancelling other %d running threads",crt->m_name,c-1);
else
Debug(DebugNote,"Soft cancelling %d running threads",c);
ObjList* l = &s_threads; ObjList* l = &s_threads;
while (l && (t = static_cast<ThreadPrivate *>(l->get())) != 0) while (l && (t = static_cast<ThreadPrivate *>(l->get())) != 0)
{ {
Debug(DebugInfo,"Stopping ThreadPrivate '%s' [%p]",t->m_name,t); if (t != crt) {
t->cancel(false); Debug(DebugInfo,"Stopping ThreadPrivate '%s' [%p]",t->m_name,t);
t->cancel(false);
}
l = l->next(); l = l->next();
} }
for (int w = 0; w < SOFT_WAITS; w++) { for (int w = 0; w < SOFT_WAITS; w++) {
@ -443,6 +449,9 @@ void ThreadPrivate::killall()
Thread::idle(); Thread::idle();
s_tmutex.lock(); s_tmutex.lock();
c = s_threads.count(); c = s_threads.count();
// ignore the current thread if we have one
if (crt && c)
c--;
if (!c) { if (!c) {
s_tmutex.unlock(); s_tmutex.unlock();
return; return;
@ -453,6 +462,10 @@ void ThreadPrivate::killall()
c = 1; c = 1;
while (l && (t = static_cast<ThreadPrivate *>(l->get())) != 0) while (l && (t = static_cast<ThreadPrivate *>(l->get())) != 0)
{ {
if (t == crt) {
l = l->next();
continue;
}
Debug(DebugInfo,"Trying to kill ThreadPrivate '%s' [%p], attempt %d",t->m_name,t,c); Debug(DebugInfo,"Trying to kill ThreadPrivate '%s' [%p], attempt %d",t->m_name,t,c);
bool ok = t->cancel(true); bool ok = t->cancel(true);
if (ok) { if (ok) {
@ -622,8 +635,7 @@ void Thread::cleanup()
void Thread::killall() void Thread::killall()
{ {
if (!ThreadPrivate::current()) ThreadPrivate::killall();
ThreadPrivate::killall();
} }
void Thread::exit() void Thread::exit()