From 52da087e919b8cbd08a68ff43aed7675f9ddd8a8 Mon Sep 17 00:00:00 2001 From: Marcus Winter Date: Tue, 24 Mar 2015 15:44:22 +0100 Subject: [PATCH] task_cpp: refactored namespace from mtapi to tasks --- CMakeLists.txt | 2 +- tasks_cpp/CMakeLists.txt | 32 ++++++++++++++++---------------- tasks_cpp/include/embb/mtapi/action.h | 109 ------------------------------------------------------------------------------------------------------------- tasks_cpp/include/embb/mtapi/continuation.h | 105 --------------------------------------------------------------------------------------------------------- tasks_cpp/include/embb/mtapi/execution_policy.h | 151 ------------------------------------------------------------------------------------------------------------------------------------------------------- tasks_cpp/include/embb/mtapi/group.h | 125 ----------------------------------------------------------------------------------------------------------------------------- tasks_cpp/include/embb/mtapi/internal/cmake_config.h.in | 41 ----------------------------------------- tasks_cpp/include/embb/mtapi/mtapi.h | 55 ------------------------------------------------------- tasks_cpp/include/embb/mtapi/node.h | 231 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- tasks_cpp/include/embb/mtapi/queue.h | 116 -------------------------------------------------------------------------------------------------------------------- tasks_cpp/include/embb/mtapi/task.h | 115 ------------------------------------------------------------------------------------------------------------------- tasks_cpp/include/embb/mtapi/taskcontext.h | 78 ------------------------------------------------------------------------------ tasks_cpp/include/embb/tasks/action.h | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tasks_cpp/include/embb/tasks/continuation.h | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tasks_cpp/include/embb/tasks/execution_policy.h | 153 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tasks_cpp/include/embb/tasks/group.h | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tasks_cpp/include/embb/tasks/internal/cmake_config.h.in | 41 +++++++++++++++++++++++++++++++++++++++++ tasks_cpp/include/embb/tasks/node.h | 231 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tasks_cpp/include/embb/tasks/queue.h | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tasks_cpp/include/embb/tasks/task.h | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tasks_cpp/include/embb/tasks/task_context.h | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tasks_cpp/include/embb/tasks/tasks.h | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ tasks_cpp/src/continuation.cc | 14 +++++++------- tasks_cpp/src/continuationstage.h | 14 +++++++------- tasks_cpp/src/execution_policy.cc | 8 ++++---- tasks_cpp/src/group.cc | 6 +++--- tasks_cpp/src/node.cc | 28 ++++++++++++++-------------- tasks_cpp/src/queue.cc | 8 ++++---- tasks_cpp/src/task.cc | 12 ++++++------ tasks_cpp/src/task_context.cc | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tasks_cpp/src/taskcontext.cc | 61 ------------------------------------------------------------- tasks_cpp/test/main.cc | 8 ++++---- tasks_cpp/test/mtapi_cpp_test_config.h | 36 ------------------------------------ tasks_cpp/test/mtapi_cpp_test_group.cc | 88 ---------------------------------------------------------------------------------------- tasks_cpp/test/mtapi_cpp_test_group.h | 40 ---------------------------------------- tasks_cpp/test/mtapi_cpp_test_queue.cc | 70 ---------------------------------------------------------------------- tasks_cpp/test/mtapi_cpp_test_queue.h | 40 ---------------------------------------- tasks_cpp/test/mtapi_cpp_test_task.cc | 136 ---------------------------------------------------------------------------------------------------------------------------------------- tasks_cpp/test/mtapi_cpp_test_task.h | 40 ---------------------------------------- tasks_cpp/test/tasks_cpp_test_config.h | 36 ++++++++++++++++++++++++++++++++++++ tasks_cpp/test/tasks_cpp_test_group.cc | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tasks_cpp/test/tasks_cpp_test_group.h | 40 ++++++++++++++++++++++++++++++++++++++++ tasks_cpp/test/tasks_cpp_test_queue.cc | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tasks_cpp/test/tasks_cpp_test_queue.h | 40 ++++++++++++++++++++++++++++++++++++++++ tasks_cpp/test/tasks_cpp_test_task.cc | 136 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tasks_cpp/test/tasks_cpp_test_task.h | 40 ++++++++++++++++++++++++++++++++++++++++ 46 files changed, 1703 insertions(+), 1703 deletions(-) delete mode 100644 tasks_cpp/include/embb/mtapi/action.h delete mode 100644 tasks_cpp/include/embb/mtapi/continuation.h delete mode 100644 tasks_cpp/include/embb/mtapi/execution_policy.h delete mode 100644 tasks_cpp/include/embb/mtapi/group.h delete mode 100644 tasks_cpp/include/embb/mtapi/internal/cmake_config.h.in delete mode 100644 tasks_cpp/include/embb/mtapi/mtapi.h delete mode 100644 tasks_cpp/include/embb/mtapi/node.h delete mode 100644 tasks_cpp/include/embb/mtapi/queue.h delete mode 100644 tasks_cpp/include/embb/mtapi/task.h delete mode 100644 tasks_cpp/include/embb/mtapi/taskcontext.h create mode 100644 tasks_cpp/include/embb/tasks/action.h create mode 100644 tasks_cpp/include/embb/tasks/continuation.h create mode 100644 tasks_cpp/include/embb/tasks/execution_policy.h create mode 100644 tasks_cpp/include/embb/tasks/group.h create mode 100644 tasks_cpp/include/embb/tasks/internal/cmake_config.h.in create mode 100644 tasks_cpp/include/embb/tasks/node.h create mode 100644 tasks_cpp/include/embb/tasks/queue.h create mode 100644 tasks_cpp/include/embb/tasks/task.h create mode 100644 tasks_cpp/include/embb/tasks/task_context.h create mode 100644 tasks_cpp/include/embb/tasks/tasks.h create mode 100644 tasks_cpp/src/task_context.cc delete mode 100644 tasks_cpp/src/taskcontext.cc delete mode 100644 tasks_cpp/test/mtapi_cpp_test_config.h delete mode 100644 tasks_cpp/test/mtapi_cpp_test_group.cc delete mode 100644 tasks_cpp/test/mtapi_cpp_test_group.h delete mode 100644 tasks_cpp/test/mtapi_cpp_test_queue.cc delete mode 100644 tasks_cpp/test/mtapi_cpp_test_queue.h delete mode 100644 tasks_cpp/test/mtapi_cpp_test_task.cc delete mode 100644 tasks_cpp/test/mtapi_cpp_test_task.h create mode 100644 tasks_cpp/test/tasks_cpp_test_config.h create mode 100644 tasks_cpp/test/tasks_cpp_test_group.cc create mode 100644 tasks_cpp/test/tasks_cpp_test_group.h create mode 100644 tasks_cpp/test/tasks_cpp_test_queue.cc create mode 100644 tasks_cpp/test/tasks_cpp_test_queue.h create mode 100644 tasks_cpp/test/tasks_cpp_test_task.cc create mode 100644 tasks_cpp/test/tasks_cpp_test_task.h 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/mtapi/action.h deleted file mode 100644 index 68e9776..0000000 --- a/tasks_cpp/include/embb/mtapi/action.h +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef EMBB_MTAPI_ACTION_H_ -#define EMBB_MTAPI_ACTION_H_ - -#include -#include -#include - -namespace embb { -namespace mtapi { - -/** - * A function to be spawned as a Task. - * - * \ingroup CPP_MTAPI - */ -class Action { - public: - /** - * Constructs an empty Action. - */ - Action() - : function_() - , execution_policy_() { - // empty - } - - /** - * Constructs an Action from a function object. - * - * \tparam Function Function object - */ - template - Action( - Function func /**< [in] Function object */ - ) - : function_(func) - , execution_policy_() { - // empty - } - - /** - * Constructs an Action from a function object and an Affinity. - * - * \tparam Function Function object - */ - template - Action( - Function func, /**< [in] Function object */ - ExecutionPolicy execution_policy /**< [in] Execution policy */ - ) - : function_(func) - , execution_policy_(execution_policy) { - // empty - } - - /** - * Executes the Action in a given TaskContext. - */ - void operator() ( - TaskContext & context /**< [in, out] Context the operator - is executed in */ - ) { - function_(context); - } - - /** - * Returns the ExecutionPolicy specified during creation. - * \return The ExecutionPolicy of the Action - * \waitfree - */ - ExecutionPolicy GetExecutionPolicy() const { - return execution_policy_; - } - - private: - embb::base::Function function_; - ExecutionPolicy execution_policy_; -}; - -} // namespace mtapi -} // namespace embb - -#endif // EMBB_MTAPI_ACTION_H_ diff --git a/tasks_cpp/include/embb/mtapi/continuation.h b/tasks_cpp/include/embb/mtapi/continuation.h deleted file mode 100644 index 29789a2..0000000 --- a/tasks_cpp/include/embb/mtapi/continuation.h +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef EMBB_MTAPI_CONTINUATION_H_ -#define EMBB_MTAPI_CONTINUATION_H_ - -#include -#include -#include -#include - -namespace embb { -namespace mtapi { - -/** - * Helper struct for Continuation. - * - * \ingroup CPP_MTAPI - */ -struct ContinuationStage; - -/** - * A Continuation encapsulates a chain of \link Action Actions \endlink to be - * executed consecutively. - * - * \ingroup CPP_MTAPI - */ -class Continuation { - public: - /** - * Copy constructor. - */ - Continuation( - Continuation const & cont /**< [in] The Continuation to copy. */ - ); - - /** - * Destructor. - */ - ~Continuation(); - - /** - * 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 - */ - Task Spawn(); - - /** - * 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 */ - ); - - friend class Node; - - private: - explicit Continuation(Action action); - - void ExecuteContinuation(TaskContext & context); - - ContinuationStage * first_; - ContinuationStage * last_; -}; - -} // namespace mtapi -} // namespace embb - -#endif // EMBB_MTAPI_CONTINUATION_H_ diff --git a/tasks_cpp/include/embb/mtapi/execution_policy.h b/tasks_cpp/include/embb/mtapi/execution_policy.h deleted file mode 100644 index 85727f3..0000000 --- a/tasks_cpp/include/embb/mtapi/execution_policy.h +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef EMBB_MTAPI_EXECUTION_POLICY_H_ -#define EMBB_MTAPI_EXECUTION_POLICY_H_ - -#include - -namespace embb { -namespace mtapi { -/** - * Describes the execution policy of a parallel algorithm. - * The execution policy comprises - * - the affinity of tasks to MTAPI worker threads (not CPU cores) and - * - the priority of the spawned tasks. - * - * The priority is a number between 0 (denoting the highest priority) to - * max_priorities - 1 as given during initialization using Node::Initialize(). - * The default value of max_priorities is 4. - * - * \ingroup CPP_MTAPI - */ -class ExecutionPolicy{ - public: - /** - * Constructs the default execution policy. - * Sets the affinity to all worker threads and the priority to the default - * value. - */ - ExecutionPolicy(); - - /** - * Constructs an execution policy with the specified affinity and priority. - */ - ExecutionPolicy( - bool initial_affinity, /**< [in] \c true sets the affinity to - all worker threads, \c false to no - worker threads. */ - mtapi_uint_t priority /**< [in] Priority for the execution - policy. */ - ); - - /** - * Constructs an execution policy with the specified priority. - * Sets the affinity to all worker threads. - */ - explicit ExecutionPolicy( - mtapi_uint_t priority /**< [in] Priority for the execution - policy. */ - ); - - /** - * Constructs an execution policy with the specified affinity. - * Sets the priority to the default value. - */ - explicit ExecutionPolicy( - bool initial_affinity /**< [in] \c true sets the affinity to - all worker threads, \c false to no - worker threads. */ - ); - - /** - * Sets affinity to a specific worker thread. - */ - void AddWorker( - mtapi_uint_t worker /**< [in] Worker thread index */ - ); - - /** - * Removes affinity to a specific worker thread. - */ - void RemoveWorker( - mtapi_uint_t worker /**< [in] Worker thread index */ - ); - - /** - * Checks if affinity to a specific worker thread is set. - * - * \return \c true if affinity is set, otherwise \c false - */ - bool IsSetWorker( - mtapi_uint_t worker /**< [in] Worker thread index */ - ); - - /** - * Returns the number of cores the policy is affine to. - * - * \return the number of cores - */ - unsigned int GetCoreCount() const; - - /** - * Returns the affinity - * - * \return the affinity - */ - const mtapi_affinity_t &GetAffinity() const; - - /** Returns the priority - * - * \return the priority - */ - mtapi_uint_t GetPriority() const; - - friend class Task; - - private: - /** - * Default priority. - * Currently set to 0 = MAX priority. - */ - static const mtapi_uint_t DefaultPriority; - - /** - * Task Affinity. - * Maps the affinity of tasks to MTAPI worker threads (not CPU cores). - */ - mtapi_affinity_t affinity_; - - /** - * Task Priority. - */ - mtapi_uint_t priority_; -}; -} // namespace mtapi -} // namespace embb - -#endif // EMBB_MTAPI_EXECUTION_POLICY_H_ diff --git a/tasks_cpp/include/embb/mtapi/group.h b/tasks_cpp/include/embb/mtapi/group.h deleted file mode 100644 index b3c4906..0000000 --- a/tasks_cpp/include/embb/mtapi/group.h +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef EMBB_MTAPI_GROUP_H_ -#define EMBB_MTAPI_GROUP_H_ - -#include -#include -#include - -namespace embb { - -namespace base { - -class Allocation; - -} // namespace base - -namespace mtapi { - -/** - * Represents a facility to wait for multiple related - * \link Task Tasks\endlink. - * - * \ingroup CPP_MTAPI - */ -class Group { - public: - /** - * Runs an Action within the Group. - * \return A Task identifying the Action to run - * \throws ErrorException if the Task object could not be constructed. - * \threadsafe - */ - Task Spawn( - Action action /**< [in] The Action to run */ - ); - - /** - * Runs an Action within the Group. The \c id is returned by WaitAny(). - * \return A Task identifying the Action to run - * \throws ErrorException if the Task object could not be constructed. - * \threadsafe - */ - Task Spawn( - mtapi_task_id_t id, /**< [in] The id to return by - WaitAny() */ - Action action /**< [in] The Action to run */ - ); - - /** - * Waits for any Task in the Group to finish for \c timeout milliseconds. - * \return The status of the Task that finished execution - * \threadsafe - */ - mtapi_status_t WaitAny( - mtapi_timeout_t timeout /**< [in] Timeout duration in - milliseconds */ - ); - - /** - * Waits for any Task in the Group to finish for \c timeout milliseconds and - * retrieves the id given in Spawn(). - * \return The status of the Task that finished execution, \c MTAPI_TIMEOUT - * or \c MTAPI_ERR_* - * \threadsafe - */ - mtapi_status_t WaitAny( - mtapi_timeout_t timeout, /**< [in] Timeout duration in - milliseconds */ - mtapi_task_id_t & id /**< [out] The id given to Spawn() */ - ); - - /** - * Waits for all Task in the Group to finish for \c timeout milliseconds. - * \return \c MTAPI_SUCCESS, \c MTAPI_TIMEOUT, \c MTAPI_ERR_* or the status - * of any failed Task - * \threadsafe - */ - mtapi_status_t WaitAll( - mtapi_timeout_t timeout /**< [in] Timeout duration in - milliseconds */ - ); - - friend class embb::base::Allocation; - friend class Node; - friend class Queue; - - private: - Group(Group const & group); - Group(); - ~Group(); - - void Create(); - - mtapi_group_hndl_t handle_; -}; - -} // namespace mtapi -} // namespace embb - -#endif // EMBB_MTAPI_GROUP_H_ diff --git a/tasks_cpp/include/embb/mtapi/internal/cmake_config.h.in b/tasks_cpp/include/embb/mtapi/internal/cmake_config.h.in deleted file mode 100644 index 32af64c..0000000 --- a/tasks_cpp/include/embb/mtapi/internal/cmake_config.h.in +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef EMBB_MTAPI_INTERNAL_CMAKE_CONFIG_H_ -#define EMBB_MTAPI_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 - there, the cmake_config.h can be included as usual using - #include - */ - -/** - * Is used to enable automatic initialization of the MTAPI node - */ -#define MTAPI_CPP_AUTOMATIC_INITIALIZE ${MTAPI_CPP_AUTOMATIC_INITIALIZE} - -#endif // EMBB_MTAPI_INTERNAL_CMAKE_CONFIG_H_ diff --git a/tasks_cpp/include/embb/mtapi/mtapi.h b/tasks_cpp/include/embb/mtapi/mtapi.h deleted file mode 100644 index 4c83834..0000000 --- a/tasks_cpp/include/embb/mtapi/mtapi.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef EMBB_MTAPI_MTAPI_H_ -#define EMBB_MTAPI_MTAPI_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". - * \ingroup CPP - */ - -#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 -#endif - -#include -#include -#include -#include -#include -#include -#include -#include - -#endif // EMBB_MTAPI_MTAPI_H_ diff --git a/tasks_cpp/include/embb/mtapi/node.h b/tasks_cpp/include/embb/mtapi/node.h deleted file mode 100644 index a7c5d99..0000000 --- a/tasks_cpp/include/embb/mtapi/node.h +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef EMBB_MTAPI_NODE_H_ -#define EMBB_MTAPI_NODE_H_ - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace embb { - -namespace base { - -class Allocation; - -} // namespace base - -namespace mtapi { - -/** - * A singleton representing the MTAPI runtime. - * - * \ingroup CPP_MTAPI - */ -class Node { - public: - /** - * Initializes the runtime singleton using default values: - * - all available cores will be used - * - maximum number of tasks is 1024 - * - maximum number of groups is 128 - * - maximum number of queues is 16 - * - maximum queue capacity is 1024 - * - maximum number of priorities is 4. - * - * \notthreadsafe - * \throws ErrorException if the singleton was already initialized or the - * Node could not be initialized. - * \memory Allocates about 200kb of memory. - */ - static void Initialize( - mtapi_domain_t domain_id, /**< [in] The domain id to use */ - mtapi_node_t node_id /**< [in] The node id to use */ - ); - - /** - * Initializes the runtime singleton. - * \notthreadsafe - * \throws ErrorException if the singleton was already initialized or the - * Node could not be initialized. - * \memory Allocates some memory depending on the values given. - */ - static void Initialize( - mtapi_domain_t domain_id, /**< [in] The domain id to use */ - mtapi_node_t node_id, /**< [in] The node id to use */ - embb::base::CoreSet const & core_set, - /**< [in] A set of cores MTAPI should - use for its worker threads */ - mtapi_uint_t max_tasks, /**< [in] Maximum number of concurrent - \link Task Tasks \endlink */ - mtapi_uint_t max_groups, /**< [in] Maximum number of concurrent - \link Group Groups \endlink */ - mtapi_uint_t max_queues, /**< [in] Maximum number of concurrent - \link Queue Queues \endlink */ - mtapi_uint_t queue_limit, /**< [in] Maximum Queue capacity */ - mtapi_uint_t max_priorities /**< [in] Maximum number of priorities, - priorities will be between 0 and - max_priorities-1 */ - ); - - /** - * Checks if runtime is initialized. - * \return \c true if the Node singleton is already initialized, false - * otherwise - * \waitfree - */ - static bool IsInitialized(); - - /** - * Gets the instance of the runtime system. - * \return Reference to the Node singleton - * \threadsafe - */ - static Node & GetInstance(); - - /** - * Shuts the runtime system down. - * \throws ErrorException if the singleton is not initialized. - * \notthreadsafe - */ - static void Finalize(); - - /** - * Returns the number of available cores. - * \return The number of available cores - * \waitfree - */ - mtapi_uint_t GetCoreCount() const { - return core_count_; - } - - /** - * Returns the number of worker threads. - * \return The number of worker threads. - * \waitfree - */ - mtapi_uint_t GetWorkerThreadCount() const { - return worker_thread_count_; - } - - /** - * Creates a Group to launch \link Task Tasks \endlink in. - * \return A reference to the created Group - * \throws ErrorException if the Group object could not be constructed. - * \threadsafe - * \memory Allocates some memory depending on the configuration of the - * runtime. - */ - Group & CreateGroup(); - - /** - * Destroys a Group. \link Task Tasks \endlink running in the Group will - * finish execution. - * \threadsafe - */ - void DestroyGroup( - Group & group /**< [in,out] The Group to destroy */ - ); - - /** - * Creates a Queue for stream processing. The queue might execute its - * \link Task Tasks \endlink either in order or unordered. - * \return A reference to the new Queue - * \throws ErrorException if the Queue object could not be constructed. - * \threadsafe - * \memory Allocates some memory depending on the configuration of the - * runtime. - */ - Queue & CreateQueue( - mtapi_uint_t priority, /**< [in] Priority of the Queue */ - bool ordered /**< [in] \c true if the Queue should be - ordered, otherwise \c false */ - ); - - /** - * Destroys a Queue. Running \link Task Tasks \endlink will be canceled. - * \threadsafe - */ - void DestroyQueue( - Queue & queue /**< [in,out] The Queue to destroy */ - ); - - /** - * Runs an Action. - * \return A Task identifying the Action to run - * \throws ErrorException if the Task object could not be constructed. - * \threadsafe - */ - Task Spawn( - Action action /**< [in] The Action to execute */ - ); - - /** - * Creates a Continuation. - * \return A Continuation chain - * \threadsafe - */ - Continuation First( - Action action /**< [in] The first Action of the - Continuation chain */ - ); - - friend class embb::base::Allocation; - - private: - Node(Node const & node); - Node( - mtapi_domain_t domain_id, - mtapi_node_t node_id, - mtapi_node_attributes_t * attr); - ~Node(); - - static void action_func( - const void* args, - mtapi_size_t args_size, - void* result_buffer, - mtapi_size_t result_buffer_size, - const void* node_local_data, - mtapi_size_t node_local_data_size, - mtapi_task_context_t * context); - - mtapi_uint_t core_count_; - mtapi_uint_t worker_thread_count_; - mtapi_action_hndl_t action_handle_; - std::list queues_; - std::list groups_; -}; - -} // namespace mtapi -} // namespace embb - -#endif // EMBB_MTAPI_NODE_H_ diff --git a/tasks_cpp/include/embb/mtapi/queue.h b/tasks_cpp/include/embb/mtapi/queue.h deleted file mode 100644 index 4671359..0000000 --- a/tasks_cpp/include/embb/mtapi/queue.h +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef EMBB_MTAPI_QUEUE_H_ -#define EMBB_MTAPI_QUEUE_H_ - -#include -#include -#include -#include - -namespace embb { - -namespace base { - -class Allocation; - -} // namespace base - -namespace mtapi { - -/** - * Allows for stream processing, either ordered or unordered. - * - * \ingroup CPP_MTAPI - */ -class Queue { - public: - /** - * Enables the Queue. \link Task Tasks \endlink enqueued while the Queue was - * disabled are executed. - * \waitfree - */ - void Enable(); - - /** - * Disables the Queue. Running \link Task Tasks \endlink are canceled. - * \waitfree - */ - void Disable(); - - /** - * Runs an Action. - * \return A Task identifying the Action to run - * \throws ErrorException if the Task object could not be constructed. - * \threadsafe - */ - Task Spawn( - Action action /**< [in] The Action to run */ - ); - - /** - * Runs an Action in the specified Group - * \return A Task identifying the Action to run - * \throws ErrorException if the Task object could not be constructed. - * \threadsafe - */ - Task Spawn( - Group const * group, /**< [in] The Group to run the Action - in */ - Action action /**< [in] The Action to run */ - ); - - /** - * Runs an Action in the specified Group. The \c id is returned by - * Group::WaitAny(). - * \return A Task identifying the Action to run - * \throws ErrorException if the Task object could not be constructed. - * \threadsafe - */ - Task Spawn( - mtapi_task_id_t id, /**< [in] The id to return in - Group::WaitAny() */ - Group const * group, /**< [in] The Group to run the Action - in */ - Action action /**< [in] The Action to run */ - ); - - friend class embb::base::Allocation; - friend class Node; - - private: - Queue(Queue const & taskqueue); - Queue(mtapi_uint_t priority, bool ordered); - ~Queue(); - - mtapi_queue_hndl_t handle_; -}; - -} // namespace mtapi -} // namespace embb - -#endif // EMBB_MTAPI_QUEUE_H_ diff --git a/tasks_cpp/include/embb/mtapi/task.h b/tasks_cpp/include/embb/mtapi/task.h deleted file mode 100644 index a98e09a..0000000 --- a/tasks_cpp/include/embb/mtapi/task.h +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef EMBB_MTAPI_TASK_H_ -#define EMBB_MTAPI_TASK_H_ - -#include -#include - -namespace embb { -namespace mtapi { - -/** - * A Task represents a running Action. - * - * \ingroup CPP_MTAPI - */ -class Task { - public: - /** - * Constructs an empty Task - */ - Task(); - - /** - * Copies a Task - */ - Task( - Task const & task /**< The task to copy. */ - ); - - /** - * Destroys a Task - */ - ~Task(); - - /** - * Waits for Task to finish for \c timeout milliseconds. - * \return The status of the finished Task, \c MTAPI_TIMEOUT or - * \c MTAPI_ERR_* - * \threadsafe - */ - mtapi_status_t Wait( - mtapi_timeout_t timeout /**< [in] Timeout duration in - milliseconds */ - ); - - /** - * Signals the Task to cancel computation. - * \waitfree - */ - void Cancel(); - - friend class Group; - friend class Queue; - friend class Node; - - private: - Task( - Action action); - - Task( - Action action, - mtapi_group_hndl_t group); - - Task( - mtapi_task_id_t id, - Action action, - mtapi_group_hndl_t group); - - Task( - Action action, - mtapi_queue_hndl_t queue); - - Task( - Action action, - mtapi_queue_hndl_t queue, - mtapi_group_hndl_t group); - - Task( - mtapi_task_id_t id, - Action action, - mtapi_queue_hndl_t queue, - mtapi_group_hndl_t group); - - mtapi_task_hndl_t handle_; -}; - -} // namespace mtapi -} // namespace embb - -#endif // EMBB_MTAPI_TASK_H_ diff --git a/tasks_cpp/include/embb/mtapi/taskcontext.h b/tasks_cpp/include/embb/mtapi/taskcontext.h deleted file mode 100644 index 955991d..0000000 --- a/tasks_cpp/include/embb/mtapi/taskcontext.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef EMBB_MTAPI_TASKCONTEXT_H_ -#define EMBB_MTAPI_TASKCONTEXT_H_ - -#include - -namespace embb { -namespace mtapi { - -/** - * Provides information about the status of the currently running Task. - * - * \ingroup CPP_MTAPI - */ -class TaskContext { - public: - /** - * Queries whether the Task running in the TaskContext should finish. - * \return \c true if the Task should finish, otherwise \c false - * \notthreadsafe - */ - bool ShouldCancel(); - - /** - * Queries the index of the worker thread the Task is running on. - * \return The worker thread index the Task is running on - * \notthreadsafe - */ - mtapi_uint_t GetCurrentCoreNumber(); - - /** - * Sets the return status of the running Task. This will be returned by - * Task::Wait() and is set to \c MTAPI_SUCCESS by default. - * \notthreadsafe - */ - void SetStatus( - mtapi_status_t error_code /**< [in] The status to return by - Task::Wait(), Group::WaitAny(), - Group::WaitAll() */ - ); - - friend class Node; - - private: - explicit TaskContext(mtapi_task_context_t * task_context); - - mtapi_task_context_t * context_; -}; - -} // namespace mtapi -} // namespace embb - -#endif // EMBB_MTAPI_TASKCONTEXT_H_ diff --git a/tasks_cpp/include/embb/tasks/action.h b/tasks_cpp/include/embb/tasks/action.h new file mode 100644 index 0000000..69b6132 --- /dev/null +++ b/tasks_cpp/include/embb/tasks/action.h @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef EMBB_TASKS_ACTION_H_ +#define EMBB_TASKS_ACTION_H_ + +#include +#include +#include + +namespace embb { +namespace tasks { + +/** + * A function to be spawned as a Task. + * + * \ingroup CPP_MTAPI + */ +class Action { + public: + /** + * Constructs an empty Action. + */ + Action() + : function_() + , execution_policy_() { + // empty + } + + /** + * Constructs an Action from a function object. + * + * \tparam Function Function object + */ + template + Action( + Function func /**< [in] Function object */ + ) + : function_(func) + , execution_policy_() { + // empty + } + + /** + * Constructs an Action from a function object and an Affinity. + * + * \tparam Function Function object + */ + template + Action( + Function func, /**< [in] Function object */ + ExecutionPolicy execution_policy /**< [in] Execution policy */ + ) + : function_(func) + , execution_policy_(execution_policy) { + // empty + } + + /** + * Executes the Action in a given TaskContext. + */ + void operator() ( + TaskContext & context /**< [in, out] Context the operator + is executed in */ + ) { + function_(context); + } + + /** + * Returns the ExecutionPolicy specified during creation. + * \return The ExecutionPolicy of the Action + * \waitfree + */ + ExecutionPolicy GetExecutionPolicy() const { + return execution_policy_; + } + + private: + embb::base::Function function_; + ExecutionPolicy execution_policy_; +}; + +} // namespace tasks +} // namespace embb + +#endif // EMBB_TASKS_ACTION_H_ diff --git a/tasks_cpp/include/embb/tasks/continuation.h b/tasks_cpp/include/embb/tasks/continuation.h new file mode 100644 index 0000000..666df75 --- /dev/null +++ b/tasks_cpp/include/embb/tasks/continuation.h @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef EMBB_TASKS_CONTINUATION_H_ +#define EMBB_TASKS_CONTINUATION_H_ + +#include +#include +#include +#include + +namespace embb { +namespace tasks { + +/** + * 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_TASKS + */ +class Continuation { + public: + /** + * Copies a Continuation. + */ + Continuation( + Continuation const & cont /**< [in] The Continuation to copy. */ + ); + + /** + * Destroys a Continuation. + */ + ~Continuation(); + + /** + * 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 + */ + Task Spawn(); + + /** + * 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 */ + ); + + friend class Node; + + private: + explicit Continuation(Action action); + + void ExecuteContinuation(TaskContext & context); + + ContinuationStage * first_; + ContinuationStage * last_; +}; + +} // namespace tasks +} // namespace embb + +#endif // EMBB_TASKS_CONTINUATION_H_ diff --git a/tasks_cpp/include/embb/tasks/execution_policy.h b/tasks_cpp/include/embb/tasks/execution_policy.h new file mode 100644 index 0000000..8a9a019 --- /dev/null +++ b/tasks_cpp/include/embb/tasks/execution_policy.h @@ -0,0 +1,153 @@ +/* + * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef EMBB_TASKS_EXECUTION_POLICY_H_ +#define EMBB_TASKS_EXECUTION_POLICY_H_ + +#include + +namespace embb { +namespace tasks { + +/** + * Describes the execution policy of a parallel algorithm. + * The execution policy comprises + * - the affinity of tasks to MTAPI worker threads (not CPU cores) and + * - the priority of the spawned tasks. + * + * The priority is a number between 0 (denoting the highest priority) to + * max_priorities - 1 as given during initialization using Node::Initialize(). + * The default value of max_priorities is 4. + * + * \ingroup CPP_TASKS + */ +class ExecutionPolicy{ + public: + /** + * Constructs the default execution policy. + * Sets the affinity to all worker threads and the priority to the default + * value. + */ + ExecutionPolicy(); + + /** + * Constructs an execution policy with the specified affinity and priority. + */ + ExecutionPolicy( + bool initial_affinity, /**< [in] \c true sets the affinity to + all worker threads, \c false to no + worker threads. */ + mtapi_uint_t priority /**< [in] Priority for the execution + policy. */ + ); + + /** + * Constructs an execution policy with the specified priority. + * Sets the affinity to all worker threads. + */ + explicit ExecutionPolicy( + mtapi_uint_t priority /**< [in] Priority for the execution + policy. */ + ); + + /** + * Constructs an execution policy with the specified affinity. + * Sets the priority to the default value. + */ + explicit ExecutionPolicy( + bool initial_affinity /**< [in] \c true sets the affinity to + all worker threads, \c false to no + worker threads. */ + ); + + /** + * Sets affinity to a specific worker thread. + */ + void AddWorker( + mtapi_uint_t worker /**< [in] Worker thread index */ + ); + + /** + * Removes affinity to a specific worker thread. + */ + void RemoveWorker( + mtapi_uint_t worker /**< [in] Worker thread index */ + ); + + /** + * Checks if affinity to a specific worker thread is set. + * + * \return \c true if affinity is set, otherwise \c false + */ + bool IsSetWorker( + mtapi_uint_t worker /**< [in] Worker thread index */ + ); + + /** + * Returns the number of cores the policy is affine to. + * + * \return the number of cores + */ + unsigned int GetCoreCount() const; + + /** + * Returns the affinity + * + * \return the affinity + */ + const mtapi_affinity_t &GetAffinity() const; + + /** Returns the priority + * + * \return the priority + */ + mtapi_uint_t GetPriority() const; + + friend class Task; + + private: + /** + * Default priority. + * Currently set to 0 = MAX priority. + */ + static const mtapi_uint_t DefaultPriority; + + /** + * Task Affinity. + * Maps the affinity of tasks to MTAPI worker threads (not CPU cores). + */ + mtapi_affinity_t affinity_; + + /** + * Task Priority. + */ + mtapi_uint_t priority_; +}; + +} // namespace tasks +} // namespace embb + +#endif // EMBB_TASKS_EXECUTION_POLICY_H_ diff --git a/tasks_cpp/include/embb/tasks/group.h b/tasks_cpp/include/embb/tasks/group.h new file mode 100644 index 0000000..039fe1d --- /dev/null +++ b/tasks_cpp/include/embb/tasks/group.h @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef EMBB_TASKS_GROUP_H_ +#define EMBB_TASKS_GROUP_H_ + +#include +#include +#include + +namespace embb { + +namespace base { + +class Allocation; + +} // namespace base + +namespace tasks { + +/** + * Represents a facility to wait for multiple related + * \link Task Tasks\endlink. + * + * \ingroup CPP_TASKS + */ +class Group { + public: + /** + * Runs an Action within the Group. + * \return A Task identifying the Action to run + * \throws ErrorException if the Task object could not be constructed. + * \threadsafe + */ + Task Spawn( + Action action /**< [in] The Action to run */ + ); + + /** + * Runs an Action within the Group. The \c id is returned by WaitAny(). + * \return A Task identifying the Action to run + * \throws ErrorException if the Task object could not be constructed. + * \threadsafe + */ + Task Spawn( + mtapi_task_id_t id, /**< [in] The id to return by + WaitAny() */ + Action action /**< [in] The Action to run */ + ); + + /** + * Waits for any Task in the Group to finish for \c timeout milliseconds. + * \return The status of the Task that finished execution + * \threadsafe + */ + mtapi_status_t WaitAny( + mtapi_timeout_t timeout /**< [in] Timeout duration in + milliseconds */ + ); + + /** + * Waits for any Task in the Group to finish for \c timeout milliseconds and + * retrieves the id given in Spawn(). + * \return The status of the Task that finished execution, \c MTAPI_TIMEOUT + * or \c MTAPI_ERR_* + * \threadsafe + */ + mtapi_status_t WaitAny( + mtapi_timeout_t timeout, /**< [in] Timeout duration in + milliseconds */ + mtapi_task_id_t & id /**< [out] The id given to Spawn() */ + ); + + /** + * Waits for all Task in the Group to finish for \c timeout milliseconds. + * \return \c MTAPI_SUCCESS, \c MTAPI_TIMEOUT, \c MTAPI_ERR_* or the status + * of any failed Task + * \threadsafe + */ + mtapi_status_t WaitAll( + mtapi_timeout_t timeout /**< [in] Timeout duration in + milliseconds */ + ); + + friend class embb::base::Allocation; + friend class Node; + friend class Queue; + + private: + Group(Group const & group); + Group(); + ~Group(); + + void Create(); + + mtapi_group_hndl_t handle_; +}; + +} // namespace tasks +} // namespace embb + +#endif // EMBB_TASKS_GROUP_H_ diff --git a/tasks_cpp/include/embb/tasks/internal/cmake_config.h.in b/tasks_cpp/include/embb/tasks/internal/cmake_config.h.in new file mode 100644 index 0000000..400139a --- /dev/null +++ b/tasks_cpp/include/embb/tasks/internal/cmake_config.h.in @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#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/tasks/internal/. From + there, the cmake_config.h can be included as usual using + #include + */ + +/** + * Is used to enable automatic initialization of the MTAPI node + */ +#define TASKS_CPP_AUTOMATIC_INITIALIZE ${TASKS_CPP_AUTOMATIC_INITIALIZE} + +#endif // EMBB_TASKS_INTERNAL_CMAKE_CONFIG_H_ diff --git a/tasks_cpp/include/embb/tasks/node.h b/tasks_cpp/include/embb/tasks/node.h new file mode 100644 index 0000000..094b34d --- /dev/null +++ b/tasks_cpp/include/embb/tasks/node.h @@ -0,0 +1,231 @@ +/* + * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef EMBB_TASKS_NODE_H_ +#define EMBB_TASKS_NODE_H_ + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace embb { + +namespace base { + +class Allocation; + +} // namespace base + +namespace tasks { + +/** + * A singleton representing the MTAPI runtime. + * + * \ingroup CPP_TASKS + */ +class Node { + public: + /** + * Initializes the runtime singleton using default values: + * - all available cores will be used + * - maximum number of tasks is 1024 + * - maximum number of groups is 128 + * - maximum number of queues is 16 + * - maximum queue capacity is 1024 + * - maximum number of priorities is 4. + * + * \notthreadsafe + * \throws ErrorException if the singleton was already initialized or the + * Node could not be initialized. + * \memory Allocates about 200kb of memory. + */ + static void Initialize( + mtapi_domain_t domain_id, /**< [in] The domain id to use */ + mtapi_node_t node_id /**< [in] The node id to use */ + ); + + /** + * Initializes the runtime singleton. + * \notthreadsafe + * \throws ErrorException if the singleton was already initialized or the + * Node could not be initialized. + * \memory Allocates some memory depending on the values given. + */ + static void Initialize( + mtapi_domain_t domain_id, /**< [in] The domain id to use */ + mtapi_node_t node_id, /**< [in] The node id to use */ + embb::base::CoreSet const & core_set, + /**< [in] A set of cores MTAPI should + use for its worker threads */ + mtapi_uint_t max_tasks, /**< [in] Maximum number of concurrent + \link Task Tasks \endlink */ + mtapi_uint_t max_groups, /**< [in] Maximum number of concurrent + \link Group Groups \endlink */ + mtapi_uint_t max_queues, /**< [in] Maximum number of concurrent + \link Queue Queues \endlink */ + mtapi_uint_t queue_limit, /**< [in] Maximum Queue capacity */ + mtapi_uint_t max_priorities /**< [in] Maximum number of priorities, + priorities will be between 0 and + max_priorities-1 */ + ); + + /** + * Checks if runtime is initialized. + * \return \c true if the Node singleton is already initialized, false + * otherwise + * \waitfree + */ + static bool IsInitialized(); + + /** + * Gets the instance of the runtime system. + * \return Reference to the Node singleton + * \threadsafe + */ + static Node & GetInstance(); + + /** + * Shuts the runtime system down. + * \throws ErrorException if the singleton is not initialized. + * \notthreadsafe + */ + static void Finalize(); + + /** + * Returns the number of available cores. + * \return The number of available cores + * \waitfree + */ + mtapi_uint_t GetCoreCount() const { + return core_count_; + } + + /** + * Returns the number of worker threads. + * \return The number of worker threads. + * \waitfree + */ + mtapi_uint_t GetWorkerThreadCount() const { + return worker_thread_count_; + } + + /** + * Creates a Group to launch \link Task Tasks \endlink in. + * \return A reference to the created Group + * \throws ErrorException if the Group object could not be constructed. + * \threadsafe + * \memory Allocates some memory depending on the configuration of the + * runtime. + */ + Group & CreateGroup(); + + /** + * Destroys a Group. \link Task Tasks \endlink running in the Group will + * finish execution. + * \threadsafe + */ + void DestroyGroup( + Group & group /**< [in,out] The Group to destroy */ + ); + + /** + * Creates a Queue for stream processing. The queue might execute its + * \link Task Tasks \endlink either in order or unordered. + * \return A reference to the new Queue + * \throws ErrorException if the Queue object could not be constructed. + * \threadsafe + * \memory Allocates some memory depending on the configuration of the + * runtime. + */ + Queue & CreateQueue( + mtapi_uint_t priority, /**< [in] Priority of the Queue */ + bool ordered /**< [in] \c true if the Queue should be + ordered, otherwise \c false */ + ); + + /** + * Destroys a Queue. Running \link Task Tasks \endlink will be canceled. + * \threadsafe + */ + void DestroyQueue( + Queue & queue /**< [in,out] The Queue to destroy */ + ); + + /** + * Runs an Action. + * \return A Task identifying the Action to run + * \throws ErrorException if the Task object could not be constructed. + * \threadsafe + */ + Task Spawn( + Action action /**< [in] The Action to execute */ + ); + + /** + * Creates a Continuation. + * \return A Continuation chain + * \threadsafe + */ + Continuation First( + Action action /**< [in] The first Action of the + Continuation chain */ + ); + + friend class embb::base::Allocation; + + private: + Node(Node const & node); + Node( + mtapi_domain_t domain_id, + mtapi_node_t node_id, + mtapi_node_attributes_t * attr); + ~Node(); + + static void action_func( + const void* args, + mtapi_size_t args_size, + void* result_buffer, + mtapi_size_t result_buffer_size, + const void* node_local_data, + mtapi_size_t node_local_data_size, + mtapi_task_context_t * context); + + mtapi_uint_t core_count_; + mtapi_uint_t worker_thread_count_; + mtapi_action_hndl_t action_handle_; + std::list queues_; + std::list groups_; +}; + +} // namespace tasks +} // namespace embb + +#endif // EMBB_TASKS_NODE_H_ diff --git a/tasks_cpp/include/embb/tasks/queue.h b/tasks_cpp/include/embb/tasks/queue.h new file mode 100644 index 0000000..df9f303 --- /dev/null +++ b/tasks_cpp/include/embb/tasks/queue.h @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef EMBB_TASKS_QUEUE_H_ +#define EMBB_TASKS_QUEUE_H_ + +#include +#include +#include +#include + +namespace embb { + +namespace base { + +class Allocation; + +} // namespace base + +namespace tasks { + +/** + * Allows for stream processing, either ordered or unordered. + * + * \ingroup CPP_TASKS + */ +class Queue { + public: + /** + * Enables the Queue. \link Task Tasks \endlink enqueued while the Queue was + * disabled are executed. + * \waitfree + */ + void Enable(); + + /** + * Disables the Queue. Running \link Task Tasks \endlink are canceled. + * \waitfree + */ + void Disable(); + + /** + * Runs an Action. + * \return A Task identifying the Action to run + * \throws ErrorException if the Task object could not be constructed. + * \threadsafe + */ + Task Spawn( + Action action /**< [in] The Action to run */ + ); + + /** + * Runs an Action in the specified Group + * \return A Task identifying the Action to run + * \throws ErrorException if the Task object could not be constructed. + * \threadsafe + */ + Task Spawn( + Group const * group, /**< [in] The Group to run the Action + in */ + Action action /**< [in] The Action to run */ + ); + + /** + * Runs an Action in the specified Group. The \c id is returned by + * Group::WaitAny(). + * \return A Task identifying the Action to run + * \throws ErrorException if the Task object could not be constructed. + * \threadsafe + */ + Task Spawn( + mtapi_task_id_t id, /**< [in] The id to return in + Group::WaitAny() */ + Group const * group, /**< [in] The Group to run the Action + in */ + Action action /**< [in] The Action to run */ + ); + + friend class embb::base::Allocation; + friend class Node; + + private: + Queue(Queue const & taskqueue); + Queue(mtapi_uint_t priority, bool ordered); + ~Queue(); + + mtapi_queue_hndl_t handle_; +}; + +} // namespace tasks +} // namespace embb + +#endif // EMBB_TASKS_QUEUE_H_ diff --git a/tasks_cpp/include/embb/tasks/task.h b/tasks_cpp/include/embb/tasks/task.h new file mode 100644 index 0000000..fd86b40 --- /dev/null +++ b/tasks_cpp/include/embb/tasks/task.h @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef EMBB_TASKS_TASK_H_ +#define EMBB_TASKS_TASK_H_ + +#include +#include + +namespace embb { +namespace tasks { + +/** + * A Task represents a running Action. + * + * \ingroup CPP_TASKS + */ +class Task { + public: + /** + * Constructs an empty Task + */ + Task(); + + /** + * Copies a Task + */ + Task( + Task const & task /**< The task to copy. */ + ); + + /** + * Destroys a Task + */ + ~Task(); + + /** + * Waits for Task to finish for \c timeout milliseconds. + * \return The status of the finished Task, \c MTAPI_TIMEOUT or + * \c MTAPI_ERR_* + * \threadsafe + */ + mtapi_status_t Wait( + mtapi_timeout_t timeout /**< [in] Timeout duration in + milliseconds */ + ); + + /** + * Signals the Task to cancel computation. + * \waitfree + */ + void Cancel(); + + friend class Group; + friend class Queue; + friend class Node; + + private: + Task( + Action action); + + Task( + Action action, + mtapi_group_hndl_t group); + + Task( + mtapi_task_id_t id, + Action action, + mtapi_group_hndl_t group); + + Task( + Action action, + mtapi_queue_hndl_t queue); + + Task( + Action action, + mtapi_queue_hndl_t queue, + mtapi_group_hndl_t group); + + Task( + mtapi_task_id_t id, + Action action, + mtapi_queue_hndl_t queue, + mtapi_group_hndl_t group); + + mtapi_task_hndl_t handle_; +}; + +} // namespace tasks +} // namespace embb + +#endif // EMBB_TASKS_TASK_H_ diff --git a/tasks_cpp/include/embb/tasks/task_context.h b/tasks_cpp/include/embb/tasks/task_context.h new file mode 100644 index 0000000..ecb416e --- /dev/null +++ b/tasks_cpp/include/embb/tasks/task_context.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef EMBB_TASKS_TASK_CONTEXT_H_ +#define EMBB_TASKS_TASK_CONTEXT_H_ + +#include + +namespace embb { +namespace tasks { + +/** + * Provides information about the status of the currently running Task. + * + * \ingroup CPP_TASKS + */ +class TaskContext { + public: + /** + * Queries whether the Task running in the TaskContext should finish. + * \return \c true if the Task should finish, otherwise \c false + * \notthreadsafe + */ + bool ShouldCancel(); + + /** + * Queries the index of the worker thread the Task is running on. + * \return The worker thread index the Task is running on + * \notthreadsafe + */ + mtapi_uint_t GetCurrentCoreNumber(); + + /** + * Sets the return status of the running Task. This will be returned by + * Task::Wait() and is set to \c MTAPI_SUCCESS by default. + * \notthreadsafe + */ + void SetStatus( + mtapi_status_t error_code /**< [in] The status to return by + Task::Wait(), Group::WaitAny(), + Group::WaitAll() */ + ); + + friend class Node; + + private: + explicit TaskContext(mtapi_task_context_t * task_context); + + mtapi_task_context_t * context_; +}; + +} // namespace tasks +} // namespace embb + +#endif // EMBB_TASKS_TASK_CONTEXT_H_ diff --git a/tasks_cpp/include/embb/tasks/tasks.h b/tasks_cpp/include/embb/tasks/tasks.h new file mode 100644 index 0000000..11e8d12 --- /dev/null +++ b/tasks_cpp/include/embb/tasks/tasks.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef EMBB_TASKS_TASKS_H_ +#define EMBB_TASKS_TASKS_H_ + +/** + * \defgroup CPP_TASKS Tasks + * Simple task management based on MTAPI. + * \ingroup CPP + */ + +#include + +#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 + +#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/task_context.cc b/tasks_cpp/src/task_context.cc new file mode 100644 index 0000000..bba9312 --- /dev/null +++ b/tasks_cpp/src/task_context.cc @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#include + +namespace embb { +namespace tasks { + +TaskContext::TaskContext(mtapi_task_context_t * task_context) + : context_(task_context) { +} + +bool TaskContext::ShouldCancel() { + mtapi_status_t status; + bool result = + MTAPI_TASK_CANCELLED == mtapi_context_taskstate_get(context_, &status); + assert(MTAPI_SUCCESS == status); + return result; +} + +mtapi_uint_t TaskContext::GetCurrentCoreNumber() { + mtapi_status_t status; + mtapi_uint_t result = + mtapi_context_corenum_get(context_, &status); + assert(MTAPI_SUCCESS == status); + return result; +} + +void TaskContext::SetStatus(mtapi_status_t error_code) { + mtapi_status_t status; + mtapi_context_status_set(context_, error_code, &status); + assert(MTAPI_SUCCESS == status); +} + +} // namespace tasks +} // namespace embb diff --git a/tasks_cpp/src/taskcontext.cc b/tasks_cpp/src/taskcontext.cc deleted file mode 100644 index 71e28b3..0000000 --- a/tasks_cpp/src/taskcontext.cc +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include - -#include - -namespace embb { -namespace mtapi { - -TaskContext::TaskContext(mtapi_task_context_t * task_context) - : context_(task_context) { -} - -bool TaskContext::ShouldCancel() { - mtapi_status_t status; - bool result = - MTAPI_TASK_CANCELLED == mtapi_context_taskstate_get(context_, &status); - assert(MTAPI_SUCCESS == status); - return result; -} - -mtapi_uint_t TaskContext::GetCurrentCoreNumber() { - mtapi_status_t status; - mtapi_uint_t result = - mtapi_context_corenum_get(context_, &status); - assert(MTAPI_SUCCESS == status); - return result; -} - -void TaskContext::SetStatus(mtapi_status_t error_code) { - mtapi_status_t status; - mtapi_context_status_set(context_, error_code, &status); - assert(MTAPI_SUCCESS == status); -} - -} // namespace mtapi -} // 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/mtapi_cpp_test_config.h deleted file mode 100644 index 4b3c2d7..0000000 --- a/tasks_cpp/test/mtapi_cpp_test_config.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef MTAPI_CPP_TEST_MTAPI_CPP_TEST_CONFIG_H_ -#define MTAPI_CPP_TEST_MTAPI_CPP_TEST_CONFIG_H_ - -#include -#include - -#define THIS_DOMAIN_ID 1 -#define THIS_NODE_ID 1 - -#endif // MTAPI_CPP_TEST_MTAPI_CPP_TEST_CONFIG_H_ diff --git a/tasks_cpp/test/mtapi_cpp_test_group.cc b/tasks_cpp/test/mtapi_cpp_test_group.cc deleted file mode 100644 index 6645dd5..0000000 --- a/tasks_cpp/test/mtapi_cpp_test_group.cc +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include - -#include -#include - -#include - -struct result_example_struct { - mtapi_uint_t value1; - mtapi_uint_t value2; -}; - -typedef struct result_example_struct result_example_t; - -static void testGroupAction(embb::mtapi::TaskContext & /*context*/) { - //std::cout << "testGroupAction on core " << - // context.GetCurrentCoreNumber() << std::endl; -} - -static void testDoSomethingElse() { -} - -GroupTest::GroupTest() { - CreateUnit("mtapi 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::mtapi::Node & node = embb::mtapi::Node::GetInstance(); - embb::mtapi::Group & group = node.CreateGroup(); - embb::mtapi::Task task; - - //std::cout << "wait all..." << std::endl; - - for (int ii = 0; ii < 4; ii++) { - task = group.Spawn(testGroupAction); - } - testDoSomethingElse(); - group.WaitAll(MTAPI_INFINITE); - - //std::cout << "wait any..." << std::endl; - - for (int ii = 0; ii < 4; ii++) { - task = group.Spawn(mtapi_task_id_t(ii + 1), testGroupAction); - } - testDoSomethingElse(); - mtapi_status_t status; - mtapi_task_id_t result; - while (MTAPI_SUCCESS == (status = group.WaitAny(MTAPI_INFINITE, result))) { - //std::cout << "got a result from task " << result << std::endl; - } - - node.DestroyGroup(group); - - embb::mtapi::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_group.h b/tasks_cpp/test/mtapi_cpp_test_group.h deleted file mode 100644 index 7a1cf2c..0000000 --- a/tasks_cpp/test/mtapi_cpp_test_group.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef MTAPI_CPP_TEST_MTAPI_CPP_TEST_GROUP_H_ -#define MTAPI_CPP_TEST_MTAPI_CPP_TEST_GROUP_H_ - -#include - -class GroupTest : public partest::TestCase { - public: - GroupTest(); - - private: - void TestBasic(); -}; - -#endif // MTAPI_CPP_TEST_MTAPI_CPP_TEST_GROUP_H_ diff --git a/tasks_cpp/test/mtapi_cpp_test_queue.cc b/tasks_cpp/test/mtapi_cpp_test_queue.cc deleted file mode 100644 index b8f7145..0000000 --- a/tasks_cpp/test/mtapi_cpp_test_queue.cc +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include - -#include -#include - -#include - -#define JOB_TEST_TASK 42 -#define TASK_TEST_ID 23 -#define QUEUE_TEST_ID 17 - -static void testQueueAction(embb::mtapi::TaskContext & /*context*/) { - //std::cout << "testQueueAction on core " << - // context.GetCurrentCoreNumber() << std::endl; -} - -static void testDoSomethingElse() { -} - -QueueTest::QueueTest() { - CreateUnit("mtapi 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::mtapi::Node & node = embb::mtapi::Node::GetInstance(); - embb::mtapi::Queue & queue = node.CreateQueue(0, false); - - embb::mtapi::Task task = queue.Spawn(testQueueAction); - - testDoSomethingElse(); - - task.Wait(MTAPI_INFINITE); - - node.DestroyQueue(queue); - - embb::mtapi::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_queue.h b/tasks_cpp/test/mtapi_cpp_test_queue.h deleted file mode 100644 index 9659ae2..0000000 --- a/tasks_cpp/test/mtapi_cpp_test_queue.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef MTAPI_CPP_TEST_MTAPI_CPP_TEST_QUEUE_H_ -#define MTAPI_CPP_TEST_MTAPI_CPP_TEST_QUEUE_H_ - -#include - -class QueueTest : public partest::TestCase { - public: - QueueTest(); - - private: - void TestBasic(); -}; - -#endif // MTAPI_CPP_TEST_MTAPI_CPP_TEST_QUEUE_H_ diff --git a/tasks_cpp/test/mtapi_cpp_test_task.cc b/tasks_cpp/test/mtapi_cpp_test_task.cc deleted file mode 100644 index 88242b3..0000000 --- a/tasks_cpp/test/mtapi_cpp_test_task.cc +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include - -#include -#include - -#include - -#define JOB_TEST_TASK 42 -#define TASK_TEST_ID 23 - -static void testTaskAction( - char const * msg, - std::string * output, - embb::mtapi::TaskContext & /*context*/) { - //std::cout << "testTaskAction " << msg << " on core " << - // context.GetCurrentCoreNumber() << std::endl; - *output = msg; -} - -static void testRecursiveTaskAction( - int * value, - embb::mtapi::TaskContext & /*context*/) { - embb::mtapi::Node & node = embb::mtapi::Node::GetInstance(); - *value = *value + 1; - if (*value < 1000) { - embb::mtapi::Task task = node.Spawn( - embb::base::Bind( - testRecursiveTaskAction, value, embb::base::Placeholder::_1)); - task.Wait(MTAPI_INFINITE); - } - PT_EXPECT(*value == 1000); -} - -static void testErrorTaskAction(embb::mtapi::TaskContext & context) { - context.SetStatus(MTAPI_ERR_ACTION_FAILED); -} - -static void testDoSomethingElse() { -} - -TaskTest::TaskTest() { - CreateUnit("mtapi_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::mtapi::Node & node = embb::mtapi::Node::GetInstance(); - - embb::mtapi::ExecutionPolicy policy(false); - PT_EXPECT_EQ(policy.GetAffinity(), 0u); - PT_EXPECT_EQ(policy.GetPriority(), 0u); - policy.AddWorker(0u); - PT_EXPECT_EQ(policy.GetAffinity(), 1u); - policy.AddWorker(1u); - PT_EXPECT_EQ(policy.GetAffinity(), 3u); - policy.RemoveWorker(0u); - PT_EXPECT_EQ(policy.GetAffinity(), 2u); - PT_EXPECT_EQ(policy.IsSetWorker(0), false); - PT_EXPECT_EQ(policy.IsSetWorker(1), true); - - std::string test; - embb::mtapi::Task task = node.Spawn( - embb::base::Bind( - testTaskAction, "simple", &test, embb::base::Placeholder::_1)); - testDoSomethingElse(); - task.Wait(MTAPI_INFINITE); - PT_EXPECT(test == "simple"); - //std::cout << "result: " << test.c_str() << std::endl; - - std::string test1, test2, test3; - task = node.First( - embb::base::Bind( - testTaskAction, "first", &test1, embb::base::Placeholder::_1)). - Then(embb::base::Bind( - testTaskAction, "second", &test2, embb::base::Placeholder::_1)). - Then(embb::base::Bind( - testTaskAction, "third", &test3, embb::base::Placeholder::_1)). - Spawn(); - testDoSomethingElse(); - task.Wait(MTAPI_INFINITE); - PT_EXPECT(test1 == "first"); - PT_EXPECT(test2 == "second"); - PT_EXPECT(test3 == "third"); - //std::cout << "result1: " << test1.c_str() << std::endl; - //std::cout << "result2: " << test2.c_str() << std::endl; - //std::cout << "result3: " << test3.c_str() << std::endl; - - int value = 0; - task = node.Spawn( - embb::base::Bind( - testRecursiveTaskAction, &value, embb::base::Placeholder::_1)); - task.Wait(MTAPI_INFINITE); - PT_EXPECT(value == 1000); - - mtapi_status_t status; - task = node.Spawn(testErrorTaskAction); - testDoSomethingElse(); - status = task.Wait(MTAPI_INFINITE); - PT_EXPECT(MTAPI_ERR_ACTION_FAILED == status); - - embb::mtapi::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/mtapi_cpp_test_task.h deleted file mode 100644 index f86b6fe..0000000 --- a/tasks_cpp/test/mtapi_cpp_test_task.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef MTAPI_CPP_TEST_MTAPI_CPP_TEST_TASK_H_ -#define MTAPI_CPP_TEST_MTAPI_CPP_TEST_TASK_H_ - -#include - -class TaskTest : public partest::TestCase { - public: - TaskTest(); - - private: - void TestBasic(); -}; - -#endif // MTAPI_CPP_TEST_MTAPI_CPP_TEST_TASK_H_ diff --git a/tasks_cpp/test/tasks_cpp_test_config.h b/tasks_cpp/test/tasks_cpp_test_config.h new file mode 100644 index 0000000..b7244c3 --- /dev/null +++ b/tasks_cpp/test/tasks_cpp_test_config.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef TASKS_CPP_TEST_TASKS_CPP_TEST_CONFIG_H_ +#define TASKS_CPP_TEST_TASKS_CPP_TEST_CONFIG_H_ + +#include +#include + +#define THIS_DOMAIN_ID 1 +#define THIS_NODE_ID 1 + +#endif // TASKS_CPP_TEST_TASKS_CPP_TEST_CONFIG_H_ diff --git a/tasks_cpp/test/tasks_cpp_test_group.cc b/tasks_cpp/test/tasks_cpp_test_group.cc new file mode 100644 index 0000000..6173e90 --- /dev/null +++ b/tasks_cpp/test/tasks_cpp_test_group.cc @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#include +#include + +#include + +struct result_example_struct { + mtapi_uint_t value1; + mtapi_uint_t value2; +}; + +typedef struct result_example_struct result_example_t; + +static void testGroupAction(embb::tasks::TaskContext & /*context*/) { + //std::cout << "testGroupAction on core " << + // context.GetCurrentCoreNumber() << std::endl; +} + +static void testDoSomethingElse() { +} + +GroupTest::GroupTest() { + CreateUnit("tasks_cpp group test").Add(&GroupTest::TestBasic, this); +} + +void GroupTest::TestBasic() { + //std::cout << "running testGroup..." << std::endl; + + embb::tasks::Node::Initialize(THIS_DOMAIN_ID, THIS_NODE_ID); + + embb::tasks::Node & node = embb::tasks::Node::GetInstance(); + embb::tasks::Group & group = node.CreateGroup(); + embb::tasks::Task task; + + //std::cout << "wait all..." << std::endl; + + for (int ii = 0; ii < 4; ii++) { + task = group.Spawn(testGroupAction); + } + testDoSomethingElse(); + group.WaitAll(MTAPI_INFINITE); + + //std::cout << "wait any..." << std::endl; + + for (int ii = 0; ii < 4; ii++) { + task = group.Spawn(mtapi_task_id_t(ii + 1), testGroupAction); + } + testDoSomethingElse(); + mtapi_status_t status; + mtapi_task_id_t result; + while (MTAPI_SUCCESS == (status = group.WaitAny(MTAPI_INFINITE, result))) { + //std::cout << "got a result from task " << result << std::endl; + } + + node.DestroyGroup(group); + + embb::tasks::Node::Finalize(); + + PT_EXPECT_EQ(embb_get_bytes_allocated(), 0u); + //std::cout << "...done" << std::endl << std::endl; +} diff --git a/tasks_cpp/test/tasks_cpp_test_group.h b/tasks_cpp/test/tasks_cpp_test_group.h new file mode 100644 index 0000000..cc6c4fe --- /dev/null +++ b/tasks_cpp/test/tasks_cpp_test_group.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef TASKS_CPP_TEST_TASKS_CPP_TEST_GROUP_H_ +#define TASKS_CPP_TEST_TASKS_CPP_TEST_GROUP_H_ + +#include + +class GroupTest : public partest::TestCase { + public: + GroupTest(); + + private: + void TestBasic(); +}; + +#endif // TASKS_CPP_TEST_TASKS_CPP_TEST_GROUP_H_ diff --git a/tasks_cpp/test/tasks_cpp_test_queue.cc b/tasks_cpp/test/tasks_cpp_test_queue.cc new file mode 100644 index 0000000..2867c6a --- /dev/null +++ b/tasks_cpp/test/tasks_cpp_test_queue.cc @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#include +#include + +#include + +#define JOB_TEST_TASK 42 +#define TASK_TEST_ID 23 +#define QUEUE_TEST_ID 17 + +static void testQueueAction(embb::tasks::TaskContext & /*context*/) { + //std::cout << "testQueueAction on core " << + // context.GetCurrentCoreNumber() << std::endl; +} + +static void testDoSomethingElse() { +} + +QueueTest::QueueTest() { + CreateUnit("tasks_cpp queue test").Add(&QueueTest::TestBasic, this); +} + +void QueueTest::TestBasic() { + //std::cout << "running testQueue..." << std::endl; + + embb::tasks::Node::Initialize(THIS_DOMAIN_ID, THIS_NODE_ID); + + embb::tasks::Node & node = embb::tasks::Node::GetInstance(); + embb::tasks::Queue & queue = node.CreateQueue(0, false); + + embb::tasks::Task task = queue.Spawn(testQueueAction); + + testDoSomethingElse(); + + task.Wait(MTAPI_INFINITE); + + node.DestroyQueue(queue); + + embb::tasks::Node::Finalize(); + + PT_EXPECT_EQ(embb_get_bytes_allocated(), 0u); + //std::cout << "...done" << std::endl << std::endl; +} diff --git a/tasks_cpp/test/tasks_cpp_test_queue.h b/tasks_cpp/test/tasks_cpp_test_queue.h new file mode 100644 index 0000000..88770ca --- /dev/null +++ b/tasks_cpp/test/tasks_cpp_test_queue.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef TASKS_CPP_TEST_TASKS_CPP_TEST_QUEUE_H_ +#define TASKS_CPP_TEST_TASKS_CPP_TEST_QUEUE_H_ + +#include + +class QueueTest : public partest::TestCase { + public: + QueueTest(); + + private: + void TestBasic(); +}; + +#endif // TASKS_CPP_TEST_TASKS_CPP_TEST_QUEUE_H_ diff --git a/tasks_cpp/test/tasks_cpp_test_task.cc b/tasks_cpp/test/tasks_cpp_test_task.cc new file mode 100644 index 0000000..deb01ce --- /dev/null +++ b/tasks_cpp/test/tasks_cpp_test_task.cc @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +#include +#include + +#include + +#define JOB_TEST_TASK 42 +#define TASK_TEST_ID 23 + +static void testTaskAction( + char const * msg, + std::string * output, + embb::tasks::TaskContext & /*context*/) { + //std::cout << "testTaskAction " << msg << " on core " << + // context.GetCurrentCoreNumber() << std::endl; + *output = msg; +} + +static void testRecursiveTaskAction( + int * value, + embb::tasks::TaskContext & /*context*/) { + embb::tasks::Node & node = embb::tasks::Node::GetInstance(); + *value = *value + 1; + if (*value < 1000) { + embb::tasks::Task task = node.Spawn( + embb::base::Bind( + testRecursiveTaskAction, value, embb::base::Placeholder::_1)); + task.Wait(MTAPI_INFINITE); + } + PT_EXPECT(*value == 1000); +} + +static void testErrorTaskAction(embb::tasks::TaskContext & context) { + context.SetStatus(MTAPI_ERR_ACTION_FAILED); +} + +static void testDoSomethingElse() { +} + +TaskTest::TaskTest() { + CreateUnit("tasks_cpp task test").Add(&TaskTest::TestBasic, this); +} + +void TaskTest::TestBasic() { + //std::cout << "running testTask..." << std::endl; + + embb::tasks::Node::Initialize(THIS_DOMAIN_ID, THIS_NODE_ID); + + embb::tasks::Node & node = embb::tasks::Node::GetInstance(); + + embb::tasks::ExecutionPolicy policy(false); + PT_EXPECT_EQ(policy.GetAffinity(), 0u); + PT_EXPECT_EQ(policy.GetPriority(), 0u); + policy.AddWorker(0u); + PT_EXPECT_EQ(policy.GetAffinity(), 1u); + policy.AddWorker(1u); + PT_EXPECT_EQ(policy.GetAffinity(), 3u); + policy.RemoveWorker(0u); + PT_EXPECT_EQ(policy.GetAffinity(), 2u); + PT_EXPECT_EQ(policy.IsSetWorker(0), false); + PT_EXPECT_EQ(policy.IsSetWorker(1), true); + + std::string test; + embb::tasks::Task task = node.Spawn( + embb::base::Bind( + testTaskAction, "simple", &test, embb::base::Placeholder::_1)); + testDoSomethingElse(); + task.Wait(MTAPI_INFINITE); + PT_EXPECT(test == "simple"); + //std::cout << "result: " << test.c_str() << std::endl; + + std::string test1, test2, test3; + task = node.First( + embb::base::Bind( + testTaskAction, "first", &test1, embb::base::Placeholder::_1)). + Then(embb::base::Bind( + testTaskAction, "second", &test2, embb::base::Placeholder::_1)). + Then(embb::base::Bind( + testTaskAction, "third", &test3, embb::base::Placeholder::_1)). + Spawn(); + testDoSomethingElse(); + task.Wait(MTAPI_INFINITE); + PT_EXPECT(test1 == "first"); + PT_EXPECT(test2 == "second"); + PT_EXPECT(test3 == "third"); + //std::cout << "result1: " << test1.c_str() << std::endl; + //std::cout << "result2: " << test2.c_str() << std::endl; + //std::cout << "result3: " << test3.c_str() << std::endl; + + int value = 0; + task = node.Spawn( + embb::base::Bind( + testRecursiveTaskAction, &value, embb::base::Placeholder::_1)); + task.Wait(MTAPI_INFINITE); + PT_EXPECT(value == 1000); + + mtapi_status_t status; + task = node.Spawn(testErrorTaskAction); + testDoSomethingElse(); + status = task.Wait(MTAPI_INFINITE); + PT_EXPECT(MTAPI_ERR_ACTION_FAILED == status); + + embb::tasks::Node::Finalize(); + + PT_EXPECT(embb_get_bytes_allocated() == 0); + //std::cout << "...done" << std::endl << std::endl; +} diff --git a/tasks_cpp/test/tasks_cpp_test_task.h b/tasks_cpp/test/tasks_cpp_test_task.h new file mode 100644 index 0000000..f86b6fe --- /dev/null +++ b/tasks_cpp/test/tasks_cpp_test_task.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef MTAPI_CPP_TEST_MTAPI_CPP_TEST_TASK_H_ +#define MTAPI_CPP_TEST_MTAPI_CPP_TEST_TASK_H_ + +#include + +class TaskTest : public partest::TestCase { + public: + TaskTest(); + + private: + void TestBasic(); +}; + +#endif // MTAPI_CPP_TEST_MTAPI_CPP_TEST_TASK_H_ -- libgit2 0.26.0