From 0e4d503384a254c843a065c26f77bc19dfccff16 Mon Sep 17 00:00:00 2001 From: Justin Berger Date: Sat, 22 Jul 2017 09:29:18 -0600 Subject: server: Added thread check to protect writedata --- Source/cmConnection.cxx | 6 ++++++ Source/cmServer.cxx | 6 ++++++ Source/cmServer.h | 9 +++++++++ 3 files changed, 21 insertions(+) diff --git a/Source/cmConnection.cxx b/Source/cmConnection.cxx index c0d1b82..f482412 100644 --- a/Source/cmConnection.cxx +++ b/Source/cmConnection.cxx @@ -69,6 +69,12 @@ bool cmEventBasedConnection::IsOpen() const void cmEventBasedConnection::WriteData(const std::string& _data) { +#ifndef NDEBUG + auto curr_thread_id = uv_thread_self(); + assert(this->Server); + assert(uv_thread_equal(&curr_thread_id, &this->Server->ServeThreadId)); +#endif + auto data = _data; assert(this->WriteStream); if (BufferStrategy) { diff --git a/Source/cmServer.cxx b/Source/cmServer.cxx index b1b4020..30d0f51 100644 --- a/Source/cmServer.cxx +++ b/Source/cmServer.cxx @@ -436,6 +436,12 @@ bool cmServerBase::StartServeThread() bool cmServerBase::Serve(std::string* errorMessage) { +#ifndef NDEBUG + uv_thread_t blank_thread_t = {}; + assert(uv_thread_equal(&blank_thread_t, &ServeThreadId)); + ServeThreadId = uv_thread_self(); +#endif + errorMessage->clear(); uv_signal_init(&Loop, &this->SIGINTHandler); diff --git a/Source/cmServer.h b/Source/cmServer.h index d8f73c1..15fd2ba 100644 --- a/Source/cmServer.h +++ b/Source/cmServer.h @@ -67,6 +67,15 @@ protected: bool ServeThreadRunning = false; uv_thread_t ServeThread; uv_async_t ShutdownSignal; +#ifndef NDEBUG +public: + // When the server starts it will mark down it's current thread ID, + // which is useful in other contexts to just assert that operations + // are performed on that same thread. + uv_thread_t ServeThreadId = {}; + +protected: +#endif uv_loop_t Loop; -- cgit v0.12