From de79ef66d8baa50df9ad05f441805ef0a6637bda Mon Sep 17 00:00:00 2001 From: Uwe Schulzweida <uwe.schulzweida@mpimet.mpg.de> Date: Tue, 4 Mar 2025 20:42:29 +0100 Subject: [PATCH] Renamed cdo::Task to WorkerThread --- src/Afterburner.cc | 2 +- src/CMakeLists.txt | 4 ++-- src/Detrend.cc | 4 ++-- src/Diff.cc | 4 ++-- src/Ensstat.cc | 4 ++-- src/Info.cc | 4 ++-- src/Longinfo.cc | 4 ++-- src/Makefile.am | 8 ++++---- src/Timstat.cc | 4 ++-- src/Trend.cc | 4 ++-- src/afterburner.h | 4 ++-- src/{cdo_task.cc => workerthread.cc} | 27 +++++++++++---------------- src/{cdo_task.h => workerthread.h} | 19 +++++++------------ 13 files changed, 41 insertions(+), 51 deletions(-) rename src/{cdo_task.cc => workerthread.cc} (86%) rename src/{cdo_task.h => workerthread.h} (81%) diff --git a/src/Afterburner.cc b/src/Afterburner.cc index 6f524e29f..8e4951155 100644 --- a/src/Afterburner.cc +++ b/src/Afterburner.cc @@ -560,7 +560,7 @@ after_control(AfterControl &globs, struct Variable *vars) int numFields = 0; RARG rarg; - if (afterReadAsync) afterReadTask = new cdo::Task; + if (afterReadAsync) afterReadTask = new WorkerThread; for (int code = 0; code < MaxCodes; ++code) vars[code].needed0 = vars[code].needed; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d5772694e..6091124ce 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -183,8 +183,6 @@ list( APPEND cdolib_src_files cdo_stepstat.h cdo_syntax_error.cc cdo_syntax_error.h - cdo_task.cc - cdo_task.h cdo_timer.h cdo_varlist.cc cdo_varlist.h @@ -314,6 +312,8 @@ list( APPEND cdolib_src_files remap_stat.cc results_template_parser.cc results_template_parser.h + workerthread.cc + workerthread.h ) list( APPEND cdolib_src_files diff --git a/src/Detrend.cc b/src/Detrend.cc index 1eb9a3ea9..6e38316f4 100644 --- a/src/Detrend.cc +++ b/src/Detrend.cc @@ -17,7 +17,7 @@ #include "process_int.h" #include "cdo_vlist.h" #include "cdo_options.h" -#include "cdo_task.h" +#include "workerthread.h" #include "field_trend.h" #include "datetime.h" #include "pmlist.h" @@ -182,7 +182,7 @@ public: run() override { auto runAsync = (Options::CDO_Async_Read > 0); - auto task = runAsync ? std::make_unique<cdo::Task>() : nullptr; + auto task = runAsync ? std::make_unique<WorkerThread>() : nullptr; auto calendar = taxisInqCalendar(taxisID1); CheckTimeIncr checkTimeIncr; diff --git a/src/Diff.cc b/src/Diff.cc index be4c10a4b..770329f46 100644 --- a/src/Diff.cc +++ b/src/Diff.cc @@ -17,7 +17,7 @@ #include <cdi.h> -#include "cdo_task.h" +#include "workerthread.h" #include "process_int.h" #include "mpmo_color.h" #include "cdo_math.h" @@ -396,7 +396,7 @@ public: run() override { auto runAsync = (Options::CDO_Async_Read > 0); - auto task = runAsync ? std::make_unique<cdo::Task>() : nullptr; + auto task = runAsync ? std::make_unique<WorkerThread>() : nullptr; auto numTasks = runAsync ? 2 : 1; FieldVector fieldVector1(numTasks); diff --git a/src/Ensstat.cc b/src/Ensstat.cc index fd95ae039..837c12f75 100644 --- a/src/Ensstat.cc +++ b/src/Ensstat.cc @@ -29,7 +29,7 @@ #include "process_int.h" #include "cdo_vlist.h" #include "param_conversion.h" -#include "cdo_task.h" +#include "workerthread.h" #include "cdo_options.h" #include "cdo_cdi_wrapper.h" #include "util_files.h" @@ -235,7 +235,7 @@ public: void run() override { - auto task = Options::CDO_task ? std::make_unique<cdo::Task>() : nullptr; + auto task = Options::CDO_task ? std::make_unique<WorkerThread>() : nullptr; auto numTasks = Options::CDO_task ? 2 : 1; FieldVector workFields(Threading::ompNumMaxThreads); diff --git a/src/Info.cc b/src/Info.cc index a3de0bad1..01954583d 100644 --- a/src/Info.cc +++ b/src/Info.cc @@ -15,7 +15,7 @@ #include <cdi.h> #include <numbers> -#include "cdo_task.h" +#include "workerthread.h" #include "cdo_options.h" #include "cdo_math.h" #include "process_int.h" @@ -541,7 +541,7 @@ public: if (numVars == 0) continue; auto runAsync = (Options::CDO_Async_Read > 0); - auto task = runAsync ? std::make_unique<cdo::Task>() : nullptr; + auto task = runAsync ? std::make_unique<WorkerThread>() : nullptr; auto numTasks = runAsync ? 2 : 1; FieldVector fieldVector(numTasks); diff --git a/src/Longinfo.cc b/src/Longinfo.cc index af2b47012..99cbf4ed4 100644 --- a/src/Longinfo.cc +++ b/src/Longinfo.cc @@ -15,7 +15,7 @@ #include <cdi.h> -#include "cdo_task.h" +#include "workerthread.h" #include "cdo_options.h" #include "cdo_math.h" #include "process_int.h" @@ -191,7 +191,7 @@ public: run() override { auto runAsync = (Options::CDO_Async_Read > 0); - auto task = runAsync ? std::make_unique<cdo::Task>() : nullptr; + auto task = runAsync ? std::make_unique<WorkerThread>() : nullptr; auto numTasks = runAsync ? 2 : 1; FieldVector fieldVector(numTasks); diff --git a/src/Makefile.am b/src/Makefile.am index 96302eb9d..40071cd8e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -63,8 +63,6 @@ libcdo_la_SOURCES = after_dvtrans.cc \ cdo_syntax_error.h \ cdo_node_attach_exception.h \ cdo_exception.h \ - cdo_task.cc \ - cdo_task.h \ cdo_timer.h \ cdo_varlist.cc \ cdo_varlist.h \ @@ -300,11 +298,13 @@ libcdo_la_SOURCES = after_dvtrans.cc \ vertical_interp.h \ vertint_util.h \ vertint_util.cc \ + workerthread.cc \ + workerthread.h \ zaxis_print.cc -libcdo_la_SOURCES += \ +libcdo_la_SOURCES += \ json/jsmn.h \ json/jsmn.c -libcdo_la_SOURCES += \ +libcdo_la_SOURCES += \ kdtreelib/kdtree.h \ kdtreelib/kdtree_cartesian.cc \ kdtreelib/kdtree_common.cc \ diff --git a/src/Timstat.cc b/src/Timstat.cc index d862ba32a..1ff05a8de 100644 --- a/src/Timstat.cc +++ b/src/Timstat.cc @@ -66,7 +66,7 @@ #include "cdo_options.h" #include "cdo_stepstat.h" -#include "cdo_task.h" +#include "workerthread.h" #include "process_int.h" #include "datetime.h" #include "printinfo.h" @@ -422,7 +422,7 @@ public: field2D_init(fields3D[1], varList1, FIELD_VEC | FIELD_NAT); auto useTask = true; - auto task = useTask ? std::make_unique<cdo::Task>() : nullptr; + auto task = useTask ? std::make_unique<WorkerThread>() : nullptr; int tsID = 0; int otsID = 0; diff --git a/src/Trend.cc b/src/Trend.cc index bf71e2da8..9fabd21e9 100644 --- a/src/Trend.cc +++ b/src/Trend.cc @@ -17,7 +17,7 @@ #include "process_int.h" #include "cdo_vlist.h" #include "cdo_options.h" -#include "cdo_task.h" +#include "workerthread.h" #include "field_trend.h" #include "cdo_omp.h" #include "datetime.h" @@ -227,7 +227,7 @@ public: field2D_init(fields3D[1], varList1, FIELD_VEC | FIELD_NAT); bool useTask = true; - auto task = useTask ? std::make_unique<cdo::Task>() : nullptr; + auto task = useTask ? std::make_unique<WorkerThread>() : nullptr; int tsID = 0; while (true) diff --git a/src/afterburner.h b/src/afterburner.h index 0e53c8964..51cac9f37 100644 --- a/src/afterburner.h +++ b/src/afterburner.h @@ -12,7 +12,7 @@ #include "process_int.h" #include "transform.h" -#include "cdo_task.h" +#include "workerthread.h" #include "varray.h" constexpr int MaxLevel = 1024; @@ -220,7 +220,7 @@ void after_EchamDependencies(struct Variable *vars, int ncodes, int type, int so void after_legini_setup(AfterControl &globs, struct Variable *vars); -static cdo::Task *afterReadTask = nullptr; +static WorkerThread *afterReadTask = nullptr; static bool afterReadAsync = true; template <typename... Args> diff --git a/src/cdo_task.cc b/src/workerthread.cc similarity index 86% rename from src/cdo_task.cc rename to src/workerthread.cc index d41a59200..48871943d 100644 --- a/src/cdo_task.cc +++ b/src/workerthread.cc @@ -10,13 +10,10 @@ #include "cdo_options.h" #endif -#include "cdo_task.h" - -namespace cdo -{ +#include "workerthread.h" void -Task::task(cdo::Task *taskInfo) +WorkerThread::task(WorkerThread *taskInfo) { #if defined(_OPENMP) omp_set_num_threads(Threading::ompNumMaxThreads); // Has to be called for every thread! @@ -57,7 +54,7 @@ Task::task(cdo::Task *taskInfo) } void -Task::doAsync(const std::function<void()> &_function) +WorkerThread::doAsync(const std::function<void()> &_function) { // ensure worker is waiting std::lock_guard<std::mutex> _(workMutex); @@ -70,7 +67,7 @@ Task::doAsync(const std::function<void()> &_function) } void -Task::start(void *(*taskRoutine)(void *), void *taskArg) +WorkerThread::start(void *(*taskRoutine)(void *), void *taskArg) { // ensure worker is waiting std::lock_guard<std::mutex> _(workMutex); @@ -83,7 +80,7 @@ Task::start(void *(*taskRoutine)(void *), void *taskArg) } void * -Task::wait() +WorkerThread::wait() { while (1) { @@ -94,14 +91,14 @@ Task::wait() return this->result; } -Task::Task() +WorkerThread::WorkerThread() { bossMutex.lock(); this->thread = std::thread(this->task, this); this->wait(); } -Task::~Task() +WorkerThread::~WorkerThread() { // ensure the worker is waiting workMutex.lock(); @@ -115,10 +112,8 @@ Task::~Task() bossMutex.unlock(); } -} // namespace cdo - -#ifdef TEST_CDO_TASK -// g++ -g -Wall -O2 -DTEST_CDO_TASK cdo_task.cc +#ifdef TEST_WORKERTHREAD +// g++ -g -Wall -O2 -DTEST_WORKERTHREAD workerthread.cc void * myfunc(void *arg) @@ -130,7 +125,7 @@ myfunc(void *arg) void mytask1(void) { - cdo::Task task; + WorkerThread task; void *myarg = nullptr; void *myresult; @@ -143,7 +138,7 @@ void mytask2(void) { bool useTask = true; - auto task = useTask ? std::make_unique<cdo::Task>() : nullptr; + auto task = useTask ? std::make_unique<WorkerThread>() : nullptr; void *myarg = nullptr; void *myresult; diff --git a/src/cdo_task.h b/src/workerthread.h similarity index 81% rename from src/cdo_task.h rename to src/workerthread.h index 15374a5d9..cf82f4df2 100644 --- a/src/cdo_task.h +++ b/src/workerthread.h @@ -5,18 +5,15 @@ */ -#ifndef CDO_TASK_H -#define CDO_TASK_H +#ifndef WORKERTHREAD_H +#define WORKERTHREAD_H #include <thread> #include <mutex> #include <condition_variable> #include <functional> -namespace cdo -{ - -class Task +class WorkerThread { private: enum struct State @@ -40,16 +37,14 @@ private: std::mutex bossMutex; std::condition_variable workCond; std::condition_variable_any bossCond; - static void task(Task *taskInfo); + static void task(WorkerThread *taskInfo); public: - Task(); - ~Task(); + WorkerThread(); + ~WorkerThread(); void doAsync(const std::function<void()> &_function); void start(void *(*task_routine)(void *), void *task_arg); void *wait(); }; -} // namespace cdo - -#endif /* CDO_TASK_H */ +#endif /* WORKERTHREAD_H */ -- GitLab