From 7456b19e88bd6d405863b1a180ec95e4c598afa1 Mon Sep 17 00:00:00 2001 From: Charlie Fenton Date: Mon, 21 Jul 2008 11:14:44 +0000 Subject: [PATCH] MGR: async GUI RPCs: Fix RPC cancel, etc. for Windows. svn path=/workspaces/charlief/; revision=15641 --- checkin_notes | 7 +++++++ clientgui/AsyncRPC.cpp | 12 ++++++++---- clientgui/MainDocument.cpp | 17 ++++++++++++++++- clientgui/MainDocument.h | 2 +- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/checkin_notes b/checkin_notes index 710726bf13..f9a06d10f0 100644 --- a/checkin_notes +++ b/checkin_notes @@ -5888,3 +5888,10 @@ Charlie 18 July 2008 clientgui/ AsyncRPC.cpp MainDocument.cpp,.h + +Charlie 21 July 2008 + - MGR: async GUI RPCs: Fix RPC cancel, etc. for Windows. + + clientgui/ + AsyncRPC.cpp + MainDocument.cpp,.h diff --git a/clientgui/AsyncRPC.cpp b/clientgui/AsyncRPC.cpp index 6166086ac5..99fb92a7b1 100644 --- a/clientgui/AsyncRPC.cpp +++ b/clientgui/AsyncRPC.cpp @@ -79,6 +79,8 @@ RPCThread::RPCThread(CMainDocument *pDoc) void RPCThread::OnExit() { + // Tell CMainDocument that thread has gracefully ended + m_Doc->m_RPCThread = NULL; } @@ -233,6 +235,7 @@ int CMainDocument::RequestRPC(ASYNC_RPC_REQUEST& request) { // start a new RPC thread. if (current_rpc_request.isActive) { current_rpc_request.isActive = false; + m_RPCThread->Pause(); // Needed on Windows rpc.close(); m_RPCThread->Kill(); m_RPCThread = NULL; @@ -247,8 +250,9 @@ int CMainDocument::RequestRPC(ASYNC_RPC_REQUEST& request) { m_RPCThread = new RPCThread(this); wxASSERT(m_RPCThread); retval2 = m_RPCThread->Create(); - wxASSERT(retval2); - m_RPCThread->Run(); + wxASSERT(!retval2); + retval2 = m_RPCThread->Run(); + wxASSERT(!retval2); } } if (m_RPCWaitDlg) { @@ -432,7 +436,7 @@ ALL_PROJECTS_LIST pl; void CMainDocument::TestAsyncRPC() { // TEMPORARY FOR TESTING ASYNC RPCs -- CAF ASYNC_RPC_REQUEST request; - wxDateTime completionTime; + wxDateTime completionTime = wxDateTime((time_t)0); int retval = 0; completionTime.ResetTime(); @@ -450,7 +454,7 @@ void CMainDocument::TestAsyncRPC() { // TEMPORARY FOR TESTING ASYNC RPCs retval = RequestRPC(request); - wxString s = completionTime.Format("%T"); + wxString s = completionTime.Format("%X"); printf("Completion time = %s\n", s.c_str()); printf("RequestRPC returned %d\n", retval); } diff --git a/clientgui/MainDocument.cpp b/clientgui/MainDocument.cpp index 355ab2abb1..a95b27839b 100644 --- a/clientgui/MainDocument.cpp +++ b/clientgui/MainDocument.cpp @@ -385,7 +385,7 @@ int CMainDocument::OnInit() { wxASSERT(m_RPCThread); iRetVal = m_RPCThread->Create(); - wxASSERT(iRetVal); + wxASSERT(!iRetVal); m_RPCThread->Run(); @@ -403,6 +403,21 @@ int CMainDocument::OnExit() { m_pClientManager = NULL; } + if (m_RPCThread) { + m_RPCThread->Delete(); + wxStopWatch ThreadDeleteTimer = wxStopWatch(); + // RPC thread sets m_RPCThread to NULL when it exits + while (m_RPCThread) { + // Allow 5 seconds for RPC thread to exit gracefully + if (ThreadDeleteTimer.Time() > 5000) { + m_RPCThread->Pause(); // Needed on Windows + m_RPCThread->Kill(); + break; + } + } + m_RPCThread = NULL; + } + if (m_pNetworkConnection) { delete m_pNetworkConnection; m_pNetworkConnection = NULL; diff --git a/clientgui/MainDocument.h b/clientgui/MainDocument.h index 25dc47073e..f3bc513f46 100644 --- a/clientgui/MainDocument.h +++ b/clientgui/MainDocument.h @@ -169,12 +169,12 @@ public: void OnRPCComplete(CRPCFinishedEvent& event); ASYNC_RPC_REQUEST* GetCurrentRPCRequest() { return ¤t_rpc_request; }; void TestAsyncRPC(); // TEMPORARY -- CAF + RPCThread* m_RPCThread; #if USE_CRITICAL_SECTIONS_FOR_ASYNC_RPCS wxCriticalSection m_critsect; #endif private: - RPCThread* m_RPCThread; ASYNC_RPC_REQUEST current_rpc_request; AsyncRPCDlg* m_RPCWaitDlg; std::vector RPC_requests;