diff options
author | zork@google.com <zork@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-09 20:51:19 +0000 |
---|---|---|
committer | zork@google.com <zork@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-09 20:51:19 +0000 |
commit | c10d60b4194cab3f68da71e0270647c02d000146 (patch) | |
tree | 3f8bfc88aa2b002e9ea4b31af74668dabe7ad201 /third_party | |
parent | fa7b1e3db23e140dd31a332fb510420449ce09e4 (diff) | |
download | chromium_src-c10d60b4194cab3f68da71e0270647c02d000146.zip chromium_src-c10d60b4194cab3f68da71e0270647c02d000146.tar.gz chromium_src-c10d60b4194cab3f68da71e0270647c02d000146.tar.bz2 |
Prevent threads from running in libjingle after their object has been deleted.
BUG=23251
TEST=none
Review URL: http://codereview.chromium.org/261043
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28594 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party')
-rw-r--r-- | third_party/libjingle/files/talk/base/thread.cc | 12 | ||||
-rw-r--r-- | third_party/libjingle/files/talk/base/thread.h | 2 |
2 files changed, 14 insertions, 0 deletions
diff --git a/third_party/libjingle/files/talk/base/thread.cc b/third_party/libjingle/files/talk/base/thread.cc index 8fc45e1..78db60d 100644 --- a/third_party/libjingle/files/talk/base/thread.cc +++ b/third_party/libjingle/files/talk/base/thread.cc @@ -98,6 +98,11 @@ void ThreadManager::Remove(Thread *thread) { threads_.erase(std::remove(threads_.begin(), threads_.end(), thread), threads_.end()); } +bool ThreadManager::ThreadActive(Thread *thread) { + CritScope cs(&crit_); + return(std::find(threads_.begin(), threads_.end(), thread) != threads_.end()); +} + Thread::Thread(SocketServer* ss) : MessageQueue(ss), priority_(PRIORITY_NORMAL) { g_thmgr.Add(this); started_ = false; @@ -121,11 +126,13 @@ void Thread::Start() { param.sched_priority = 15; // +15 = pthread_attr_setschedparam(&attr, ¶m); } + CritScope cs(&crit_); pthread_create(&thread_, &attr, PreRun, this); started_ = true; } void Thread::Join() { + CritScope cs(&crit_); if (started_) { void *pv; pthread_join(thread_, &pv); @@ -166,6 +173,7 @@ void Thread::Start() { if (priority_ != PRIORITY_NORMAL) { flags = CREATE_SUSPENDED; } + CritScope cs(&crit_); thread_ = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)PreRun, this, flags, NULL); if (thread_) { if (priority_ != PRIORITY_NORMAL) { @@ -179,6 +187,7 @@ void Thread::Start() { } void Thread::Join() { + CritScope cs(&crit_); if (started_) { WaitForSingleObject(thread_, INFINITE); CloseHandle(thread_); @@ -189,6 +198,9 @@ void Thread::Join() { void *Thread::PreRun(void *pv) { Thread *thread = (Thread *)pv; + // Make sure the thread hasn't been deleted. + if (!g_thmgr.ThreadActive(thread)) + return NULL; ThreadManager::SetCurrent(thread); #if defined(WIN32) && defined(_DEBUG) char buf[256]; diff --git a/third_party/libjingle/files/talk/base/thread.h b/third_party/libjingle/files/talk/base/thread.h index 5da0aed..367203a 100644 --- a/third_party/libjingle/files/talk/base/thread.h +++ b/third_party/libjingle/files/talk/base/thread.h @@ -55,6 +55,7 @@ public: static void SetCurrent(Thread *thread); void Add(Thread *thread); void Remove(Thread *thread); + bool ThreadActive(Thread *thread); private: Thread *main_thread_; @@ -132,6 +133,7 @@ private: std::list<_SendMessage> sendlist_; ThreadPriority priority_; + CriticalSection crit_; bool started_; bool has_sends_; |