///////////////////////////////////////////////////////////////////// // Task.cpp - Enqueue work item to run on a threadpool thread // // // // Jim Fawcett, CSE687 - Object Oriented Design, Spring 2016 // ///////////////////////////////////////////////////////////////////// #include "Task.h" #include "../Utilities/Utilities.h" #include "../Logger/Logger.h" #include #include ThreadPool Task::trpl_; // declare static member using DebugLog = StaticLogger<1>; using Show = StaticLogger<0>; void Task::workItem(CallObj* pCo) { trpl_.workItem(pCo); } void Task::wait() { trpl_.wait(); } //----< test stub >-------------------------------------------------- #ifdef TEST_TASK #include using namespace std::chrono_literals; using namespace Utilities; using Utils = StringHelper; int main() { Utils::Title("Testing Task Class"); Show::attach(&std::cout); Show::start(); DebugLog::attach(&std::cout); //DebugLog::start(); Task tsk; Task::CallObj co = [&tsk]() { Show::write( "\n hello from thread " + Utilities::Converter::toString(std::this_thread::get_id()) ); std::this_thread::sleep_for(5ms); }; for (size_t i = 0; i < 20; ++i) { tsk.workItem(&co); } tsk.workItem(nullptr); tsk.wait(); } #endif