]> git.sesse.net Git - casparcg/blobdiff - common/exception/win32_exception.cpp
* Created custom decklink allocator for reducing memory footprint.
[casparcg] / common / exception / win32_exception.cpp
index e0338c59258bb0630e05db01d28a863958aeb2b2..bd983c66dcc95322e90a99d320a3e61dd026a883 100644 (file)
 \r
 #include "../stdafx.h"\r
 \r
+#include <boost/thread.hpp>\r
+\r
 #include "win32_exception.h"\r
 \r
 #include "../log/log.h"\r
+#include "../concurrency/executor.h"\r
 \r
 namespace caspar {\r
 \r
+bool& installed_for_thread()\r
+{\r
+       static boost::thread_specific_ptr<bool> installed;\r
+\r
+       auto for_thread = installed.get();\r
+       \r
+       if (!for_thread)\r
+       {\r
+               for_thread = new bool(false);\r
+               installed.reset(for_thread);\r
+       }\r
+\r
+       return *for_thread;\r
+}\r
+\r
 void win32_exception::install_handler() \r
 {\r
 //#ifndef _DEBUG\r
        _set_se_translator(win32_exception::Handler);\r
+       installed_for_thread() = true;\r
 //#endif\r
 }\r
 \r
+void win32_exception::ensure_handler_installed_for_thread(\r
+               const char* thread_description)\r
+{\r
+       if (!installed_for_thread())\r
+       {\r
+               install_handler();\r
+\r
+               if (thread_description)\r
+                       detail::SetThreadName(GetCurrentThreadId(), thread_description);\r
+       }\r
+}\r
+\r
 void win32_exception::Handler(unsigned int errorCode, EXCEPTION_POINTERS* pInfo) {\r
        switch(errorCode)\r
        {\r