From a97a72c1e1b53f1ec70cb9fccf1966094688fae1 Mon Sep 17 00:00:00 2001 From: Marcus Winter Date: Tue, 24 Mar 2015 15:14:28 +0100 Subject: [PATCH] renamed mtapi_cpp to tasks_cpp --- mtapi_cpp/CMakeLists.txt | 49 ------------------------------------------------- mtapi_cpp/include/embb/mtapi/action.h | 109 ------------------------------------------------------------------------------------------------------------- mtapi_cpp/include/embb/mtapi/continuation.h | 105 --------------------------------------------------------------------------------------------------------- mtapi_cpp/include/embb/mtapi/execution_policy.h | 151 ------------------------------------------------------------------------------------------------------------------------------------------------------- mtapi_cpp/include/embb/mtapi/group.h | 125 ----------------------------------------------------------------------------------------------------------------------------- mtapi_cpp/include/embb/mtapi/internal/cmake_config.h.in | 41 ----------------------------------------- mtapi_cpp/include/embb/mtapi/mtapi.h | 55 ------------------------------------------------------- mtapi_cpp/include/embb/mtapi/node.h | 231 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- mtapi_cpp/include/embb/mtapi/queue.h | 116 -------------------------------------------------------------------------------------------------------------------- mtapi_cpp/include/embb/mtapi/task.h | 115 ------------------------------------------------------------------------------------------------------------------- mtapi_cpp/include/embb/mtapi/taskcontext.h | 78 ------------------------------------------------------------------------------ mtapi_cpp/src/continuation.cc | 94 ---------------------------------------------------------------------------------------------- mtapi_cpp/src/continuationstage.h | 43 ------------------------------------------- mtapi_cpp/src/execution_policy.cc | 124 ---------------------------------------------------------------------------------------------------------------------------- mtapi_cpp/src/group.cc | 96 ------------------------------------------------------------------------------------------------ mtapi_cpp/src/node.cc | 274 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- mtapi_cpp/src/queue.cc | 90 ------------------------------------------------------------------------------------------ mtapi_cpp/src/task.cc | 220 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- mtapi_cpp/src/taskcontext.cc | 61 ------------------------------------------------------------- mtapi_cpp/test/main.cc | 40 ---------------------------------------- mtapi_cpp/test/mtapi_cpp_test_config.h | 36 ------------------------------------ mtapi_cpp/test/mtapi_cpp_test_group.cc | 88 ---------------------------------------------------------------------------------------- mtapi_cpp/test/mtapi_cpp_test_group.h | 40 ---------------------------------------- mtapi_cpp/test/mtapi_cpp_test_queue.cc | 70 ---------------------------------------------------------------------- mtapi_cpp/test/mtapi_cpp_test_queue.h | 40 ---------------------------------------- mtapi_cpp/test/mtapi_cpp_test_task.cc | 136 ---------------------------------------------------------------------------------------------------------------------------------------- mtapi_cpp/test/mtapi_cpp_test_task.h | 40 ---------------------------------------- tasks_cpp/CMakeLists.txt | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 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/src/continuation.cc | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tasks_cpp/src/continuationstage.h | 43 +++++++++++++++++++++++++++++++++++++++++++ tasks_cpp/src/execution_policy.cc | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tasks_cpp/src/group.cc | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tasks_cpp/src/node.cc | 274 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tasks_cpp/src/queue.cc | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tasks_cpp/src/task.cc | 220 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tasks_cpp/src/taskcontext.cc | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tasks_cpp/test/main.cc | 40 ++++++++++++++++++++++++++++++++++++++++ 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 ++++++++++++++++++++++++++++++++++++++++ 54 files changed, 2667 insertions(+), 2667 deletions(-) delete mode 100644 mtapi_cpp/CMakeLists.txt delete mode 100644 mtapi_cpp/include/embb/mtapi/action.h delete mode 100644 mtapi_cpp/include/embb/mtapi/continuation.h delete mode 100644 mtapi_cpp/include/embb/mtapi/execution_policy.h delete mode 100644 mtapi_cpp/include/embb/mtapi/group.h delete mode 100644 mtapi_cpp/include/embb/mtapi/internal/cmake_config.h.in delete mode 100644 mtapi_cpp/include/embb/mtapi/mtapi.h delete mode 100644 mtapi_cpp/include/embb/mtapi/node.h delete mode 100644 mtapi_cpp/include/embb/mtapi/queue.h delete mode 100644 mtapi_cpp/include/embb/mtapi/task.h delete mode 100644 mtapi_cpp/include/embb/mtapi/taskcontext.h delete mode 100644 mtapi_cpp/src/continuation.cc delete mode 100644 mtapi_cpp/src/continuationstage.h delete mode 100644 mtapi_cpp/src/execution_policy.cc delete mode 100644 mtapi_cpp/src/group.cc delete mode 100644 mtapi_cpp/src/node.cc delete mode 100644 mtapi_cpp/src/queue.cc delete mode 100644 mtapi_cpp/src/task.cc delete mode 100644 mtapi_cpp/src/taskcontext.cc delete mode 100644 mtapi_cpp/test/main.cc delete mode 100644 mtapi_cpp/test/mtapi_cpp_test_config.h delete mode 100644 mtapi_cpp/test/mtapi_cpp_test_group.cc delete mode 100644 mtapi_cpp/test/mtapi_cpp_test_group.h delete mode 100644 mtapi_cpp/test/mtapi_cpp_test_queue.cc delete mode 100644 mtapi_cpp/test/mtapi_cpp_test_queue.h delete mode 100644 mtapi_cpp/test/mtapi_cpp_test_task.cc delete mode 100644 mtapi_cpp/test/mtapi_cpp_test_task.h create mode 100644 tasks_cpp/CMakeLists.txt create mode 100644 tasks_cpp/include/embb/mtapi/action.h create mode 100644 tasks_cpp/include/embb/mtapi/continuation.h create mode 100644 tasks_cpp/include/embb/mtapi/execution_policy.h create mode 100644 tasks_cpp/include/embb/mtapi/group.h create mode 100644 tasks_cpp/include/embb/mtapi/internal/cmake_config.h.in create mode 100644 tasks_cpp/include/embb/mtapi/mtapi.h create mode 100644 tasks_cpp/include/embb/mtapi/node.h create mode 100644 tasks_cpp/include/embb/mtapi/queue.h create mode 100644 tasks_cpp/include/embb/mtapi/task.h create mode 100644 tasks_cpp/include/embb/mtapi/taskcontext.h create mode 100644 tasks_cpp/src/continuation.cc create mode 100644 tasks_cpp/src/continuationstage.h create mode 100644 tasks_cpp/src/execution_policy.cc create mode 100644 tasks_cpp/src/group.cc create mode 100644 tasks_cpp/src/node.cc create mode 100644 tasks_cpp/src/queue.cc create mode 100644 tasks_cpp/src/task.cc create mode 100644 tasks_cpp/src/taskcontext.cc create mode 100644 tasks_cpp/test/main.cc create mode 100644 tasks_cpp/test/mtapi_cpp_test_config.h create mode 100644 tasks_cpp/test/mtapi_cpp_test_group.cc create mode 100644 tasks_cpp/test/mtapi_cpp_test_group.h create mode 100644 tasks_cpp/test/mtapi_cpp_test_queue.cc create mode 100644 tasks_cpp/test/mtapi_cpp_test_queue.h create mode 100644 tasks_cpp/test/mtapi_cpp_test_task.cc create mode 100644 tasks_cpp/test/mtapi_cpp_test_task.h diff --git a/mtapi_cpp/CMakeLists.txt b/mtapi_cpp/CMakeLists.txt deleted file mode 100644 index 19a6353..0000000 --- a/mtapi_cpp/CMakeLists.txt +++ /dev/null @@ -1,49 +0,0 @@ -project (project_mtapi_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") - -if (USE_AUTOMATIC_INITIALIZATION STREQUAL ON) - message("-- Automatic initialization enabled (default)") - set(MTAPI_CPP_AUTOMATIC_INITIALIZE 1) -else() - set(MTAPI_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") - -# Execute the GroupSources macro -include(${CMAKE_SOURCE_DIR}/CMakeCommon/GroupSourcesMSVC.cmake) -GroupSourcesMSVC(include) -GroupSourcesMSVC(src) -GroupSourcesMSVC(test) - -set (EMBB_MTAPI_CPP_INCLUDE_DIRS "include" "src" "test") -include_directories(${EMBB_MTAPI_CPP_INCLUDE_DIRS} - ${CMAKE_CURRENT_BINARY_DIR}/include - ${CMAKE_CURRENT_SOURCE_DIR}/../base_c/include - ${CMAKE_CURRENT_BINARY_DIR}/../base_c/include - ${CMAKE_CURRENT_SOURCE_DIR}/../base_cpp/include - ${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) - -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 - embb_base_cpp embb_base_c ${compiler_libs}) - CopyBin(BIN embb_mtapi_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) diff --git a/mtapi_cpp/include/embb/mtapi/action.h b/mtapi_cpp/include/embb/mtapi/action.h deleted file mode 100644 index 68e9776..0000000 --- a/mtapi_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/mtapi_cpp/include/embb/mtapi/continuation.h b/mtapi_cpp/include/embb/mtapi/continuation.h deleted file mode 100644 index 29789a2..0000000 --- a/mtapi_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/mtapi_cpp/include/embb/mtapi/execution_policy.h b/mtapi_cpp/include/embb/mtapi/execution_policy.h deleted file mode 100644 index 85727f3..0000000 --- a/mtapi_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/mtapi_cpp/include/embb/mtapi/group.h b/mtapi_cpp/include/embb/mtapi/group.h deleted file mode 100644 index b3c4906..0000000 --- a/mtapi_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/mtapi_cpp/include/embb/mtapi/internal/cmake_config.h.in b/mtapi_cpp/include/embb/mtapi/internal/cmake_config.h.in deleted file mode 100644 index 32af64c..0000000 --- a/mtapi_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/mtapi_cpp/include/embb/mtapi/mtapi.h b/mtapi_cpp/include/embb/mtapi/mtapi.h deleted file mode 100644 index 4c83834..0000000 --- a/mtapi_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/mtapi_cpp/include/embb/mtapi/node.h b/mtapi_cpp/include/embb/mtapi/node.h deleted file mode 100644 index a7c5d99..0000000 --- a/mtapi_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/mtapi_cpp/include/embb/mtapi/queue.h b/mtapi_cpp/include/embb/mtapi/queue.h deleted file mode 100644 index 4671359..0000000 --- a/mtapi_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/mtapi_cpp/include/embb/mtapi/task.h b/mtapi_cpp/include/embb/mtapi/task.h deleted file mode 100644 index a98e09a..0000000 --- a/mtapi_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/mtapi_cpp/include/embb/mtapi/taskcontext.h b/mtapi_cpp/include/embb/mtapi/taskcontext.h deleted file mode 100644 index 955991d..0000000 --- a/mtapi_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/mtapi_cpp/src/continuation.cc b/mtapi_cpp/src/continuation.cc deleted file mode 100644 index 40bbc30..0000000 --- a/mtapi_cpp/src/continuation.cc +++ /dev/null @@ -1,94 +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 - -namespace embb { -namespace mtapi { - -Continuation::Continuation(Action action) { - first_ = last_ = embb::base::Allocation::New(); - first_->action = action; - first_->next = NULL; -} - -Continuation::Continuation(Continuation const & cont) - : first_(cont.first_) - , last_(cont.last_) { -} - -Continuation::~Continuation() { -} - -void Continuation::ExecuteContinuation(TaskContext &) { - mtapi::ContinuationStage * stage = first_; - mtapi::Node & node = mtapi::Node::GetInstance(); - while (NULL != stage) { - mtapi::Task task = node.Spawn(stage->action); - task.Wait(MTAPI_INFINITE); - stage = stage->next; - } - - // delete stages - stage = first_; - while (NULL != stage) { - mtapi::ContinuationStage * next = stage->next; - embb::base::Allocation::Delete(stage); - stage = next; - } -} - -Continuation & Continuation::Then(Action action) { - ContinuationStage * cur = embb::base::Allocation::New(); - cur->action = action; - cur->next = NULL; - - last_->next = cur; - last_ = cur; - - return *this; -} - -Task Continuation::Spawn() { - return Spawn(ExecutionPolicy()); -} - -Task Continuation::Spawn(ExecutionPolicy execution_policy) { - Node & node = Node::GetInstance(); - return node.Spawn( - Action( - embb::base::MakeFunction(*this, &Continuation::ExecuteContinuation), - ExecutionPolicy(execution_policy))); -} - -} // namespace mtapi -} // namespace embb diff --git a/mtapi_cpp/src/continuationstage.h b/mtapi_cpp/src/continuationstage.h deleted file mode 100644 index 1f37607..0000000 --- a/mtapi_cpp/src/continuationstage.h +++ /dev/null @@ -1,43 +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_SRC_CONTINUATIONSTAGE_H_ -#define MTAPI_CPP_SRC_CONTINUATIONSTAGE_H_ - -#include - -namespace embb { -namespace mtapi { - -struct ContinuationStage { - mtapi::Action action; - ContinuationStage * next; -}; - -} // namespace mtapi -} // namespace embb - -#endif // MTAPI_CPP_SRC_CONTINUATIONSTAGE_H_ diff --git a/mtapi_cpp/src/execution_policy.cc b/mtapi_cpp/src/execution_policy.cc deleted file mode 100644 index 157d0ac..0000000 --- a/mtapi_cpp/src/execution_policy.cc +++ /dev/null @@ -1,124 +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 - -namespace embb { -namespace mtapi { - -ExecutionPolicy::ExecutionPolicy() : - priority_(DefaultPriority) { -#if MTAPI_CPP_AUTOMATIC_INITIALIZE - Node::GetInstance(); // MTAPI has to be initialized -#endif - mtapi_status_t status; - mtapi_affinity_init(&affinity_, MTAPI_TRUE, &status); - if (MTAPI_SUCCESS != status) { - EMBB_THROW(embb::base::ErrorException, - "Could not default construct Affinity."); - } -} - -ExecutionPolicy::ExecutionPolicy(bool initial_affinity, mtapi_uint_t priority) -:priority_(priority) { -#if MTAPI_CPP_AUTOMATIC_INITIALIZE - Node::GetInstance(); // MTAPI has to be initialized -#endif - mtapi_status_t status; - mtapi_affinity_init(&affinity_, initial_affinity ? MTAPI_TRUE : MTAPI_FALSE, - &status); - if (MTAPI_SUCCESS != status) { - EMBB_THROW(embb::base::ErrorException, - "Could not default construct Affinity."); - } -} - -ExecutionPolicy::ExecutionPolicy(mtapi_uint_t priority) -:priority_(priority) { -#if MTAPI_CPP_AUTOMATIC_INITIALIZE - Node::GetInstance(); // MTAPI has to be initialized -#endif - mtapi_status_t status; - mtapi_affinity_init(&affinity_, MTAPI_TRUE, &status); - if (MTAPI_SUCCESS != status) { - EMBB_THROW(embb::base::ErrorException, - "Could not default construct Affinity."); - } -} - -ExecutionPolicy::ExecutionPolicy(bool initial_affinity) -:priority_(DefaultPriority) { -#if MTAPI_CPP_AUTOMATIC_INITIALIZE - Node::GetInstance(); // MTAPI has to be initialized -#endif - mtapi_status_t status; - mtapi_affinity_init(&affinity_, initial_affinity ? MTAPI_TRUE : MTAPI_FALSE, - &status); - if (MTAPI_SUCCESS != status) { - EMBB_THROW(embb::base::ErrorException, - "Could not default construct Affinity."); - } -} - -void ExecutionPolicy::AddWorker(mtapi_uint_t worker) { - mtapi_status_t status; - mtapi_affinity_set(&affinity_, worker, MTAPI_TRUE, &status); - assert(MTAPI_SUCCESS == status); -} - -void ExecutionPolicy::RemoveWorker(mtapi_uint_t worker) { - mtapi_status_t status; - mtapi_affinity_set(&affinity_, worker, MTAPI_FALSE, &status); - assert(MTAPI_SUCCESS == status); -} - -bool ExecutionPolicy::IsSetWorker(mtapi_uint_t worker) { - mtapi_status_t status; - mtapi_boolean_t aff = mtapi_affinity_get(&affinity_, worker, &status); - assert(MTAPI_SUCCESS == status); - return MTAPI_TRUE == aff; -} - -unsigned int ExecutionPolicy::GetCoreCount() const { - return embb_bitset_count(&affinity_); -} - -const mtapi_affinity_t &ExecutionPolicy::GetAffinity() const { - return affinity_; -} - -mtapi_uint_t ExecutionPolicy::GetPriority() const { - return priority_; -} - -const mtapi_uint_t ExecutionPolicy::DefaultPriority = 0; - -} // namespace mtapi -} // namespace embb diff --git a/mtapi_cpp/src/group.cc b/mtapi_cpp/src/group.cc deleted file mode 100644 index 20dc0b2..0000000 --- a/mtapi_cpp/src/group.cc +++ /dev/null @@ -1,96 +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 - -namespace embb { -namespace mtapi { - -Group::Group() { - Create(); -} - -Group::~Group() { - mtapi_status_t status; - mtapi_group_delete(handle_, &status); - assert(MTAPI_SUCCESS == status); -} - -void Group::Create() { - mtapi_status_t status; - handle_ = mtapi_group_create(MTAPI_GROUP_ID_NONE, MTAPI_NULL, &status); - if (MTAPI_SUCCESS != status) { - EMBB_THROW(embb::base::ErrorException, - "mtapi::Group could not be constructed"); - } -} - -Task Group::Spawn(Action action) { - return Task(action, handle_); -} - -Task Group::Spawn(mtapi_task_id_t id, Action action) { - return Task(id, action, handle_); -} - -mtapi_status_t Group::WaitAny(mtapi_timeout_t timeout) { - mtapi_status_t status; - mtapi_group_wait_any(handle_, MTAPI_NULL, timeout, &status); - if (MTAPI_GROUP_COMPLETED == status) { - // group has been deleted, so recreate it for simplicity - Create(); - } - return status; -} - -mtapi_status_t Group::WaitAny( - mtapi_timeout_t timeout, - mtapi_task_id_t & result) { - mtapi_status_t status; - void * res; - mtapi_group_wait_any(handle_, &res, timeout, &status); - memcpy(&result, &res, sizeof(result)); - if (MTAPI_GROUP_COMPLETED == status) { - // group has been deleted, so recreate it for simplicity - Create(); - } - return status; -} - -mtapi_status_t Group::WaitAll(mtapi_timeout_t timeout) { - mtapi_status_t status; - mtapi_group_wait_all(handle_, timeout, &status); - // group has been deleted, so recreate it for simplicity - Create(); - return status; -} - -} // namespace mtapi -} // namespace embb diff --git a/mtapi_cpp/src/node.cc b/mtapi_cpp/src/node.cc deleted file mode 100644 index 0ffe21a..0000000 --- a/mtapi_cpp/src/node.cc +++ /dev/null @@ -1,274 +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 -#include -#if MTAPI_CPP_AUTOMATIC_INITIALIZE -#include -#endif - -namespace { - -static embb::mtapi::Node * node_instance = NULL; -#if MTAPI_CPP_AUTOMATIC_INITIALIZE -static embb::base::Mutex init_mutex; -#endif - -} - -namespace embb { -namespace mtapi { - -void Node::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::Action * action = - reinterpret_cast(const_cast(args)); - mtapi::TaskContext task_context(context); - (*action)(task_context); - embb::base::Allocation::Delete(action); -} - -Node::Node( - mtapi_domain_t domain_id, - mtapi_node_t node_id, - mtapi_node_attributes_t * attr) { - mtapi_status_t status; - mtapi_info_t info; - mtapi_initialize(domain_id, node_id, attr, &info, &status); - if (MTAPI_SUCCESS != status) { - EMBB_THROW(embb::base::ErrorException, - "mtapi::Node could not initialize mtapi"); - } - 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, - MTAPI_NULL, 0, MTAPI_NULL, &status); - if (MTAPI_SUCCESS != status) { - EMBB_THROW(embb::base::ErrorException, - "mtapi::Node could not create an action"); - } -} - -Node::~Node() { - for (std::list::iterator ii = queues_.begin(); - ii != queues_.end(); - ++ii) { - embb::base::Allocation::Delete(*ii); - } - queues_.clear(); - - for (std::list::iterator ii = groups_.begin(); - ii != groups_.end(); - ++ii) { - embb::base::Allocation::Delete(*ii); - } - groups_.clear(); - - mtapi_status_t status; - mtapi_action_delete(action_handle_, MTAPI_INFINITE, &status); - assert(MTAPI_SUCCESS == status); - mtapi_finalize(&status); - assert(MTAPI_SUCCESS == status); -} - -void Node::Initialize( - mtapi_domain_t domain_id, - mtapi_node_t node_id) { - if (IsInitialized()) { - EMBB_THROW(embb::base::ErrorException, - "mtapi::Node was already initialized"); - } else { - mtapi_status_t status; - mtapi_node_attributes_t attr; - mtapi_uint_t tmp; - mtapi_nodeattr_init(&attr, &status); - assert(MTAPI_SUCCESS == status); - tmp = 4; - mtapi_nodeattr_set(&attr, MTAPI_NODE_MAX_ACTIONS, - &tmp, sizeof(tmp), &status); - assert(MTAPI_SUCCESS == status); - tmp = 4; - mtapi_nodeattr_set(&attr, MTAPI_NODE_MAX_JOBS, - &tmp, sizeof(tmp), &status); - assert(MTAPI_SUCCESS == status); - tmp = 1; - mtapi_nodeattr_set(&attr, MTAPI_NODE_MAX_ACTIONS_PER_JOB, - &tmp, sizeof(tmp), &status); - assert(MTAPI_SUCCESS == status); - node_instance = embb::base::Allocation::New( - domain_id, node_id, &attr); - } -} - -void Node::Initialize( - mtapi_domain_t domain_id, - mtapi_node_t node_id, - embb::base::CoreSet const & core_set, - mtapi_uint_t max_tasks, - mtapi_uint_t max_groups, - mtapi_uint_t max_queues, - mtapi_uint_t queue_limit, - mtapi_uint_t max_priorities) { - if (IsInitialized()) { - EMBB_THROW(embb::base::ErrorException, - "mtapi::Node was already initialized"); - } else { - mtapi_status_t status; - mtapi_node_attributes_t attr; - mtapi_uint_t tmp; - mtapi_nodeattr_init(&attr, &status); - assert(MTAPI_SUCCESS == status); - embb_core_set_t cs; - embb_core_set_init(&cs, 0); - for (unsigned int ii = 0; embb_core_set_count(&cs) < core_set.Count(); - ii++) { - if (core_set.IsContained(ii)) { - embb_core_set_add(&cs, ii); - } - } - mtapi_nodeattr_set(&attr, MTAPI_NODE_CORE_AFFINITY, - &cs, sizeof(cs), &status); - assert(MTAPI_SUCCESS == status); - mtapi_nodeattr_set(&attr, MTAPI_NODE_MAX_TASKS, - &max_tasks, sizeof(max_tasks), &status); - assert(MTAPI_SUCCESS == status); - tmp = 4; - mtapi_nodeattr_set(&attr, MTAPI_NODE_MAX_ACTIONS, - &tmp, sizeof(tmp), &status); - assert(MTAPI_SUCCESS == status); - mtapi_nodeattr_set(&attr, MTAPI_NODE_MAX_GROUPS, - &max_groups, sizeof(max_groups), &status); - assert(MTAPI_SUCCESS == status); - mtapi_nodeattr_set(&attr, MTAPI_NODE_MAX_QUEUES, - &max_queues, sizeof(max_queues), &status); - assert(MTAPI_SUCCESS == status); - mtapi_nodeattr_set(&attr, MTAPI_NODE_QUEUE_LIMIT, - &queue_limit, sizeof(queue_limit), &status); - assert(MTAPI_SUCCESS == status); - tmp = 4; - mtapi_nodeattr_set(&attr, MTAPI_NODE_MAX_JOBS, - &tmp, sizeof(tmp), &status); - assert(MTAPI_SUCCESS == status); - tmp = 1; - mtapi_nodeattr_set(&attr, MTAPI_NODE_MAX_ACTIONS_PER_JOB, - &tmp, sizeof(tmp), &status); - assert(MTAPI_SUCCESS == status); - mtapi_nodeattr_set(&attr, MTAPI_NODE_MAX_PRIORITIES, - &max_priorities, sizeof(max_priorities), &status); - assert(MTAPI_SUCCESS == status); - node_instance = embb::base::Allocation::New( - domain_id, node_id, &attr); - } -} - -bool Node::IsInitialized() { - return NULL != node_instance; -} - -Node & Node::GetInstance() { -#if MTAPI_CPP_AUTOMATIC_INITIALIZE - if (!IsInitialized()) { - init_mutex.Lock(); - if (!IsInitialized()) { - Node::Initialize( - MTAPI_CPP_AUTOMATIC_DOMAIN_ID, MTAPI_CPP_AUTOMATIC_NODE_ID); - atexit(Node::Finalize); - } - init_mutex.Unlock(); - } - return *node_instance; -#else - if (IsInitialized()) { - return *node_instance; - } else { - EMBB_THROW(embb::base::ErrorException, - "mtapi::Node is not initialized"); - } -#endif -} - -void Node::Finalize() { - if (IsInitialized()) { - embb::base::Allocation::Delete(node_instance); - node_instance = NULL; - } else { - EMBB_THROW(embb::base::ErrorException, - "mtapi::Node is not initialized"); - } -} - -Group & Node::CreateGroup() { - Group * group = embb::base::Allocation::New(); - groups_.push_back(group); - return *group; -} - -void Node::DestroyGroup(Group & group) { - std::list::iterator ii = - std::find(groups_.begin(), groups_.end(), &group); - if (ii != groups_.end()) { - embb::base::Allocation::Delete(*ii); - groups_.erase(ii); - } -} - -Queue & Node::CreateQueue(mtapi_uint_t priority, bool ordered) { - Queue * queue = embb::base::Allocation::New(priority, ordered); - queues_.push_back(queue); - return *queue; -} - -void Node::DestroyQueue(Queue & queue) { - std::list::iterator ii = - std::find(queues_.begin(), queues_.end(), &queue); - if (ii != queues_.end()) { - embb::base::Allocation::Delete(*ii); - queues_.erase(ii); - } -} - -Task Node::Spawn(Action action) { - return Task(action); -} - -Continuation Node::First(Action action) { - return Continuation(action); -} - -} // namespace mtapi -} // namespace embb diff --git a/mtapi_cpp/src/queue.cc b/mtapi_cpp/src/queue.cc deleted file mode 100644 index a6e8371..0000000 --- a/mtapi_cpp/src/queue.cc +++ /dev/null @@ -1,90 +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 - -namespace embb { -namespace mtapi { - -Queue::Queue(mtapi_uint_t priority, bool ordered) { - mtapi_status_t status; - mtapi_queue_attributes_t attr; - mtapi_boolean_t bb; - mtapi_queueattr_init(&attr, &status); - assert(MTAPI_SUCCESS == status); - mtapi_queueattr_set(&attr, MTAPI_QUEUE_PRIORITY, - &priority, sizeof(priority), &status); - assert(MTAPI_SUCCESS == status); - bb = ordered ? MTAPI_TRUE : MTAPI_FALSE; - mtapi_queueattr_set(&attr, MTAPI_QUEUE_ORDERED, - &bb, sizeof(bb), &status); - assert(MTAPI_SUCCESS == status); - bb = MTAPI_TRUE; - mtapi_queueattr_set(&attr, MTAPI_QUEUE_RETAIN, - &bb, sizeof(bb), &status); - 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); - assert(MTAPI_SUCCESS == status); - handle_ = mtapi_queue_create(MTAPI_QUEUE_ID_NONE, job, &attr, &status); - if (MTAPI_SUCCESS != status) { - EMBB_THROW(embb::base::ErrorException, - "mtapi::Queue could not be constructed"); - } -} - -Queue::~Queue() { - mtapi_status_t status; - mtapi_queue_delete(handle_, MTAPI_INFINITE, &status); - assert(MTAPI_SUCCESS == status); -} - -void Queue::Enable() { - mtapi_status_t status; - mtapi_queue_enable(handle_, &status); - assert(MTAPI_SUCCESS == status); -} - -void Queue::Disable() { - mtapi_status_t status; - mtapi_queue_disable(handle_, MTAPI_INFINITE, &status); - assert(MTAPI_SUCCESS == status); -} - -Task Queue::Spawn(Action action) { - return Task(action, handle_); -} - -Task Queue::Spawn(Group const * group, Action action) { - return Task(action, handle_, group->handle_); -} - -} // namespace mtapi -} // namespace embb diff --git a/mtapi_cpp/src/task.cc b/mtapi_cpp/src/task.cc deleted file mode 100644 index 5239a3c..0000000 --- a/mtapi_cpp/src/task.cc +++ /dev/null @@ -1,220 +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 - -namespace embb { -namespace mtapi { - -Task::Task() { - handle_.id = 0; - handle_.tag = 0; -} - -Task::Task(Task const & task) - : handle_(task.handle_) { - // empty -} - -Task::Task( - Action action) { - mtapi_status_t status; - mtapi_task_attributes_t attr; - ExecutionPolicy policy = action.GetExecutionPolicy(); - mtapi_taskattr_init(&attr, &status); - assert(MTAPI_SUCCESS == status); - mtapi_taskattr_set(&attr, MTAPI_TASK_PRIORITY, - &policy.priority_, sizeof(policy.priority_), &status); - assert(MTAPI_SUCCESS == status); - mtapi_taskattr_set(&attr, MTAPI_TASK_AFFINITY, - &policy.affinity_, sizeof(policy.affinity_), &status); - 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); - assert(MTAPI_SUCCESS == status); - Action* holder = embb::base::Allocation::New(action); - handle_ = mtapi_task_start(MTAPI_TASK_ID_NONE, job, - holder, sizeof(Action), MTAPI_NULL, 0, &attr, MTAPI_GROUP_NONE, &status); - if (MTAPI_SUCCESS != status) { - EMBB_THROW(embb::base::ErrorException, - "mtapi::Task could not be started"); - } -} - -Task::Task( - Action action, - mtapi_group_hndl_t group) { - mtapi_status_t status; - mtapi_task_attributes_t attr; - ExecutionPolicy policy = action.GetExecutionPolicy(); - mtapi_taskattr_init(&attr, &status); - assert(MTAPI_SUCCESS == status); - mtapi_taskattr_set(&attr, MTAPI_TASK_PRIORITY, - &policy.priority_, sizeof(policy.priority_), &status); - assert(MTAPI_SUCCESS == status); - mtapi_taskattr_set(&attr, MTAPI_TASK_AFFINITY, - &policy.affinity_, sizeof(policy.affinity_), &status); - 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); - assert(MTAPI_SUCCESS == status); - Action* holder = embb::base::Allocation::New(action); - handle_ = mtapi_task_start(MTAPI_TASK_ID_NONE, job, - holder, sizeof(Action), MTAPI_NULL, 0, &attr, group, &status); - if (MTAPI_SUCCESS != status) { - EMBB_THROW(embb::base::ErrorException, - "mtapi::Task could not be started"); - } -} - -Task::Task( - mtapi_task_id_t id, - Action action, - mtapi_group_hndl_t group) { - mtapi_status_t status; - mtapi_task_attributes_t attr; - ExecutionPolicy policy = action.GetExecutionPolicy(); - mtapi_taskattr_init(&attr, &status); - assert(MTAPI_SUCCESS == status); - mtapi_taskattr_set(&attr, MTAPI_TASK_PRIORITY, - &policy.priority_, sizeof(policy.priority_), &status); - assert(MTAPI_SUCCESS == status); - mtapi_taskattr_set(&attr, MTAPI_TASK_AFFINITY, - &policy.affinity_, sizeof(policy.affinity_), &status); - 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); - assert(MTAPI_SUCCESS == status); - Action* holder = embb::base::Allocation::New(action); - void * idptr = MTAPI_NULL; - memcpy(&idptr, &id, sizeof(id)); - handle_ = mtapi_task_start(id, job, - holder, sizeof(Action), idptr, 0, &attr, group, &status); - if (MTAPI_SUCCESS != status) { - EMBB_THROW(embb::base::ErrorException, - "mtapi::Task could not be started"); - } -} - -Task::Task( - Action action, - mtapi_queue_hndl_t queue) { - mtapi_status_t status; - mtapi_task_attributes_t attr; - ExecutionPolicy policy = action.GetExecutionPolicy(); - mtapi_taskattr_init(&attr, &status); - assert(MTAPI_SUCCESS == status); - mtapi_taskattr_set(&attr, MTAPI_TASK_PRIORITY, - &policy.priority_, sizeof(policy.priority_), &status); - assert(MTAPI_SUCCESS == status); - mtapi_taskattr_set(&attr, MTAPI_TASK_AFFINITY, - &policy.affinity_, sizeof(policy.affinity_), &status); - assert(MTAPI_SUCCESS == status); - Action* holder = embb::base::Allocation::New(action); - handle_ = mtapi_task_enqueue(MTAPI_TASK_ID_NONE, queue, - holder, sizeof(Action), MTAPI_NULL, 0, &attr, MTAPI_GROUP_NONE, &status); - if (MTAPI_SUCCESS != status) { - EMBB_THROW(embb::base::ErrorException, - "mtapi::Task could not be started"); - } -} - -Task::Task( - Action action, - mtapi_queue_hndl_t queue, - mtapi_group_hndl_t group) { - mtapi_status_t status; - mtapi_task_attributes_t attr; - ExecutionPolicy policy = action.GetExecutionPolicy(); - mtapi_taskattr_init(&attr, &status); - assert(MTAPI_SUCCESS == status); - mtapi_taskattr_set(&attr, MTAPI_TASK_PRIORITY, - &policy.priority_, sizeof(policy.priority_), &status); - assert(MTAPI_SUCCESS == status); - mtapi_taskattr_set(&attr, MTAPI_TASK_AFFINITY, - &policy.affinity_, sizeof(policy.affinity_), &status); - assert(MTAPI_SUCCESS == status); - Action* holder = embb::base::Allocation::New(action); - handle_ = mtapi_task_enqueue(MTAPI_TASK_ID_NONE, queue, - holder, sizeof(Action), MTAPI_NULL, 0, &attr, group, &status); - if (MTAPI_SUCCESS != status) { - EMBB_THROW(embb::base::ErrorException, - "mtapi::Task could not be started"); - } -} - -Task::Task( - mtapi_task_id_t id, - Action action, - mtapi_queue_hndl_t queue, - mtapi_group_hndl_t group) { - mtapi_status_t status; - mtapi_task_attributes_t attr; - ExecutionPolicy policy = action.GetExecutionPolicy(); - mtapi_taskattr_init(&attr, &status); - assert(MTAPI_SUCCESS == status); - mtapi_taskattr_set(&attr, MTAPI_TASK_PRIORITY, - &policy.priority_, sizeof(policy.priority_), &status); - assert(MTAPI_SUCCESS == status); - mtapi_taskattr_set(&attr, MTAPI_TASK_AFFINITY, - &policy.affinity_, sizeof(policy.affinity_), &status); - assert(MTAPI_SUCCESS == status); - Action* holder = embb::base::Allocation::New(action); - void * idptr = MTAPI_NULL; - memcpy(&idptr, &id, sizeof(id)); - handle_ = mtapi_task_enqueue(id, queue, - holder, sizeof(Action), idptr, 0, &attr, group, &status); - if (MTAPI_SUCCESS != status) { - EMBB_THROW(embb::base::ErrorException, - "mtapi::Task could not be started"); - } -} - -Task::~Task() { -} - -mtapi_status_t Task::Wait(mtapi_timeout_t timeout) { - mtapi_status_t status; - mtapi_task_wait(handle_, timeout, &status); - return status; -} - -void Task::Cancel() { - mtapi_status_t status; - mtapi_task_cancel(handle_, &status); - assert(MTAPI_SUCCESS == status); -} - -} // namespace mtapi -} // namespace embb diff --git a/mtapi_cpp/src/taskcontext.cc b/mtapi_cpp/src/taskcontext.cc deleted file mode 100644 index 71e28b3..0000000 --- a/mtapi_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/mtapi_cpp/test/main.cc b/mtapi_cpp/test/main.cc deleted file mode 100644 index f5aa24a..0000000 --- a/mtapi_cpp/test/main.cc +++ /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. - */ - -#include - -#include - -#include -#include -#include - - -PT_MAIN("MTAPI C++") { - PT_RUN(TaskTest); - PT_RUN(GroupTest); - PT_RUN(QueueTest); -} diff --git a/mtapi_cpp/test/mtapi_cpp_test_config.h b/mtapi_cpp/test/mtapi_cpp_test_config.h deleted file mode 100644 index 4b3c2d7..0000000 --- a/mtapi_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/mtapi_cpp/test/mtapi_cpp_test_group.cc b/mtapi_cpp/test/mtapi_cpp_test_group.cc deleted file mode 100644 index 6645dd5..0000000 --- a/mtapi_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/mtapi_cpp/test/mtapi_cpp_test_group.h b/mtapi_cpp/test/mtapi_cpp_test_group.h deleted file mode 100644 index 7a1cf2c..0000000 --- a/mtapi_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/mtapi_cpp/test/mtapi_cpp_test_queue.cc b/mtapi_cpp/test/mtapi_cpp_test_queue.cc deleted file mode 100644 index b8f7145..0000000 --- a/mtapi_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/mtapi_cpp/test/mtapi_cpp_test_queue.h b/mtapi_cpp/test/mtapi_cpp_test_queue.h deleted file mode 100644 index 9659ae2..0000000 --- a/mtapi_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/mtapi_cpp/test/mtapi_cpp_test_task.cc b/mtapi_cpp/test/mtapi_cpp_test_task.cc deleted file mode 100644 index 88242b3..0000000 --- a/mtapi_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/mtapi_cpp/test/mtapi_cpp_test_task.h b/mtapi_cpp/test/mtapi_cpp_test_task.h deleted file mode 100644 index f86b6fe..0000000 --- a/mtapi_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/CMakeLists.txt b/tasks_cpp/CMakeLists.txt new file mode 100644 index 0000000..19a6353 --- /dev/null +++ b/tasks_cpp/CMakeLists.txt @@ -0,0 +1,49 @@ +project (project_mtapi_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") + +if (USE_AUTOMATIC_INITIALIZATION STREQUAL ON) + message("-- Automatic initialization enabled (default)") + set(MTAPI_CPP_AUTOMATIC_INITIALIZE 1) +else() + set(MTAPI_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") + +# Execute the GroupSources macro +include(${CMAKE_SOURCE_DIR}/CMakeCommon/GroupSourcesMSVC.cmake) +GroupSourcesMSVC(include) +GroupSourcesMSVC(src) +GroupSourcesMSVC(test) + +set (EMBB_MTAPI_CPP_INCLUDE_DIRS "include" "src" "test") +include_directories(${EMBB_MTAPI_CPP_INCLUDE_DIRS} + ${CMAKE_CURRENT_BINARY_DIR}/include + ${CMAKE_CURRENT_SOURCE_DIR}/../base_c/include + ${CMAKE_CURRENT_BINARY_DIR}/../base_c/include + ${CMAKE_CURRENT_SOURCE_DIR}/../base_cpp/include + ${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) + +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 + embb_base_cpp embb_base_c ${compiler_libs}) + CopyBin(BIN embb_mtapi_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) diff --git a/tasks_cpp/include/embb/mtapi/action.h b/tasks_cpp/include/embb/mtapi/action.h new file mode 100644 index 0000000..68e9776 --- /dev/null +++ b/tasks_cpp/include/embb/mtapi/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_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 new file mode 100644 index 0000000..29789a2 --- /dev/null +++ b/tasks_cpp/include/embb/mtapi/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_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 new file mode 100644 index 0000000..85727f3 --- /dev/null +++ b/tasks_cpp/include/embb/mtapi/execution_policy.h @@ -0,0 +1,151 @@ +/* + * 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 new file mode 100644 index 0000000..b3c4906 --- /dev/null +++ b/tasks_cpp/include/embb/mtapi/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_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 new file mode 100644 index 0000000..32af64c --- /dev/null +++ b/tasks_cpp/include/embb/mtapi/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_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 new file mode 100644 index 0000000..4c83834 --- /dev/null +++ b/tasks_cpp/include/embb/mtapi/mtapi.h @@ -0,0 +1,55 @@ +/* + * 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 new file mode 100644 index 0000000..a7c5d99 --- /dev/null +++ b/tasks_cpp/include/embb/mtapi/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_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 new file mode 100644 index 0000000..4671359 --- /dev/null +++ b/tasks_cpp/include/embb/mtapi/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_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 new file mode 100644 index 0000000..a98e09a --- /dev/null +++ b/tasks_cpp/include/embb/mtapi/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_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 new file mode 100644 index 0000000..955991d --- /dev/null +++ b/tasks_cpp/include/embb/mtapi/taskcontext.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_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/src/continuation.cc b/tasks_cpp/src/continuation.cc new file mode 100644 index 0000000..40bbc30 --- /dev/null +++ b/tasks_cpp/src/continuation.cc @@ -0,0 +1,94 @@ +/* + * 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 + +namespace embb { +namespace mtapi { + +Continuation::Continuation(Action action) { + first_ = last_ = embb::base::Allocation::New(); + first_->action = action; + first_->next = NULL; +} + +Continuation::Continuation(Continuation const & cont) + : first_(cont.first_) + , last_(cont.last_) { +} + +Continuation::~Continuation() { +} + +void Continuation::ExecuteContinuation(TaskContext &) { + mtapi::ContinuationStage * stage = first_; + mtapi::Node & node = mtapi::Node::GetInstance(); + while (NULL != stage) { + mtapi::Task task = node.Spawn(stage->action); + task.Wait(MTAPI_INFINITE); + stage = stage->next; + } + + // delete stages + stage = first_; + while (NULL != stage) { + mtapi::ContinuationStage * next = stage->next; + embb::base::Allocation::Delete(stage); + stage = next; + } +} + +Continuation & Continuation::Then(Action action) { + ContinuationStage * cur = embb::base::Allocation::New(); + cur->action = action; + cur->next = NULL; + + last_->next = cur; + last_ = cur; + + return *this; +} + +Task Continuation::Spawn() { + return Spawn(ExecutionPolicy()); +} + +Task Continuation::Spawn(ExecutionPolicy execution_policy) { + Node & node = Node::GetInstance(); + return node.Spawn( + Action( + embb::base::MakeFunction(*this, &Continuation::ExecuteContinuation), + ExecutionPolicy(execution_policy))); +} + +} // namespace mtapi +} // namespace embb diff --git a/tasks_cpp/src/continuationstage.h b/tasks_cpp/src/continuationstage.h new file mode 100644 index 0000000..1f37607 --- /dev/null +++ b/tasks_cpp/src/continuationstage.h @@ -0,0 +1,43 @@ +/* + * 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_SRC_CONTINUATIONSTAGE_H_ +#define MTAPI_CPP_SRC_CONTINUATIONSTAGE_H_ + +#include + +namespace embb { +namespace mtapi { + +struct ContinuationStage { + mtapi::Action action; + ContinuationStage * next; +}; + +} // namespace mtapi +} // namespace embb + +#endif // MTAPI_CPP_SRC_CONTINUATIONSTAGE_H_ diff --git a/tasks_cpp/src/execution_policy.cc b/tasks_cpp/src/execution_policy.cc new file mode 100644 index 0000000..157d0ac --- /dev/null +++ b/tasks_cpp/src/execution_policy.cc @@ -0,0 +1,124 @@ +/* + * 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 + +namespace embb { +namespace mtapi { + +ExecutionPolicy::ExecutionPolicy() : + priority_(DefaultPriority) { +#if MTAPI_CPP_AUTOMATIC_INITIALIZE + Node::GetInstance(); // MTAPI has to be initialized +#endif + mtapi_status_t status; + mtapi_affinity_init(&affinity_, MTAPI_TRUE, &status); + if (MTAPI_SUCCESS != status) { + EMBB_THROW(embb::base::ErrorException, + "Could not default construct Affinity."); + } +} + +ExecutionPolicy::ExecutionPolicy(bool initial_affinity, mtapi_uint_t priority) +:priority_(priority) { +#if MTAPI_CPP_AUTOMATIC_INITIALIZE + Node::GetInstance(); // MTAPI has to be initialized +#endif + mtapi_status_t status; + mtapi_affinity_init(&affinity_, initial_affinity ? MTAPI_TRUE : MTAPI_FALSE, + &status); + if (MTAPI_SUCCESS != status) { + EMBB_THROW(embb::base::ErrorException, + "Could not default construct Affinity."); + } +} + +ExecutionPolicy::ExecutionPolicy(mtapi_uint_t priority) +:priority_(priority) { +#if MTAPI_CPP_AUTOMATIC_INITIALIZE + Node::GetInstance(); // MTAPI has to be initialized +#endif + mtapi_status_t status; + mtapi_affinity_init(&affinity_, MTAPI_TRUE, &status); + if (MTAPI_SUCCESS != status) { + EMBB_THROW(embb::base::ErrorException, + "Could not default construct Affinity."); + } +} + +ExecutionPolicy::ExecutionPolicy(bool initial_affinity) +:priority_(DefaultPriority) { +#if MTAPI_CPP_AUTOMATIC_INITIALIZE + Node::GetInstance(); // MTAPI has to be initialized +#endif + mtapi_status_t status; + mtapi_affinity_init(&affinity_, initial_affinity ? MTAPI_TRUE : MTAPI_FALSE, + &status); + if (MTAPI_SUCCESS != status) { + EMBB_THROW(embb::base::ErrorException, + "Could not default construct Affinity."); + } +} + +void ExecutionPolicy::AddWorker(mtapi_uint_t worker) { + mtapi_status_t status; + mtapi_affinity_set(&affinity_, worker, MTAPI_TRUE, &status); + assert(MTAPI_SUCCESS == status); +} + +void ExecutionPolicy::RemoveWorker(mtapi_uint_t worker) { + mtapi_status_t status; + mtapi_affinity_set(&affinity_, worker, MTAPI_FALSE, &status); + assert(MTAPI_SUCCESS == status); +} + +bool ExecutionPolicy::IsSetWorker(mtapi_uint_t worker) { + mtapi_status_t status; + mtapi_boolean_t aff = mtapi_affinity_get(&affinity_, worker, &status); + assert(MTAPI_SUCCESS == status); + return MTAPI_TRUE == aff; +} + +unsigned int ExecutionPolicy::GetCoreCount() const { + return embb_bitset_count(&affinity_); +} + +const mtapi_affinity_t &ExecutionPolicy::GetAffinity() const { + return affinity_; +} + +mtapi_uint_t ExecutionPolicy::GetPriority() const { + return priority_; +} + +const mtapi_uint_t ExecutionPolicy::DefaultPriority = 0; + +} // namespace mtapi +} // namespace embb diff --git a/tasks_cpp/src/group.cc b/tasks_cpp/src/group.cc new file mode 100644 index 0000000..20dc0b2 --- /dev/null +++ b/tasks_cpp/src/group.cc @@ -0,0 +1,96 @@ +/* + * 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 + +namespace embb { +namespace mtapi { + +Group::Group() { + Create(); +} + +Group::~Group() { + mtapi_status_t status; + mtapi_group_delete(handle_, &status); + assert(MTAPI_SUCCESS == status); +} + +void Group::Create() { + mtapi_status_t status; + handle_ = mtapi_group_create(MTAPI_GROUP_ID_NONE, MTAPI_NULL, &status); + if (MTAPI_SUCCESS != status) { + EMBB_THROW(embb::base::ErrorException, + "mtapi::Group could not be constructed"); + } +} + +Task Group::Spawn(Action action) { + return Task(action, handle_); +} + +Task Group::Spawn(mtapi_task_id_t id, Action action) { + return Task(id, action, handle_); +} + +mtapi_status_t Group::WaitAny(mtapi_timeout_t timeout) { + mtapi_status_t status; + mtapi_group_wait_any(handle_, MTAPI_NULL, timeout, &status); + if (MTAPI_GROUP_COMPLETED == status) { + // group has been deleted, so recreate it for simplicity + Create(); + } + return status; +} + +mtapi_status_t Group::WaitAny( + mtapi_timeout_t timeout, + mtapi_task_id_t & result) { + mtapi_status_t status; + void * res; + mtapi_group_wait_any(handle_, &res, timeout, &status); + memcpy(&result, &res, sizeof(result)); + if (MTAPI_GROUP_COMPLETED == status) { + // group has been deleted, so recreate it for simplicity + Create(); + } + return status; +} + +mtapi_status_t Group::WaitAll(mtapi_timeout_t timeout) { + mtapi_status_t status; + mtapi_group_wait_all(handle_, timeout, &status); + // group has been deleted, so recreate it for simplicity + Create(); + return status; +} + +} // namespace mtapi +} // namespace embb diff --git a/tasks_cpp/src/node.cc b/tasks_cpp/src/node.cc new file mode 100644 index 0000000..0ffe21a --- /dev/null +++ b/tasks_cpp/src/node.cc @@ -0,0 +1,274 @@ +/* + * 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 +#include +#if MTAPI_CPP_AUTOMATIC_INITIALIZE +#include +#endif + +namespace { + +static embb::mtapi::Node * node_instance = NULL; +#if MTAPI_CPP_AUTOMATIC_INITIALIZE +static embb::base::Mutex init_mutex; +#endif + +} + +namespace embb { +namespace mtapi { + +void Node::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::Action * action = + reinterpret_cast(const_cast(args)); + mtapi::TaskContext task_context(context); + (*action)(task_context); + embb::base::Allocation::Delete(action); +} + +Node::Node( + mtapi_domain_t domain_id, + mtapi_node_t node_id, + mtapi_node_attributes_t * attr) { + mtapi_status_t status; + mtapi_info_t info; + mtapi_initialize(domain_id, node_id, attr, &info, &status); + if (MTAPI_SUCCESS != status) { + EMBB_THROW(embb::base::ErrorException, + "mtapi::Node could not initialize mtapi"); + } + 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, + MTAPI_NULL, 0, MTAPI_NULL, &status); + if (MTAPI_SUCCESS != status) { + EMBB_THROW(embb::base::ErrorException, + "mtapi::Node could not create an action"); + } +} + +Node::~Node() { + for (std::list::iterator ii = queues_.begin(); + ii != queues_.end(); + ++ii) { + embb::base::Allocation::Delete(*ii); + } + queues_.clear(); + + for (std::list::iterator ii = groups_.begin(); + ii != groups_.end(); + ++ii) { + embb::base::Allocation::Delete(*ii); + } + groups_.clear(); + + mtapi_status_t status; + mtapi_action_delete(action_handle_, MTAPI_INFINITE, &status); + assert(MTAPI_SUCCESS == status); + mtapi_finalize(&status); + assert(MTAPI_SUCCESS == status); +} + +void Node::Initialize( + mtapi_domain_t domain_id, + mtapi_node_t node_id) { + if (IsInitialized()) { + EMBB_THROW(embb::base::ErrorException, + "mtapi::Node was already initialized"); + } else { + mtapi_status_t status; + mtapi_node_attributes_t attr; + mtapi_uint_t tmp; + mtapi_nodeattr_init(&attr, &status); + assert(MTAPI_SUCCESS == status); + tmp = 4; + mtapi_nodeattr_set(&attr, MTAPI_NODE_MAX_ACTIONS, + &tmp, sizeof(tmp), &status); + assert(MTAPI_SUCCESS == status); + tmp = 4; + mtapi_nodeattr_set(&attr, MTAPI_NODE_MAX_JOBS, + &tmp, sizeof(tmp), &status); + assert(MTAPI_SUCCESS == status); + tmp = 1; + mtapi_nodeattr_set(&attr, MTAPI_NODE_MAX_ACTIONS_PER_JOB, + &tmp, sizeof(tmp), &status); + assert(MTAPI_SUCCESS == status); + node_instance = embb::base::Allocation::New( + domain_id, node_id, &attr); + } +} + +void Node::Initialize( + mtapi_domain_t domain_id, + mtapi_node_t node_id, + embb::base::CoreSet const & core_set, + mtapi_uint_t max_tasks, + mtapi_uint_t max_groups, + mtapi_uint_t max_queues, + mtapi_uint_t queue_limit, + mtapi_uint_t max_priorities) { + if (IsInitialized()) { + EMBB_THROW(embb::base::ErrorException, + "mtapi::Node was already initialized"); + } else { + mtapi_status_t status; + mtapi_node_attributes_t attr; + mtapi_uint_t tmp; + mtapi_nodeattr_init(&attr, &status); + assert(MTAPI_SUCCESS == status); + embb_core_set_t cs; + embb_core_set_init(&cs, 0); + for (unsigned int ii = 0; embb_core_set_count(&cs) < core_set.Count(); + ii++) { + if (core_set.IsContained(ii)) { + embb_core_set_add(&cs, ii); + } + } + mtapi_nodeattr_set(&attr, MTAPI_NODE_CORE_AFFINITY, + &cs, sizeof(cs), &status); + assert(MTAPI_SUCCESS == status); + mtapi_nodeattr_set(&attr, MTAPI_NODE_MAX_TASKS, + &max_tasks, sizeof(max_tasks), &status); + assert(MTAPI_SUCCESS == status); + tmp = 4; + mtapi_nodeattr_set(&attr, MTAPI_NODE_MAX_ACTIONS, + &tmp, sizeof(tmp), &status); + assert(MTAPI_SUCCESS == status); + mtapi_nodeattr_set(&attr, MTAPI_NODE_MAX_GROUPS, + &max_groups, sizeof(max_groups), &status); + assert(MTAPI_SUCCESS == status); + mtapi_nodeattr_set(&attr, MTAPI_NODE_MAX_QUEUES, + &max_queues, sizeof(max_queues), &status); + assert(MTAPI_SUCCESS == status); + mtapi_nodeattr_set(&attr, MTAPI_NODE_QUEUE_LIMIT, + &queue_limit, sizeof(queue_limit), &status); + assert(MTAPI_SUCCESS == status); + tmp = 4; + mtapi_nodeattr_set(&attr, MTAPI_NODE_MAX_JOBS, + &tmp, sizeof(tmp), &status); + assert(MTAPI_SUCCESS == status); + tmp = 1; + mtapi_nodeattr_set(&attr, MTAPI_NODE_MAX_ACTIONS_PER_JOB, + &tmp, sizeof(tmp), &status); + assert(MTAPI_SUCCESS == status); + mtapi_nodeattr_set(&attr, MTAPI_NODE_MAX_PRIORITIES, + &max_priorities, sizeof(max_priorities), &status); + assert(MTAPI_SUCCESS == status); + node_instance = embb::base::Allocation::New( + domain_id, node_id, &attr); + } +} + +bool Node::IsInitialized() { + return NULL != node_instance; +} + +Node & Node::GetInstance() { +#if MTAPI_CPP_AUTOMATIC_INITIALIZE + if (!IsInitialized()) { + init_mutex.Lock(); + if (!IsInitialized()) { + Node::Initialize( + MTAPI_CPP_AUTOMATIC_DOMAIN_ID, MTAPI_CPP_AUTOMATIC_NODE_ID); + atexit(Node::Finalize); + } + init_mutex.Unlock(); + } + return *node_instance; +#else + if (IsInitialized()) { + return *node_instance; + } else { + EMBB_THROW(embb::base::ErrorException, + "mtapi::Node is not initialized"); + } +#endif +} + +void Node::Finalize() { + if (IsInitialized()) { + embb::base::Allocation::Delete(node_instance); + node_instance = NULL; + } else { + EMBB_THROW(embb::base::ErrorException, + "mtapi::Node is not initialized"); + } +} + +Group & Node::CreateGroup() { + Group * group = embb::base::Allocation::New(); + groups_.push_back(group); + return *group; +} + +void Node::DestroyGroup(Group & group) { + std::list::iterator ii = + std::find(groups_.begin(), groups_.end(), &group); + if (ii != groups_.end()) { + embb::base::Allocation::Delete(*ii); + groups_.erase(ii); + } +} + +Queue & Node::CreateQueue(mtapi_uint_t priority, bool ordered) { + Queue * queue = embb::base::Allocation::New(priority, ordered); + queues_.push_back(queue); + return *queue; +} + +void Node::DestroyQueue(Queue & queue) { + std::list::iterator ii = + std::find(queues_.begin(), queues_.end(), &queue); + if (ii != queues_.end()) { + embb::base::Allocation::Delete(*ii); + queues_.erase(ii); + } +} + +Task Node::Spawn(Action action) { + return Task(action); +} + +Continuation Node::First(Action action) { + return Continuation(action); +} + +} // namespace mtapi +} // namespace embb diff --git a/tasks_cpp/src/queue.cc b/tasks_cpp/src/queue.cc new file mode 100644 index 0000000..a6e8371 --- /dev/null +++ b/tasks_cpp/src/queue.cc @@ -0,0 +1,90 @@ +/* + * 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 + +namespace embb { +namespace mtapi { + +Queue::Queue(mtapi_uint_t priority, bool ordered) { + mtapi_status_t status; + mtapi_queue_attributes_t attr; + mtapi_boolean_t bb; + mtapi_queueattr_init(&attr, &status); + assert(MTAPI_SUCCESS == status); + mtapi_queueattr_set(&attr, MTAPI_QUEUE_PRIORITY, + &priority, sizeof(priority), &status); + assert(MTAPI_SUCCESS == status); + bb = ordered ? MTAPI_TRUE : MTAPI_FALSE; + mtapi_queueattr_set(&attr, MTAPI_QUEUE_ORDERED, + &bb, sizeof(bb), &status); + assert(MTAPI_SUCCESS == status); + bb = MTAPI_TRUE; + mtapi_queueattr_set(&attr, MTAPI_QUEUE_RETAIN, + &bb, sizeof(bb), &status); + 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); + assert(MTAPI_SUCCESS == status); + handle_ = mtapi_queue_create(MTAPI_QUEUE_ID_NONE, job, &attr, &status); + if (MTAPI_SUCCESS != status) { + EMBB_THROW(embb::base::ErrorException, + "mtapi::Queue could not be constructed"); + } +} + +Queue::~Queue() { + mtapi_status_t status; + mtapi_queue_delete(handle_, MTAPI_INFINITE, &status); + assert(MTAPI_SUCCESS == status); +} + +void Queue::Enable() { + mtapi_status_t status; + mtapi_queue_enable(handle_, &status); + assert(MTAPI_SUCCESS == status); +} + +void Queue::Disable() { + mtapi_status_t status; + mtapi_queue_disable(handle_, MTAPI_INFINITE, &status); + assert(MTAPI_SUCCESS == status); +} + +Task Queue::Spawn(Action action) { + return Task(action, handle_); +} + +Task Queue::Spawn(Group const * group, Action action) { + return Task(action, handle_, group->handle_); +} + +} // namespace mtapi +} // namespace embb diff --git a/tasks_cpp/src/task.cc b/tasks_cpp/src/task.cc new file mode 100644 index 0000000..5239a3c --- /dev/null +++ b/tasks_cpp/src/task.cc @@ -0,0 +1,220 @@ +/* + * 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 + +namespace embb { +namespace mtapi { + +Task::Task() { + handle_.id = 0; + handle_.tag = 0; +} + +Task::Task(Task const & task) + : handle_(task.handle_) { + // empty +} + +Task::Task( + Action action) { + mtapi_status_t status; + mtapi_task_attributes_t attr; + ExecutionPolicy policy = action.GetExecutionPolicy(); + mtapi_taskattr_init(&attr, &status); + assert(MTAPI_SUCCESS == status); + mtapi_taskattr_set(&attr, MTAPI_TASK_PRIORITY, + &policy.priority_, sizeof(policy.priority_), &status); + assert(MTAPI_SUCCESS == status); + mtapi_taskattr_set(&attr, MTAPI_TASK_AFFINITY, + &policy.affinity_, sizeof(policy.affinity_), &status); + 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); + assert(MTAPI_SUCCESS == status); + Action* holder = embb::base::Allocation::New(action); + handle_ = mtapi_task_start(MTAPI_TASK_ID_NONE, job, + holder, sizeof(Action), MTAPI_NULL, 0, &attr, MTAPI_GROUP_NONE, &status); + if (MTAPI_SUCCESS != status) { + EMBB_THROW(embb::base::ErrorException, + "mtapi::Task could not be started"); + } +} + +Task::Task( + Action action, + mtapi_group_hndl_t group) { + mtapi_status_t status; + mtapi_task_attributes_t attr; + ExecutionPolicy policy = action.GetExecutionPolicy(); + mtapi_taskattr_init(&attr, &status); + assert(MTAPI_SUCCESS == status); + mtapi_taskattr_set(&attr, MTAPI_TASK_PRIORITY, + &policy.priority_, sizeof(policy.priority_), &status); + assert(MTAPI_SUCCESS == status); + mtapi_taskattr_set(&attr, MTAPI_TASK_AFFINITY, + &policy.affinity_, sizeof(policy.affinity_), &status); + 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); + assert(MTAPI_SUCCESS == status); + Action* holder = embb::base::Allocation::New(action); + handle_ = mtapi_task_start(MTAPI_TASK_ID_NONE, job, + holder, sizeof(Action), MTAPI_NULL, 0, &attr, group, &status); + if (MTAPI_SUCCESS != status) { + EMBB_THROW(embb::base::ErrorException, + "mtapi::Task could not be started"); + } +} + +Task::Task( + mtapi_task_id_t id, + Action action, + mtapi_group_hndl_t group) { + mtapi_status_t status; + mtapi_task_attributes_t attr; + ExecutionPolicy policy = action.GetExecutionPolicy(); + mtapi_taskattr_init(&attr, &status); + assert(MTAPI_SUCCESS == status); + mtapi_taskattr_set(&attr, MTAPI_TASK_PRIORITY, + &policy.priority_, sizeof(policy.priority_), &status); + assert(MTAPI_SUCCESS == status); + mtapi_taskattr_set(&attr, MTAPI_TASK_AFFINITY, + &policy.affinity_, sizeof(policy.affinity_), &status); + 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); + assert(MTAPI_SUCCESS == status); + Action* holder = embb::base::Allocation::New(action); + void * idptr = MTAPI_NULL; + memcpy(&idptr, &id, sizeof(id)); + handle_ = mtapi_task_start(id, job, + holder, sizeof(Action), idptr, 0, &attr, group, &status); + if (MTAPI_SUCCESS != status) { + EMBB_THROW(embb::base::ErrorException, + "mtapi::Task could not be started"); + } +} + +Task::Task( + Action action, + mtapi_queue_hndl_t queue) { + mtapi_status_t status; + mtapi_task_attributes_t attr; + ExecutionPolicy policy = action.GetExecutionPolicy(); + mtapi_taskattr_init(&attr, &status); + assert(MTAPI_SUCCESS == status); + mtapi_taskattr_set(&attr, MTAPI_TASK_PRIORITY, + &policy.priority_, sizeof(policy.priority_), &status); + assert(MTAPI_SUCCESS == status); + mtapi_taskattr_set(&attr, MTAPI_TASK_AFFINITY, + &policy.affinity_, sizeof(policy.affinity_), &status); + assert(MTAPI_SUCCESS == status); + Action* holder = embb::base::Allocation::New(action); + handle_ = mtapi_task_enqueue(MTAPI_TASK_ID_NONE, queue, + holder, sizeof(Action), MTAPI_NULL, 0, &attr, MTAPI_GROUP_NONE, &status); + if (MTAPI_SUCCESS != status) { + EMBB_THROW(embb::base::ErrorException, + "mtapi::Task could not be started"); + } +} + +Task::Task( + Action action, + mtapi_queue_hndl_t queue, + mtapi_group_hndl_t group) { + mtapi_status_t status; + mtapi_task_attributes_t attr; + ExecutionPolicy policy = action.GetExecutionPolicy(); + mtapi_taskattr_init(&attr, &status); + assert(MTAPI_SUCCESS == status); + mtapi_taskattr_set(&attr, MTAPI_TASK_PRIORITY, + &policy.priority_, sizeof(policy.priority_), &status); + assert(MTAPI_SUCCESS == status); + mtapi_taskattr_set(&attr, MTAPI_TASK_AFFINITY, + &policy.affinity_, sizeof(policy.affinity_), &status); + assert(MTAPI_SUCCESS == status); + Action* holder = embb::base::Allocation::New(action); + handle_ = mtapi_task_enqueue(MTAPI_TASK_ID_NONE, queue, + holder, sizeof(Action), MTAPI_NULL, 0, &attr, group, &status); + if (MTAPI_SUCCESS != status) { + EMBB_THROW(embb::base::ErrorException, + "mtapi::Task could not be started"); + } +} + +Task::Task( + mtapi_task_id_t id, + Action action, + mtapi_queue_hndl_t queue, + mtapi_group_hndl_t group) { + mtapi_status_t status; + mtapi_task_attributes_t attr; + ExecutionPolicy policy = action.GetExecutionPolicy(); + mtapi_taskattr_init(&attr, &status); + assert(MTAPI_SUCCESS == status); + mtapi_taskattr_set(&attr, MTAPI_TASK_PRIORITY, + &policy.priority_, sizeof(policy.priority_), &status); + assert(MTAPI_SUCCESS == status); + mtapi_taskattr_set(&attr, MTAPI_TASK_AFFINITY, + &policy.affinity_, sizeof(policy.affinity_), &status); + assert(MTAPI_SUCCESS == status); + Action* holder = embb::base::Allocation::New(action); + void * idptr = MTAPI_NULL; + memcpy(&idptr, &id, sizeof(id)); + handle_ = mtapi_task_enqueue(id, queue, + holder, sizeof(Action), idptr, 0, &attr, group, &status); + if (MTAPI_SUCCESS != status) { + EMBB_THROW(embb::base::ErrorException, + "mtapi::Task could not be started"); + } +} + +Task::~Task() { +} + +mtapi_status_t Task::Wait(mtapi_timeout_t timeout) { + mtapi_status_t status; + mtapi_task_wait(handle_, timeout, &status); + return status; +} + +void Task::Cancel() { + mtapi_status_t status; + mtapi_task_cancel(handle_, &status); + assert(MTAPI_SUCCESS == status); +} + +} // namespace mtapi +} // namespace embb diff --git a/tasks_cpp/src/taskcontext.cc b/tasks_cpp/src/taskcontext.cc new file mode 100644 index 0000000..71e28b3 --- /dev/null +++ b/tasks_cpp/src/taskcontext.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 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 new file mode 100644 index 0000000..f5aa24a --- /dev/null +++ b/tasks_cpp/test/main.cc @@ -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. + */ + +#include + +#include + +#include +#include +#include + + +PT_MAIN("MTAPI C++") { + 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 new file mode 100644 index 0000000..4b3c2d7 --- /dev/null +++ b/tasks_cpp/test/mtapi_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 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 new file mode 100644 index 0000000..6645dd5 --- /dev/null +++ b/tasks_cpp/test/mtapi_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::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 new file mode 100644 index 0000000..7a1cf2c --- /dev/null +++ b/tasks_cpp/test/mtapi_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 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 new file mode 100644 index 0000000..b8f7145 --- /dev/null +++ b/tasks_cpp/test/mtapi_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::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 new file mode 100644 index 0000000..9659ae2 --- /dev/null +++ b/tasks_cpp/test/mtapi_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 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 new file mode 100644 index 0000000..88242b3 --- /dev/null +++ b/tasks_cpp/test/mtapi_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::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 new file mode 100644 index 0000000..f86b6fe --- /dev/null +++ b/tasks_cpp/test/mtapi_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