diff options
author | Pierre Ossman <ossman@cendio.se> | 2025-03-13 19:03:53 +0100 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2025-03-13 19:03:53 +0100 |
commit | 68e3cce0f8b11259b23f137aad7e366d5f4da081 (patch) | |
tree | 9b89e8e9cf59773a2c1901f4bade5320e4166cb6 /common/rfb | |
parent | e3987244cef69d404bf8ae3423a91fbf440f039d (diff) | |
download | tigervnc-68e3cce0f8b11259b23f137aad7e366d5f4da081.tar.gz tigervnc-68e3cce0f8b11259b23f137aad7e366d5f4da081.zip |
Use std::exception_ptr to store exceptions
This is much more robust and flexible than what we came up with.
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; }; } |