diff --git a/CMakeLists.txt b/CMakeLists.txt index fbbad63..11fddd8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -125,7 +125,7 @@ CheckPartestInstall(${BUILD_TESTS} partest_includepath partest_libpath) add_subdirectory(base_c) add_subdirectory(base_cpp) add_subdirectory(mtapi_c) -add_subdirectory(mtapi_cpp) +add_subdirectory(tasks_cpp) add_subdirectory(mtapi_cpp_ext) add_subdirectory(containers_cpp) add_subdirectory(algorithms_cpp) diff --git a/tasks_cpp/CMakeLists.txt b/tasks_cpp/CMakeLists.txt index 19a6353..31effbf 100644 --- a/tasks_cpp/CMakeLists.txt +++ b/tasks_cpp/CMakeLists.txt @@ -1,20 +1,20 @@ -project (project_mtapi_cpp) +project (project_tasks_cpp) -file(GLOB_RECURSE EMBB_MTAPI_CPP_SOURCES "src/*.cc" "src/*.h") -file(GLOB_RECURSE EMBB_MTAPI_CPP_HEADERS "include/*.h") -file(GLOB_RECURSE EMBB_MTAPI_CPP_TEST_SOURCES "test/*.cc" "test/*.h") +file(GLOB_RECURSE EMBB_TASKS_CPP_SOURCES "src/*.cc" "src/*.h") +file(GLOB_RECURSE EMBB_TASKS_CPP_HEADERS "include/*.h") +file(GLOB_RECURSE EMBB_TASKS_CPP_TEST_SOURCES "test/*.cc" "test/*.h") if (USE_AUTOMATIC_INITIALIZATION STREQUAL ON) message("-- Automatic initialization enabled (default)") - set(MTAPI_CPP_AUTOMATIC_INITIALIZE 1) + set(TASKS_CPP_AUTOMATIC_INITIALIZE 1) else() - set(MTAPI_CPP_AUTOMATIC_INITIALIZE 0) + set(TASKS_CPP_AUTOMATIC_INITIALIZE 0) message("-- Automatic initialization disabled") endif() message(" (set with command line option -DUSE_AUTOMATIC_INITIALIZATION=ON/OFF)") -configure_file("include/embb/mtapi/internal/cmake_config.h.in" - "include/embb/mtapi/internal/cmake_config.h") +configure_file("include/embb/tasks/internal/cmake_config.h.in" + "include/embb/tasks/internal/cmake_config.h") # Execute the GroupSources macro include(${CMAKE_SOURCE_DIR}/CMakeCommon/GroupSourcesMSVC.cmake) @@ -22,8 +22,8 @@ GroupSourcesMSVC(include) GroupSourcesMSVC(src) GroupSourcesMSVC(test) -set (EMBB_MTAPI_CPP_INCLUDE_DIRS "include" "src" "test") -include_directories(${EMBB_MTAPI_CPP_INCLUDE_DIRS} +set (EMBB_TASKS_CPP_INCLUDE_DIRS "include" "src" "test") +include_directories(${EMBB_TASKS_CPP_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/../base_c/include ${CMAKE_CURRENT_BINARY_DIR}/../base_c/include @@ -31,19 +31,19 @@ include_directories(${EMBB_MTAPI_CPP_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR}/../base_cpp/include ${CMAKE_CURRENT_SOURCE_DIR}/../mtapi_c/include) -add_library (embb_mtapi_cpp ${EMBB_MTAPI_CPP_SOURCES} ${EMBB_MTAPI_CPP_HEADERS}) -target_link_libraries(embb_mtapi_cpp embb_mtapi_c) +add_library (embb_tasks_cpp ${EMBB_TASKS_CPP_SOURCES} ${EMBB_TASKS_CPP_HEADERS}) +target_link_libraries(embb_tasks_cpp embb_mtapi_c) if (BUILD_TESTS STREQUAL ON) include_directories(${CMAKE_CURRENT_BINARY_DIR}/../partest/include) - add_executable (embb_mtapi_cpp_test ${EMBB_MTAPI_CPP_TEST_SOURCES}) - target_link_libraries(embb_mtapi_cpp_test embb_mtapi_cpp embb_mtapi_c partest + add_executable (embb_tasks_cpp_test ${EMBB_TASKS_CPP_TEST_SOURCES}) + target_link_libraries(embb_tasks_cpp_test embb_tasks_cpp embb_mtapi_c partest embb_base_cpp embb_base_c ${compiler_libs}) - CopyBin(BIN embb_mtapi_cpp_test DEST ${local_install_dir}) + CopyBin(BIN embb_tasks_cpp_test DEST ${local_install_dir}) endif() install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION include FILES_MATCHING PATTERN "*.h") install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/ DESTINATION include FILES_MATCHING PATTERN "*.h") -install(TARGETS embb_mtapi_cpp DESTINATION lib) +install(TARGETS embb_tasks_cpp DESTINATION lib) diff --git a/tasks_cpp/include/embb/mtapi/action.h b/tasks_cpp/include/embb/tasks/action.h similarity index 92% rename from tasks_cpp/include/embb/mtapi/action.h rename to tasks_cpp/include/embb/tasks/action.h index 68e9776..69b6132 100644 --- a/tasks_cpp/include/embb/mtapi/action.h +++ b/tasks_cpp/include/embb/tasks/action.h @@ -24,15 +24,15 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EMBB_MTAPI_ACTION_H_ -#define EMBB_MTAPI_ACTION_H_ +#ifndef EMBB_TASKS_ACTION_H_ +#define EMBB_TASKS_ACTION_H_ #include -#include -#include +#include +#include namespace embb { -namespace mtapi { +namespace tasks { /** * A function to be spawned as a Task. @@ -103,7 +103,7 @@ class Action { ExecutionPolicy execution_policy_; }; -} // namespace mtapi +} // namespace tasks } // namespace embb -#endif // EMBB_MTAPI_ACTION_H_ +#endif // EMBB_TASKS_ACTION_H_ diff --git a/tasks_cpp/include/embb/mtapi/continuation.h b/tasks_cpp/include/embb/tasks/continuation.h similarity index 86% rename from tasks_cpp/include/embb/mtapi/continuation.h rename to tasks_cpp/include/embb/tasks/continuation.h index 29789a2..666df75 100644 --- a/tasks_cpp/include/embb/mtapi/continuation.h +++ b/tasks_cpp/include/embb/tasks/continuation.h @@ -24,66 +24,66 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EMBB_MTAPI_CONTINUATION_H_ -#define EMBB_MTAPI_CONTINUATION_H_ +#ifndef EMBB_TASKS_CONTINUATION_H_ +#define EMBB_TASKS_CONTINUATION_H_ #include -#include -#include -#include +#include +#include +#include namespace embb { -namespace mtapi { +namespace tasks { /** - * Helper struct for Continuation. - * - * \ingroup CPP_MTAPI - */ + * Helper struct for Continuation. + * + * \ingroup CPP_TASKS + */ struct ContinuationStage; /** - * A Continuation encapsulates a chain of \link Action Actions \endlink to be - * executed consecutively. - * - * \ingroup CPP_MTAPI - */ + * A Continuation encapsulates a chain of \link Action Actions \endlink to be + * executed consecutively. + * + * \ingroup CPP_TASKS + */ class Continuation { public: /** - * Copy constructor. - */ + * Copies a Continuation. + */ Continuation( Continuation const & cont /**< [in] The Continuation to copy. */ ); /** - * Destructor. - */ + * Destroys a Continuation. + */ ~Continuation(); /** - * Appends an Action to the Continuation chain. - * \returns A reference to this Continuation chain. - * \notthreadsafe - */ + * Appends an Action to the Continuation chain. + * \returns A reference to this Continuation chain. + * \notthreadsafe + */ Continuation & Then( Action action /**< [in] The Action to append to the continuation */ ); /** - * Runs the Continuation chain. - * \returns The Task representing the Continuation chain. - * \notthreadsafe - */ + * Runs the Continuation chain. + * \returns The Task representing the Continuation chain. + * \notthreadsafe + */ Task Spawn(); /** - * Runs the Continuation chain with the specified execution_policy. - * \returns The Task representing the Continuation chain. - * \notthreadsafe - */ + * Runs the Continuation chain with the specified execution_policy. + * \returns The Task representing the Continuation chain. + * \notthreadsafe + */ Task Spawn( ExecutionPolicy execution_policy /**< [in] The execution policy to use */ ); @@ -99,7 +99,7 @@ class Continuation { ContinuationStage * last_; }; -} // namespace mtapi +} // namespace tasks } // namespace embb -#endif // EMBB_MTAPI_CONTINUATION_H_ +#endif // EMBB_TASKS_CONTINUATION_H_ diff --git a/tasks_cpp/include/embb/mtapi/execution_policy.h b/tasks_cpp/include/embb/tasks/execution_policy.h similarity index 96% rename from tasks_cpp/include/embb/mtapi/execution_policy.h rename to tasks_cpp/include/embb/tasks/execution_policy.h index 85727f3..8a9a019 100644 --- a/tasks_cpp/include/embb/mtapi/execution_policy.h +++ b/tasks_cpp/include/embb/tasks/execution_policy.h @@ -24,13 +24,14 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EMBB_MTAPI_EXECUTION_POLICY_H_ -#define EMBB_MTAPI_EXECUTION_POLICY_H_ +#ifndef EMBB_TASKS_EXECUTION_POLICY_H_ +#define EMBB_TASKS_EXECUTION_POLICY_H_ #include namespace embb { -namespace mtapi { +namespace tasks { + /** * Describes the execution policy of a parallel algorithm. * The execution policy comprises @@ -41,7 +42,7 @@ namespace mtapi { * max_priorities - 1 as given during initialization using Node::Initialize(). * The default value of max_priorities is 4. * - * \ingroup CPP_MTAPI + * \ingroup CPP_TASKS */ class ExecutionPolicy{ public: @@ -145,7 +146,8 @@ class ExecutionPolicy{ */ mtapi_uint_t priority_; }; -} // namespace mtapi + +} // namespace tasks } // namespace embb -#endif // EMBB_MTAPI_EXECUTION_POLICY_H_ +#endif // EMBB_TASKS_EXECUTION_POLICY_H_ diff --git a/tasks_cpp/include/embb/mtapi/group.h b/tasks_cpp/include/embb/tasks/group.h similarity index 92% rename from tasks_cpp/include/embb/mtapi/group.h rename to tasks_cpp/include/embb/tasks/group.h index b3c4906..039fe1d 100644 --- a/tasks_cpp/include/embb/mtapi/group.h +++ b/tasks_cpp/include/embb/tasks/group.h @@ -24,12 +24,12 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EMBB_MTAPI_GROUP_H_ -#define EMBB_MTAPI_GROUP_H_ +#ifndef EMBB_TASKS_GROUP_H_ +#define EMBB_TASKS_GROUP_H_ #include -#include -#include +#include +#include namespace embb { @@ -39,13 +39,13 @@ class Allocation; } // namespace base -namespace mtapi { +namespace tasks { /** * Represents a facility to wait for multiple related * \link Task Tasks\endlink. * - * \ingroup CPP_MTAPI + * \ingroup CPP_TASKS */ class Group { public: @@ -119,7 +119,7 @@ class Group { mtapi_group_hndl_t handle_; }; -} // namespace mtapi +} // namespace tasks } // namespace embb -#endif // EMBB_MTAPI_GROUP_H_ +#endif // EMBB_TASKS_GROUP_H_ diff --git a/tasks_cpp/include/embb/mtapi/internal/cmake_config.h.in b/tasks_cpp/include/embb/tasks/internal/cmake_config.h.in similarity index 83% rename from tasks_cpp/include/embb/mtapi/internal/cmake_config.h.in rename to tasks_cpp/include/embb/tasks/internal/cmake_config.h.in index 32af64c..400139a 100644 --- a/tasks_cpp/include/embb/mtapi/internal/cmake_config.h.in +++ b/tasks_cpp/include/embb/tasks/internal/cmake_config.h.in @@ -24,18 +24,18 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EMBB_MTAPI_INTERNAL_CMAKE_CONFIG_H_ -#define EMBB_MTAPI_INTERNAL_CMAKE_CONFIG_H_ +#ifndef EMBB_TASKS_INTERNAL_CMAKE_CONFIG_H_ +#define EMBB_TASKS_INTERNAL_CMAKE_CONFIG_H_ /* This file is used as input for CMake. CMake creates a file cmake_config.h in - its current build directory under the path builddir/embb/mtapi/internal/. From + its current build directory under the path builddir/embb/tasks/internal/. From there, the cmake_config.h can be included as usual using - #include + #include */ /** * Is used to enable automatic initialization of the MTAPI node */ -#define MTAPI_CPP_AUTOMATIC_INITIALIZE ${MTAPI_CPP_AUTOMATIC_INITIALIZE} +#define TASKS_CPP_AUTOMATIC_INITIALIZE ${TASKS_CPP_AUTOMATIC_INITIALIZE} -#endif // EMBB_MTAPI_INTERNAL_CMAKE_CONFIG_H_ +#endif // EMBB_TASKS_INTERNAL_CMAKE_CONFIG_H_ diff --git a/tasks_cpp/include/embb/mtapi/node.h b/tasks_cpp/include/embb/tasks/node.h similarity index 93% rename from tasks_cpp/include/embb/mtapi/node.h rename to tasks_cpp/include/embb/tasks/node.h index a7c5d99..094b34d 100644 --- a/tasks_cpp/include/embb/mtapi/node.h +++ b/tasks_cpp/include/embb/tasks/node.h @@ -24,17 +24,17 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EMBB_MTAPI_NODE_H_ -#define EMBB_MTAPI_NODE_H_ +#ifndef EMBB_TASKS_NODE_H_ +#define EMBB_TASKS_NODE_H_ #include #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include namespace embb { @@ -44,12 +44,12 @@ class Allocation; } // namespace base -namespace mtapi { +namespace tasks { /** * A singleton representing the MTAPI runtime. * - * \ingroup CPP_MTAPI + * \ingroup CPP_TASKS */ class Node { public: @@ -225,7 +225,7 @@ class Node { std::list groups_; }; -} // namespace mtapi +} // namespace tasks } // namespace embb -#endif // EMBB_MTAPI_NODE_H_ +#endif // EMBB_TASKS_NODE_H_ diff --git a/tasks_cpp/include/embb/mtapi/queue.h b/tasks_cpp/include/embb/tasks/queue.h similarity index 90% rename from tasks_cpp/include/embb/mtapi/queue.h rename to tasks_cpp/include/embb/tasks/queue.h index 4671359..df9f303 100644 --- a/tasks_cpp/include/embb/mtapi/queue.h +++ b/tasks_cpp/include/embb/tasks/queue.h @@ -24,13 +24,13 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EMBB_MTAPI_QUEUE_H_ -#define EMBB_MTAPI_QUEUE_H_ +#ifndef EMBB_TASKS_QUEUE_H_ +#define EMBB_TASKS_QUEUE_H_ #include -#include -#include -#include +#include +#include +#include namespace embb { @@ -40,12 +40,12 @@ class Allocation; } // namespace base -namespace mtapi { +namespace tasks { /** * Allows for stream processing, either ordered or unordered. * - * \ingroup CPP_MTAPI + * \ingroup CPP_TASKS */ class Queue { public: @@ -110,7 +110,7 @@ class Queue { mtapi_queue_hndl_t handle_; }; -} // namespace mtapi +} // namespace tasks } // namespace embb -#endif // EMBB_MTAPI_QUEUE_H_ +#endif // EMBB_TASKS_QUEUE_H_ diff --git a/tasks_cpp/include/embb/mtapi/task.h b/tasks_cpp/include/embb/tasks/task.h similarity index 92% rename from tasks_cpp/include/embb/mtapi/task.h rename to tasks_cpp/include/embb/tasks/task.h index a98e09a..fd86b40 100644 --- a/tasks_cpp/include/embb/mtapi/task.h +++ b/tasks_cpp/include/embb/tasks/task.h @@ -24,19 +24,19 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EMBB_MTAPI_TASK_H_ -#define EMBB_MTAPI_TASK_H_ +#ifndef EMBB_TASKS_TASK_H_ +#define EMBB_TASKS_TASK_H_ #include -#include +#include namespace embb { -namespace mtapi { +namespace tasks { /** * A Task represents a running Action. * - * \ingroup CPP_MTAPI + * \ingroup CPP_TASKS */ class Task { public: @@ -109,7 +109,7 @@ class Task { mtapi_task_hndl_t handle_; }; -} // namespace mtapi +} // namespace tasks } // namespace embb -#endif // EMBB_MTAPI_TASK_H_ +#endif // EMBB_TASKS_TASK_H_ diff --git a/tasks_cpp/include/embb/mtapi/taskcontext.h b/tasks_cpp/include/embb/tasks/task_context.h similarity index 91% rename from tasks_cpp/include/embb/mtapi/taskcontext.h rename to tasks_cpp/include/embb/tasks/task_context.h index 955991d..ecb416e 100644 --- a/tasks_cpp/include/embb/mtapi/taskcontext.h +++ b/tasks_cpp/include/embb/tasks/task_context.h @@ -24,18 +24,18 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EMBB_MTAPI_TASKCONTEXT_H_ -#define EMBB_MTAPI_TASKCONTEXT_H_ +#ifndef EMBB_TASKS_TASK_CONTEXT_H_ +#define EMBB_TASKS_TASK_CONTEXT_H_ #include namespace embb { -namespace mtapi { +namespace tasks { /** * Provides information about the status of the currently running Task. * - * \ingroup CPP_MTAPI + * \ingroup CPP_TASKS */ class TaskContext { public: @@ -72,7 +72,7 @@ class TaskContext { mtapi_task_context_t * context_; }; -} // namespace mtapi +} // namespace tasks } // namespace embb -#endif // EMBB_MTAPI_TASKCONTEXT_H_ +#endif // EMBB_TASKS_TASK_CONTEXT_H_ diff --git a/tasks_cpp/include/embb/mtapi/mtapi.h b/tasks_cpp/include/embb/tasks/tasks.h similarity index 60% rename from tasks_cpp/include/embb/mtapi/mtapi.h rename to tasks_cpp/include/embb/tasks/tasks.h index 4c83834..11e8d12 100644 --- a/tasks_cpp/include/embb/mtapi/mtapi.h +++ b/tasks_cpp/include/embb/tasks/tasks.h @@ -24,32 +24,30 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EMBB_MTAPI_MTAPI_H_ -#define EMBB_MTAPI_MTAPI_H_ +#ifndef EMBB_TASKS_TASKS_H_ +#define EMBB_TASKS_TASKS_H_ /** - * \defgroup CPP_MTAPI MTAPI - * C++ wrapper around C implementation of MTAPI. - * For a description of the basic concepts, see the - * \ref C_MTAPI "C implementation of MTAPI". + * \defgroup CPP_TASKS Tasks + * Simple task management based on MTAPI. * \ingroup CPP */ -#include +#include -#define MTAPI_CPP_TASK_JOB 1 -#if MTAPI_CPP_AUTOMATIC_INITIALIZE -#define MTAPI_CPP_AUTOMATIC_DOMAIN_ID 1 -#define MTAPI_CPP_AUTOMATIC_NODE_ID 1 +#define TASKS_CPP_JOB 1 +#if TASKS_CPP_AUTOMATIC_INITIALIZE +#define TASKS_CPP_AUTOMATIC_DOMAIN_ID 1 +#define TASKS_CPP_AUTOMATIC_NODE_ID 1 #endif -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include -#endif // EMBB_MTAPI_MTAPI_H_ +#endif // EMBB_TASKS_TASKS_H_ diff --git a/tasks_cpp/src/continuation.cc b/tasks_cpp/src/continuation.cc index 40bbc30..35b9d65 100644 --- a/tasks_cpp/src/continuation.cc +++ b/tasks_cpp/src/continuation.cc @@ -28,12 +28,12 @@ #include #include -#include +#include #include namespace embb { -namespace mtapi { +namespace tasks { Continuation::Continuation(Action action) { first_ = last_ = embb::base::Allocation::New(); @@ -50,10 +50,10 @@ Continuation::~Continuation() { } void Continuation::ExecuteContinuation(TaskContext &) { - mtapi::ContinuationStage * stage = first_; - mtapi::Node & node = mtapi::Node::GetInstance(); + ContinuationStage * stage = first_; + Node & node = Node::GetInstance(); while (NULL != stage) { - mtapi::Task task = node.Spawn(stage->action); + Task task = node.Spawn(stage->action); task.Wait(MTAPI_INFINITE); stage = stage->next; } @@ -61,7 +61,7 @@ void Continuation::ExecuteContinuation(TaskContext &) { // delete stages stage = first_; while (NULL != stage) { - mtapi::ContinuationStage * next = stage->next; + ContinuationStage * next = stage->next; embb::base::Allocation::Delete(stage); stage = next; } @@ -90,5 +90,5 @@ Task Continuation::Spawn(ExecutionPolicy execution_policy) { ExecutionPolicy(execution_policy))); } -} // namespace mtapi +} // namespace tasks } // namespace embb diff --git a/tasks_cpp/src/continuationstage.h b/tasks_cpp/src/continuationstage.h index 1f37607..9c1f5b0 100644 --- a/tasks_cpp/src/continuationstage.h +++ b/tasks_cpp/src/continuationstage.h @@ -24,20 +24,20 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef MTAPI_CPP_SRC_CONTINUATIONSTAGE_H_ -#define MTAPI_CPP_SRC_CONTINUATIONSTAGE_H_ +#ifndef TASKS_CPP_SRC_CONTINUATIONSTAGE_H_ +#define TASKS_CPP_SRC_CONTINUATIONSTAGE_H_ -#include +#include namespace embb { -namespace mtapi { +namespace tasks { struct ContinuationStage { - mtapi::Action action; + Action action; ContinuationStage * next; }; -} // namespace mtapi +} // namespace tasks } // namespace embb -#endif // MTAPI_CPP_SRC_CONTINUATIONSTAGE_H_ +#endif // TASKS_CPP_SRC_CONTINUATIONSTAGE_H_ diff --git a/tasks_cpp/src/execution_policy.cc b/tasks_cpp/src/execution_policy.cc index 157d0ac..bb25954 100644 --- a/tasks_cpp/src/execution_policy.cc +++ b/tasks_cpp/src/execution_policy.cc @@ -24,14 +24,14 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include -#include +#include +#include #include #include #include namespace embb { -namespace mtapi { +namespace tasks { ExecutionPolicy::ExecutionPolicy() : priority_(DefaultPriority) { @@ -120,5 +120,5 @@ mtapi_uint_t ExecutionPolicy::GetPriority() const { const mtapi_uint_t ExecutionPolicy::DefaultPriority = 0; -} // namespace mtapi +} // namespace tasks } // namespace embb diff --git a/tasks_cpp/src/group.cc b/tasks_cpp/src/group.cc index 20dc0b2..709290f 100644 --- a/tasks_cpp/src/group.cc +++ b/tasks_cpp/src/group.cc @@ -28,10 +28,10 @@ #include #include -#include +#include namespace embb { -namespace mtapi { +namespace tasks { Group::Group() { Create(); @@ -92,5 +92,5 @@ mtapi_status_t Group::WaitAll(mtapi_timeout_t timeout) { return status; } -} // namespace mtapi +} // namespace tasks } // namespace embb diff --git a/tasks_cpp/src/node.cc b/tasks_cpp/src/node.cc index 0ffe21a..362252c 100644 --- a/tasks_cpp/src/node.cc +++ b/tasks_cpp/src/node.cc @@ -31,22 +31,22 @@ #include #include -#include -#if MTAPI_CPP_AUTOMATIC_INITIALIZE +#include +#if TASKS_CPP_AUTOMATIC_INITIALIZE #include #endif namespace { -static embb::mtapi::Node * node_instance = NULL; -#if MTAPI_CPP_AUTOMATIC_INITIALIZE +static embb::tasks::Node * node_instance = NULL; +#if TASKS_CPP_AUTOMATIC_INITIALIZE static embb::base::Mutex init_mutex; #endif } namespace embb { -namespace mtapi { +namespace tasks { void Node::action_func( const void* args, @@ -56,9 +56,9 @@ void Node::action_func( const void* /*node_local_data*/, mtapi_size_t /*node_local_data_size*/, mtapi_task_context_t * context) { - mtapi::Action * action = - reinterpret_cast(const_cast(args)); - mtapi::TaskContext task_context(context); + Action * action = + reinterpret_cast(const_cast(args)); + TaskContext task_context(context); (*action)(task_context); embb::base::Allocation::Delete(action); } @@ -76,7 +76,7 @@ Node::Node( } core_count_ = info.hardware_concurrency; worker_thread_count_ = embb_core_set_count(&attr->core_affinity); - action_handle_ = mtapi_action_create(MTAPI_CPP_TASK_JOB, action_func, + action_handle_ = mtapi_action_create(TASKS_CPP_JOB, action_func, MTAPI_NULL, 0, MTAPI_NULL, &status); if (MTAPI_SUCCESS != status) { EMBB_THROW(embb::base::ErrorException, @@ -201,12 +201,12 @@ bool Node::IsInitialized() { } Node & Node::GetInstance() { -#if MTAPI_CPP_AUTOMATIC_INITIALIZE +#if TASKS_CPP_AUTOMATIC_INITIALIZE if (!IsInitialized()) { init_mutex.Lock(); if (!IsInitialized()) { Node::Initialize( - MTAPI_CPP_AUTOMATIC_DOMAIN_ID, MTAPI_CPP_AUTOMATIC_NODE_ID); + TASKS_CPP_AUTOMATIC_DOMAIN_ID, TASKS_CPP_AUTOMATIC_NODE_ID); atexit(Node::Finalize); } init_mutex.Unlock(); @@ -217,7 +217,7 @@ Node & Node::GetInstance() { return *node_instance; } else { EMBB_THROW(embb::base::ErrorException, - "mtapi::Node is not initialized"); + "embb::tasks::Node is not initialized"); } #endif } @@ -228,7 +228,7 @@ void Node::Finalize() { node_instance = NULL; } else { EMBB_THROW(embb::base::ErrorException, - "mtapi::Node is not initialized"); + "embb::tasks::Node is not initialized"); } } @@ -270,5 +270,5 @@ Continuation Node::First(Action action) { return Continuation(action); } -} // namespace mtapi +} // namespace tasks } // namespace embb diff --git a/tasks_cpp/src/queue.cc b/tasks_cpp/src/queue.cc index a6e8371..04e94b8 100644 --- a/tasks_cpp/src/queue.cc +++ b/tasks_cpp/src/queue.cc @@ -27,10 +27,10 @@ #include #include -#include +#include namespace embb { -namespace mtapi { +namespace tasks { Queue::Queue(mtapi_uint_t priority, bool ordered) { mtapi_status_t status; @@ -51,7 +51,7 @@ Queue::Queue(mtapi_uint_t priority, bool ordered) { assert(MTAPI_SUCCESS == status); mtapi_domain_t domain_id = mtapi_domain_id_get(&status); assert(MTAPI_SUCCESS == status); - mtapi_job_hndl_t job = mtapi_job_get(MTAPI_CPP_TASK_JOB, domain_id, &status); + mtapi_job_hndl_t job = mtapi_job_get(TASKS_CPP_JOB, domain_id, &status); assert(MTAPI_SUCCESS == status); handle_ = mtapi_queue_create(MTAPI_QUEUE_ID_NONE, job, &attr, &status); if (MTAPI_SUCCESS != status) { @@ -86,5 +86,5 @@ Task Queue::Spawn(Group const * group, Action action) { return Task(action, handle_, group->handle_); } -} // namespace mtapi +} // namespace tasks } // namespace embb diff --git a/tasks_cpp/src/task.cc b/tasks_cpp/src/task.cc index 5239a3c..eaba40d 100644 --- a/tasks_cpp/src/task.cc +++ b/tasks_cpp/src/task.cc @@ -29,10 +29,10 @@ #include #include -#include +#include namespace embb { -namespace mtapi { +namespace tasks { Task::Task() { handle_.id = 0; @@ -59,7 +59,7 @@ Task::Task( assert(MTAPI_SUCCESS == status); mtapi_domain_t domain_id = mtapi_domain_id_get(&status); assert(MTAPI_SUCCESS == status); - mtapi_job_hndl_t job = mtapi_job_get(MTAPI_CPP_TASK_JOB, domain_id, &status); + mtapi_job_hndl_t job = mtapi_job_get(TASKS_CPP_JOB, domain_id, &status); assert(MTAPI_SUCCESS == status); Action* holder = embb::base::Allocation::New(action); handle_ = mtapi_task_start(MTAPI_TASK_ID_NONE, job, @@ -86,7 +86,7 @@ Task::Task( assert(MTAPI_SUCCESS == status); mtapi_domain_t domain_id = mtapi_domain_id_get(&status); assert(MTAPI_SUCCESS == status); - mtapi_job_hndl_t job = mtapi_job_get(MTAPI_CPP_TASK_JOB, domain_id, &status); + mtapi_job_hndl_t job = mtapi_job_get(TASKS_CPP_JOB, domain_id, &status); assert(MTAPI_SUCCESS == status); Action* holder = embb::base::Allocation::New(action); handle_ = mtapi_task_start(MTAPI_TASK_ID_NONE, job, @@ -114,7 +114,7 @@ Task::Task( assert(MTAPI_SUCCESS == status); mtapi_domain_t domain_id = mtapi_domain_id_get(&status); assert(MTAPI_SUCCESS == status); - mtapi_job_hndl_t job = mtapi_job_get(MTAPI_CPP_TASK_JOB, domain_id, &status); + mtapi_job_hndl_t job = mtapi_job_get(TASKS_CPP_JOB, domain_id, &status); assert(MTAPI_SUCCESS == status); Action* holder = embb::base::Allocation::New(action); void * idptr = MTAPI_NULL; @@ -216,5 +216,5 @@ void Task::Cancel() { assert(MTAPI_SUCCESS == status); } -} // namespace mtapi +} // namespace tasks } // namespace embb diff --git a/tasks_cpp/src/taskcontext.cc b/tasks_cpp/src/task_context.cc similarity index 94% rename from tasks_cpp/src/taskcontext.cc rename to tasks_cpp/src/task_context.cc index 71e28b3..bba9312 100644 --- a/tasks_cpp/src/taskcontext.cc +++ b/tasks_cpp/src/task_context.cc @@ -26,10 +26,10 @@ #include -#include +#include namespace embb { -namespace mtapi { +namespace tasks { TaskContext::TaskContext(mtapi_task_context_t * task_context) : context_(task_context) { @@ -57,5 +57,5 @@ void TaskContext::SetStatus(mtapi_status_t error_code) { assert(MTAPI_SUCCESS == status); } -} // namespace mtapi +} // namespace tasks } // namespace embb diff --git a/tasks_cpp/test/main.cc b/tasks_cpp/test/main.cc index f5aa24a..f46b112 100644 --- a/tasks_cpp/test/main.cc +++ b/tasks_cpp/test/main.cc @@ -28,12 +28,12 @@ #include -#include -#include -#include +#include +#include +#include -PT_MAIN("MTAPI C++") { +PT_MAIN("TASKS") { PT_RUN(TaskTest); PT_RUN(GroupTest); PT_RUN(QueueTest); diff --git a/tasks_cpp/test/mtapi_cpp_test_config.h b/tasks_cpp/test/tasks_cpp_test_config.h similarity index 87% rename from tasks_cpp/test/mtapi_cpp_test_config.h rename to tasks_cpp/test/tasks_cpp_test_config.h index 4b3c2d7..b7244c3 100644 --- a/tasks_cpp/test/mtapi_cpp_test_config.h +++ b/tasks_cpp/test/tasks_cpp_test_config.h @@ -24,13 +24,13 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef MTAPI_CPP_TEST_MTAPI_CPP_TEST_CONFIG_H_ -#define MTAPI_CPP_TEST_MTAPI_CPP_TEST_CONFIG_H_ +#ifndef TASKS_CPP_TEST_TASKS_CPP_TEST_CONFIG_H_ +#define TASKS_CPP_TEST_TASKS_CPP_TEST_CONFIG_H_ #include -#include +#include #define THIS_DOMAIN_ID 1 #define THIS_NODE_ID 1 -#endif // MTAPI_CPP_TEST_MTAPI_CPP_TEST_CONFIG_H_ +#endif // TASKS_CPP_TEST_TASKS_CPP_TEST_CONFIG_H_ diff --git a/tasks_cpp/test/mtapi_cpp_test_group.cc b/tasks_cpp/test/tasks_cpp_test_group.cc similarity index 85% rename from tasks_cpp/test/mtapi_cpp_test_group.cc rename to tasks_cpp/test/tasks_cpp_test_group.cc index 6645dd5..6173e90 100644 --- a/tasks_cpp/test/mtapi_cpp_test_group.cc +++ b/tasks_cpp/test/tasks_cpp_test_group.cc @@ -26,8 +26,8 @@ #include -#include -#include +#include +#include #include @@ -38,7 +38,7 @@ struct result_example_struct { typedef struct result_example_struct result_example_t; -static void testGroupAction(embb::mtapi::TaskContext & /*context*/) { +static void testGroupAction(embb::tasks::TaskContext & /*context*/) { //std::cout << "testGroupAction on core " << // context.GetCurrentCoreNumber() << std::endl; } @@ -47,17 +47,17 @@ static void testDoSomethingElse() { } GroupTest::GroupTest() { - CreateUnit("mtapi group test").Add(&GroupTest::TestBasic, this); + CreateUnit("tasks_cpp group test").Add(&GroupTest::TestBasic, this); } void GroupTest::TestBasic() { //std::cout << "running testGroup..." << std::endl; - embb::mtapi::Node::Initialize(THIS_DOMAIN_ID, THIS_NODE_ID); + embb::tasks::Node::Initialize(THIS_DOMAIN_ID, THIS_NODE_ID); - embb::mtapi::Node & node = embb::mtapi::Node::GetInstance(); - embb::mtapi::Group & group = node.CreateGroup(); - embb::mtapi::Task task; + embb::tasks::Node & node = embb::tasks::Node::GetInstance(); + embb::tasks::Group & group = node.CreateGroup(); + embb::tasks::Task task; //std::cout << "wait all..." << std::endl; @@ -81,8 +81,8 @@ void GroupTest::TestBasic() { node.DestroyGroup(group); - embb::mtapi::Node::Finalize(); + embb::tasks::Node::Finalize(); - PT_EXPECT(embb_get_bytes_allocated() == 0); + PT_EXPECT_EQ(embb_get_bytes_allocated(), 0u); //std::cout << "...done" << std::endl << std::endl; } diff --git a/tasks_cpp/test/mtapi_cpp_test_group.h b/tasks_cpp/test/tasks_cpp_test_group.h similarity index 91% rename from tasks_cpp/test/mtapi_cpp_test_group.h rename to tasks_cpp/test/tasks_cpp_test_group.h index 7a1cf2c..cc6c4fe 100644 --- a/tasks_cpp/test/mtapi_cpp_test_group.h +++ b/tasks_cpp/test/tasks_cpp_test_group.h @@ -24,8 +24,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef MTAPI_CPP_TEST_MTAPI_CPP_TEST_GROUP_H_ -#define MTAPI_CPP_TEST_MTAPI_CPP_TEST_GROUP_H_ +#ifndef TASKS_CPP_TEST_TASKS_CPP_TEST_GROUP_H_ +#define TASKS_CPP_TEST_TASKS_CPP_TEST_GROUP_H_ #include @@ -37,4 +37,4 @@ class GroupTest : public partest::TestCase { void TestBasic(); }; -#endif // MTAPI_CPP_TEST_MTAPI_CPP_TEST_GROUP_H_ +#endif // TASKS_CPP_TEST_TASKS_CPP_TEST_GROUP_H_ diff --git a/tasks_cpp/test/mtapi_cpp_test_queue.cc b/tasks_cpp/test/tasks_cpp_test_queue.cc similarity index 81% rename from tasks_cpp/test/mtapi_cpp_test_queue.cc rename to tasks_cpp/test/tasks_cpp_test_queue.cc index b8f7145..2867c6a 100644 --- a/tasks_cpp/test/mtapi_cpp_test_queue.cc +++ b/tasks_cpp/test/tasks_cpp_test_queue.cc @@ -26,8 +26,8 @@ #include -#include -#include +#include +#include #include @@ -35,7 +35,7 @@ #define TASK_TEST_ID 23 #define QUEUE_TEST_ID 17 -static void testQueueAction(embb::mtapi::TaskContext & /*context*/) { +static void testQueueAction(embb::tasks::TaskContext & /*context*/) { //std::cout << "testQueueAction on core " << // context.GetCurrentCoreNumber() << std::endl; } @@ -44,18 +44,18 @@ static void testDoSomethingElse() { } QueueTest::QueueTest() { - CreateUnit("mtapi queue test").Add(&QueueTest::TestBasic, this); + CreateUnit("tasks_cpp queue test").Add(&QueueTest::TestBasic, this); } void QueueTest::TestBasic() { //std::cout << "running testQueue..." << std::endl; - embb::mtapi::Node::Initialize(THIS_DOMAIN_ID, THIS_NODE_ID); + embb::tasks::Node::Initialize(THIS_DOMAIN_ID, THIS_NODE_ID); - embb::mtapi::Node & node = embb::mtapi::Node::GetInstance(); - embb::mtapi::Queue & queue = node.CreateQueue(0, false); + embb::tasks::Node & node = embb::tasks::Node::GetInstance(); + embb::tasks::Queue & queue = node.CreateQueue(0, false); - embb::mtapi::Task task = queue.Spawn(testQueueAction); + embb::tasks::Task task = queue.Spawn(testQueueAction); testDoSomethingElse(); @@ -63,8 +63,8 @@ void QueueTest::TestBasic() { node.DestroyQueue(queue); - embb::mtapi::Node::Finalize(); + embb::tasks::Node::Finalize(); - PT_EXPECT(embb_get_bytes_allocated() == 0); + PT_EXPECT_EQ(embb_get_bytes_allocated(), 0u); //std::cout << "...done" << std::endl << std::endl; } diff --git a/tasks_cpp/test/mtapi_cpp_test_queue.h b/tasks_cpp/test/tasks_cpp_test_queue.h similarity index 91% rename from tasks_cpp/test/mtapi_cpp_test_queue.h rename to tasks_cpp/test/tasks_cpp_test_queue.h index 9659ae2..88770ca 100644 --- a/tasks_cpp/test/mtapi_cpp_test_queue.h +++ b/tasks_cpp/test/tasks_cpp_test_queue.h @@ -24,8 +24,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef MTAPI_CPP_TEST_MTAPI_CPP_TEST_QUEUE_H_ -#define MTAPI_CPP_TEST_MTAPI_CPP_TEST_QUEUE_H_ +#ifndef TASKS_CPP_TEST_TASKS_CPP_TEST_QUEUE_H_ +#define TASKS_CPP_TEST_TASKS_CPP_TEST_QUEUE_H_ #include @@ -37,4 +37,4 @@ class QueueTest : public partest::TestCase { void TestBasic(); }; -#endif // MTAPI_CPP_TEST_MTAPI_CPP_TEST_QUEUE_H_ +#endif // TASKS_CPP_TEST_TASKS_CPP_TEST_QUEUE_H_ diff --git a/tasks_cpp/test/mtapi_cpp_test_task.cc b/tasks_cpp/test/tasks_cpp_test_task.cc similarity index 88% rename from tasks_cpp/test/mtapi_cpp_test_task.cc rename to tasks_cpp/test/tasks_cpp_test_task.cc index 88242b3..deb01ce 100644 --- a/tasks_cpp/test/mtapi_cpp_test_task.cc +++ b/tasks_cpp/test/tasks_cpp_test_task.cc @@ -28,8 +28,8 @@ #include #include -#include -#include +#include +#include #include @@ -39,7 +39,7 @@ static void testTaskAction( char const * msg, std::string * output, - embb::mtapi::TaskContext & /*context*/) { + embb::tasks::TaskContext & /*context*/) { //std::cout << "testTaskAction " << msg << " on core " << // context.GetCurrentCoreNumber() << std::endl; *output = msg; @@ -47,11 +47,11 @@ static void testTaskAction( static void testRecursiveTaskAction( int * value, - embb::mtapi::TaskContext & /*context*/) { - embb::mtapi::Node & node = embb::mtapi::Node::GetInstance(); + embb::tasks::TaskContext & /*context*/) { + embb::tasks::Node & node = embb::tasks::Node::GetInstance(); *value = *value + 1; if (*value < 1000) { - embb::mtapi::Task task = node.Spawn( + embb::tasks::Task task = node.Spawn( embb::base::Bind( testRecursiveTaskAction, value, embb::base::Placeholder::_1)); task.Wait(MTAPI_INFINITE); @@ -59,7 +59,7 @@ static void testRecursiveTaskAction( PT_EXPECT(*value == 1000); } -static void testErrorTaskAction(embb::mtapi::TaskContext & context) { +static void testErrorTaskAction(embb::tasks::TaskContext & context) { context.SetStatus(MTAPI_ERR_ACTION_FAILED); } @@ -67,17 +67,17 @@ static void testDoSomethingElse() { } TaskTest::TaskTest() { - CreateUnit("mtapi_cpp task test").Add(&TaskTest::TestBasic, this); + CreateUnit("tasks_cpp task test").Add(&TaskTest::TestBasic, this); } void TaskTest::TestBasic() { //std::cout << "running testTask..." << std::endl; - embb::mtapi::Node::Initialize(THIS_DOMAIN_ID, THIS_NODE_ID); + embb::tasks::Node::Initialize(THIS_DOMAIN_ID, THIS_NODE_ID); - embb::mtapi::Node & node = embb::mtapi::Node::GetInstance(); + embb::tasks::Node & node = embb::tasks::Node::GetInstance(); - embb::mtapi::ExecutionPolicy policy(false); + embb::tasks::ExecutionPolicy policy(false); PT_EXPECT_EQ(policy.GetAffinity(), 0u); PT_EXPECT_EQ(policy.GetPriority(), 0u); policy.AddWorker(0u); @@ -90,7 +90,7 @@ void TaskTest::TestBasic() { PT_EXPECT_EQ(policy.IsSetWorker(1), true); std::string test; - embb::mtapi::Task task = node.Spawn( + embb::tasks::Task task = node.Spawn( embb::base::Bind( testTaskAction, "simple", &test, embb::base::Placeholder::_1)); testDoSomethingElse(); @@ -129,7 +129,7 @@ void TaskTest::TestBasic() { status = task.Wait(MTAPI_INFINITE); PT_EXPECT(MTAPI_ERR_ACTION_FAILED == status); - embb::mtapi::Node::Finalize(); + embb::tasks::Node::Finalize(); PT_EXPECT(embb_get_bytes_allocated() == 0); //std::cout << "...done" << std::endl << std::endl; diff --git a/tasks_cpp/test/mtapi_cpp_test_task.h b/tasks_cpp/test/tasks_cpp_test_task.h similarity index 100% rename from tasks_cpp/test/mtapi_cpp_test_task.h rename to tasks_cpp/test/tasks_cpp_test_task.h