diff --git a/src/Afterburner.cc b/src/Afterburner.cc index 6f524e29f5417348488defc3b7fb1642a077df43..8e495115597be881b731ecb29b8e8c7205e7e370 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 d5772694ebf2e86a924dfbb1e14d85aff37a5dbf..6091124cef7a44b57b512a8d2df937ee53489111 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 1eb9a3ea9c16f3a05eb1167702229cfef79e4f19..6e38316f43cfa04dbdf532ae3d30c41595cf83fa 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 be4c10a4bd5fddcfc73e1d3d1834a4ff72dc378e..770329f462a49699cb7657543360cef9e6774c22 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 fd95ae0390f4057dd661800689e2f5238e51e7cc..837c12f75b0fa9126d662c4211c030d126ec2c63 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 a3de0bad1a06aa7364e0ea050b20fa72fa4060f9..01954583def41b700b1b81fc6afcb38d3ba53862 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 af2b47012505674aac7209b25fc296e2d2600577..99cbf4ed4bccb234a01017cb8e7af7d3d311df50 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 96302eb9d79fa859ad6a7f1231ec8fd49a07ecf0..40071cd8e9cbc688569849eea403e67ed2115753 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 d862ba32a9e4b782552e3278325a598818e51b97..1ff05a8dea8650af524935c5d4b098b91778574e 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 bf71e2da873230bb56959312f2a370a6efd1fb9f..9fabd21e9392124dcfa82f65fd01ca07b8d24e83 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 0e53c8964286f95beeac8de7d15a8541b963994c..51cac9f371c842b11a6f66511516f880dd44e63f 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 d41a59200c5a6cdbd53a1e84ea6d2300e4049541..48871943dec41ba1fcd5c6d651b7a95c8290d0ed 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 15374a5d952a8a59d6d6fde15ca7e4e2d12ad030..cf82f4df2bbe4e1bdf700e8af3e017db6672b2cc 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 */