diff options
Diffstat (limited to 'common/rfb')
-rw-r--r-- | common/rfb/DecodeManager.cxx | 25 | ||||
-rw-r--r-- | common/rfb/DecodeManager.h | 5 |
2 files changed, 14 insertions, 16 deletions
diff --git a/common/rfb/DecodeManager.cxx b/common/rfb/DecodeManager.cxx index 97a90549..94908f86 100644 --- a/common/rfb/DecodeManager.cxx +++ b/common/rfb/DecodeManager.cxx @@ -85,8 +85,6 @@ DecodeManager::~DecodeManager() threads.pop_back(); } - delete threadException; - while (!freeBuffers.empty()) { delete freeBuffers.back(); freeBuffers.pop_back(); @@ -242,30 +240,29 @@ void DecodeManager::logStats() core::iecPrefix(bytes, "B").c_str(), ratio); } -void DecodeManager::setThreadException(const std::exception& e) +void DecodeManager::setThreadException() { core::AutoMutex a(queueMutex); - if (threadException != nullptr) + if (threadException) return; - threadException = new std::runtime_error( - core::format("Exception on worker thread: %s", e.what())); + threadException = std::current_exception(); } void DecodeManager::throwThreadException() { core::AutoMutex a(queueMutex); - if (threadException == nullptr) + if (!threadException) return; - std::runtime_error e(threadException->what()); - - delete threadException; - threadException = nullptr; - - throw e; + try { + std::rethrow_exception(threadException); + } catch (...) { + threadException = nullptr; + throw; + } } DecodeManager::DecodeThread::DecodeThread(DecodeManager* manager_) @@ -319,7 +316,7 @@ void DecodeManager::DecodeThread::worker() entry->bufferStream->length(), *entry->server, entry->pb); } catch (std::exception& e) { - manager->setThreadException(e); + manager->setThreadException(); } catch(...) { assert(false); } diff --git a/common/rfb/DecodeManager.h b/common/rfb/DecodeManager.h index a26f5fd6..95d3ceca 100644 --- a/common/rfb/DecodeManager.h +++ b/common/rfb/DecodeManager.h @@ -19,6 +19,7 @@ #ifndef __RFB_DECODEMANAGER_H__ #define __RFB_DECODEMANAGER_H__ +#include <exception> #include <list> #include <core/Region.h> @@ -55,7 +56,7 @@ namespace rfb { private: void logStats(); - void setThreadException(const std::exception& e); + void setThreadException(); void throwThreadException(); private: @@ -108,7 +109,7 @@ namespace rfb { }; std::list<DecodeThread*> threads; - std::exception *threadException; + std::exception_ptr threadException; }; } |