From 0415bac7d4d31232b047e3efe2678d5f0669e4ff Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sun, 3 Jan 2016 11:48:51 +1300 Subject: [PATCH] Switch use of threads on defined(CAVERNLOG_USE_THREADS) Makes it easier to test the non-thread variant. --- src/cavernlog.cc | 20 ++++++++++---------- src/cavernlog.h | 12 ++++++++---- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/cavernlog.cc b/src/cavernlog.cc index 8d767b82..f9eb9228 100644 --- a/src/cavernlog.cc +++ b/src/cavernlog.cc @@ -42,7 +42,7 @@ enum { LOG_REPROCESS = 1234, LOG_SAVE = 1235 }; -#ifdef wxUSE_THREADS +#ifdef CAVERNLOG_USE_THREADS // New event type for passing a chunk of cavern output from the worker thread // to the main thread. class CavernOutputEvent; @@ -102,7 +102,7 @@ BEGIN_EVENT_TABLE(CavernLogWindow, wxHtmlWindow) EVT_BUTTON(LOG_REPROCESS, CavernLogWindow::OnReprocess) EVT_BUTTON(LOG_SAVE, CavernLogWindow::OnSave) EVT_BUTTON(wxID_OK, CavernLogWindow::OnOK) -#ifdef wxUSE_THREADS +#ifdef CAVERNLOG_USE_THREADS EVT_CLOSE(CavernLogWindow::OnClose) EVT_COMMAND(wxID_ANY, wxEVT_CAVERN_OUTPUT, CavernLogWindow::OnCavernOutput) #else @@ -160,7 +160,7 @@ static wxString escape_for_shell(wxString s, bool protect_dash = false) CavernLogWindow::CavernLogWindow(MainFrm * mainfrm_, const wxString & survey_, wxWindow * parent) : wxHtmlWindow(parent), mainfrm(mainfrm_), cavern_out(NULL), link_count(0), end(buf), init_done(false), survey(survey_) -#ifdef wxUSE_THREADS +#ifdef CAVERNLOG_USE_THREADS , thread(NULL) #endif { @@ -177,7 +177,7 @@ CavernLogWindow::~CavernLogWindow() } } -#ifdef wxUSE_THREADS +#ifdef CAVERNLOG_USE_THREADS void CavernLogWindow::stop_thread() { @@ -297,7 +297,7 @@ void CavernLogWindow::process(const wxString &file) { SetPage(wxString()); -#ifdef wxUSE_THREADS +#ifdef CAVERNLOG_USE_THREADS if (thread) stop_thread(); #endif if (cavern_out) { @@ -366,7 +366,7 @@ CavernLogWindow::process(const wxString &file) wxGetApp().ReportError(m); return; } -#ifndef wxUSE_THREADS +#ifndef CAVERNLOG_USE_THREADS } void @@ -381,7 +381,7 @@ CavernLogWindow::OnIdle(wxIdleEvent& event) #else cavern_fd = fileno(cavern_out); #endif -#ifdef wxUSE_THREADS +#ifdef CAVERNLOG_USE_THREADS thread = new CavernThread(this, cavern_fd); if (thread->Run() != wxTHREAD_NO_ERROR) { wxGetApp().ReportError(wxT("Thread failed to start")); @@ -587,13 +587,13 @@ CavernLogWindow::OnCavernOutput(wxCommandEvent & e_) end = buf + left; if (left) memmove(buf, p, left); Update(); -#ifndef wxUSE_THREADS +#ifndef CAVERNLOG_USE_THREADS event.RequestMore(); #endif return; } -#ifdef wxUSE_THREADS +#ifdef CAVERNLOG_USE_THREADS if (e.len == 0 && buf != end) { // Truncated UTF-8 sequence. goto bad_utf8; @@ -609,7 +609,7 @@ CavernLogWindow::OnCavernOutput(wxCommandEvent & e_) bad_utf8: errno = EILSEQ; } -#if !defined wxUSE_THREADS && !defined __WXMSW__ +#if !defined CAVERNLOG_USE_THREADS && !defined __WXMSW__ abort: #endif diff --git a/src/cavernlog.h b/src/cavernlog.h index 6d9a15c4..3d43a95e 100644 --- a/src/cavernlog.h +++ b/src/cavernlog.h @@ -1,7 +1,7 @@ /* cavernlog.h * Run cavern inside an Aven window * - * Copyright (C) 2005,2006,2010,2015 Olly Betts + * Copyright (C) 2005,2006,2010,2015,2016 Olly Betts * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,13 +27,17 @@ #include #ifdef wxUSE_THREADS +# define CAVERNLOG_USE_THREADS +#endif + +#ifdef CAVERNLOG_USE_THREADS class CavernOutputEvent; class CavernThread; #endif class MainFrm; class CavernLogWindow : public wxHtmlWindow { -#ifdef wxUSE_THREADS +#ifdef CAVERNLOG_USE_THREADS friend class CavernThread; #endif @@ -53,7 +57,7 @@ class CavernLogWindow : public wxHtmlWindow { std::string log_txt; -#ifdef wxUSE_THREADS +#ifdef CAVERNLOG_USE_THREADS void stop_thread(); CavernThread * thread; @@ -77,7 +81,7 @@ class CavernLogWindow : public wxHtmlWindow { void OnOK(wxCommandEvent &); -#ifdef wxUSE_THREADS +#ifdef CAVERNLOG_USE_THREADS void OnCavernOutput(wxCommandEvent & e); void OnClose(wxCloseEvent &); -- 2.11.4.GIT