Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Threads: add missing exception handlers #921

Merged
merged 1 commit into from

3 participants

@FernetMenta
Collaborator

No description provided.

@CrystalP
Collaborator

OK for the principle. I think there is a small problem with Win32Exception.cpp, it has a dependency on utils/log.h and it seemed that you wanted to break such dependencies with the ILogger?
There's a discussion with jcarroll about that in the IRC Log.
I'll try a few things to make win32exception use the ILogger instead.

@ghost

please pull.

@jimfcarroll
Collaborator

I think this should go. I have some work I'm adding to it that I can submit this weekend. For a preview it's here:

https://github.com/jimfcarroll/xbmc/commits/thread-cleanup

@jimfcarroll
Collaborator

Oh ... and my additions will address CrystalP's comments so we wont be adding back the circular dep

@CrystalP
Collaborator

I didn't have time to look at the CLog -> ILogger conversion and don't mind this PR going in as is, to fix up later.
Some exception handling is better than no exception handling :)

@FernetMenta
Collaborator

@jimfcarroll
Just to make sure, although I have created this pr your are the owner, right?

@jimfcarroll
Collaborator

Ha ... I was waiting for you to merge it. I'll do it now.

@jimfcarroll jimfcarroll merged commit 6f68bcc into xbmc:master
@tru tru referenced this pull request from a commit in plexinc/plex-home-theater-public
@tru tru "mute" is not a controllable.
Fixes #921
4d9c334
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 2, 2012
  1. @FernetMenta
This page is out of date. Refresh to see the latest.
View
4 xbmc/threads/Thread.cpp
@@ -104,9 +104,7 @@ THREADFUNC CThread::staticThread(void* data)
currentThread.set(pThread);
pThread->m_StartEvent.Set();
- pThread->OnStartup();
- pThread->Process();
- pThread->OnExit();
+ pThread->Action();
// lock during termination
CSingleLock lock(pThread->m_CriticalSection);
View
1  xbmc/threads/Thread.h
@@ -115,6 +115,7 @@ class CThread
ThreadIdentifier ThreadId() const;
void SetThreadInfo();
void TermHandler();
+ void Action();
ThreadIdentifier m_ThreadId;
ThreadOpaque m_ThreadOpaque;
View
32 xbmc/threads/platform/pthreads/ThreadImpl.cpp
@@ -229,4 +229,36 @@ float CThread::GetRelativeUsage()
return m_fLastUsage;
}
+void CThread::Action()
+{
+ try
+ {
+ OnStartup();
+ }
+ catch (...)
+ {
+ CLog::Log(LOGERROR, "%s - thread %s, Unhandled exception caught in thread startup, aborting. auto delete: %d", __FUNCTION__, m_ThreadName.c_str(), IsAutoDelete());
+ if (IsAutoDelete())
+ return;
+ }
+
+ try
+ {
+ Process();
+ }
+ catch (...)
+ {
+ CLog::Log(LOGERROR, "%s - thread %s, Unhandled exception caught in thread process, aborting. auto delete: %d", __FUNCTION__, m_ThreadName.c_str(), IsAutoDelete());
+ }
+
+ try
+ {
+ OnExit();
+ }
+ catch (...)
+ {
+ CLog::Log(LOGERROR, "%s - thread %s, Unhandled exception caught in thread exit, aborting. auto delete: %d", __FUNCTION__, m_ThreadName.c_str(), IsAutoDelete());
+ }
+}
+
View
50 xbmc/threads/platform/win/ThreadImpl.cpp
@@ -20,6 +20,7 @@
*/
#include <windows.h>
+#include "utils/Win32Exception.h"
void CThread::Create(bool bAutoDelete, unsigned stacksize)
@@ -190,3 +191,52 @@ float CThread::GetRelativeUsage()
return m_fLastUsage;
}
+
+void CThread::Action()
+{
+ // install win32 exception translator
+ win32_exception::install_handler();
+
+ try
+ {
+ OnStartup();
+ }
+ catch (const access_violation &e)
+ {
+ e.writelog(__FUNCTION__);
+ if (IsAutoDelete())
+ return;
+ }
+ catch (const win32_exception &e)
+ {
+ e.writelog(__FUNCTION__);
+ if (IsAutoDelete())
+ return;
+ }
+
+ try
+ {
+ Process();
+ }
+ catch (const access_violation &e)
+ {
+ e.writelog(__FUNCTION__);
+ }
+ catch (const win32_exception &e)
+ {
+ e.writelog(__FUNCTION__);
+ }
+
+ try
+ {
+ OnExit();
+ }
+ catch (const access_violation &e)
+ {
+ e.writelog(__FUNCTION__);
+ }
+ catch (const win32_exception &e)
+ {
+ e.writelog(__FUNCTION__);
+ }
+}
Something went wrong with that request. Please try again.