Commit 426360eb by Marcus Winter

Merge remote-tracking branch 'origin/development' into mtapi_distributed

Conflicts:
	mtapi_c/test/main.cc
parents fd503025 030d515c
# Copyright (c) 2014, Siemens AG. All rights reserved.
# Copyright (c) 2014-2015, Siemens AG. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause
language: cpp
......
Embedded Multicore Building Blocks (EMB²)
=========================================
Version 0.2.2
-------------
### Bug fixes:
- Fixed 64bit problem in atomics
- Fixed bug in dataflow_cpp causing network to hang
- Fixed bug in conversion of core_set
- Fixed fetch-and-add implementation to support armv7-a
- Fixed missing freeing of mutex attributes in case of error
- Fixed bug where closure was allocated with Allocation::New but deleted with operator delete
- Fixed inconsistent naming of unit test cases
- Fixed memory allocation in hazard pointer implementation by replacing calls to new and delete with EMB²-specific functions
- Fixed memory leak in tests for containers
- Fixed affinity implementation for FreeBSD
### Changes and improvements:
- Added checks for memory leaks in tests
- Added block size support in MergeSort
- Renamed all platform specific defines to EMBB_PLATFORM_*
- Changed all checks for platform specific defines to checks for EMBB_* defines
- Replaced C++11 initializer lists in examples with C++03 compliant statements
- Extended unit tests for MPMC queue with checks for relative order
- Added check for result of pthread_attr_destroy
- Added assert in embb_tss_get
- Moved ExecutionPolicy from algorithms to mtapi_cpp, removed Affinity
### Features:
- None
### Build system:
- Removed cppcheck warnings
- Removed cpplint warnings
### Documentation:
- Improved documentation of default values and priorities
- Revised template argument names in base_cpp and containers_cpp
- Moved ExecutionPolicy to CPP_MTAPI and Identity to CPP_ALGORITHMS Doxygen group
- Fixed description of token limit in tutorial
- Added Clang support to README
- Mentioned the ability to cross compile in README
- Added link to release files in README
- Minor corrections in README
- Updated copyright notice
- Changed year in tutorial.tex to 2015
Version 0.2.1
-------------
......
# Copyright (c) 2014, Siemens AG. All rights reserved.
# 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:
......
# Copyright (c) 2014, Siemens AG. All rights reserved.
# 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:
......
# Copyright (c) 2014, Siemens AG. All rights reserved.
# 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:
......
# Copyright (c) 2014, Siemens AG. All rights reserved.
# 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:
......
# Copyright (c) 2014, Siemens AG. All rights reserved.
# 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:
......
# Copyright (c) 2014, Siemens AG. All rights reserved.
# 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:
......
# Copyright (c) 2014, Siemens AG. All rights reserved.
# 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:
......@@ -28,7 +28,7 @@ cmake_minimum_required (VERSION 2.8.9)
# Version number
set (EMBB_BASE_VERSION_MAJOR 0)
set (EMBB_BASE_VERSION_MINOR 2)
set (EMBB_BASE_VERSION_PATCH 1)
set (EMBB_BASE_VERSION_PATCH 2)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING
......@@ -54,6 +54,7 @@ option(BUILD_EXAMPLES "Specify whether examples should be built" OFF)
option(USE_EXCEPTIONS "Specify whether exceptions should be activated in C++" ON)
option(INSTALL_DOCS "Specify whether Doxygen docs should be installed" ON)
option(WARNINGS_ARE_ERRORS "Specify whether warnings should be treated as errors" OFF)
option(USE_AUTOMATIC_INITIALIZATION "Specify whether the MTAPI C++ interface, algorithms and dataflow should automatically intialize the MTAPI node if no explicit initialization is present" ON)
## LOCAL INSTALLATION OF SUBPROJECT BINARIES
#
......
Embedded Multicore Building Blocks (EMB²)
Embedded Multicore Building Blocks (EMB²)
=========================================
Overview
......@@ -13,7 +13,7 @@ license (see file include\embb\mtapi\c\mtapi.h).
License
-------
Copyright (c) 2014, Siemens AG. All rights reserved.
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:
......@@ -35,4 +35,4 @@ 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.
\ No newline at end of file
POSSIBILITY OF SUCH DAMAGE.
......@@ -120,9 +120,9 @@ data structures for storing object in an organized and thread-safe way.
Build and Installation
----------------------
Note: It is recommended to build from a packaged release file and not from a
snapshot of the repository in order to get the documentation and the examples
out-of-the box.
Note: It is recommended to build from a release file and not from a repository
snapshot in order to get the documentation and the examples out-of-the box.
The release files can be found at https://github.com/siemens/embb/releases.
EMB² is built using CMake (version 2.8.9 or higher). CMake is a build file
generator which allows to abstract from the concrete build tools. To generate
......@@ -159,11 +159,24 @@ use:
cmake .. -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang
In the same way you may cross compile to another platform. For example, to cross
compile to ARM Linux using GCC, you need to specify the cross compiler itself and
the target architecture as an argument to the compiler:
cmake .. -DCMAKE_CXX_COMPILER=arm-linux-gnueabi-gcc++
-DCMAKE_CXX_FLAGS=-march=armv7-a
-DCMAKE_C_COMPILER=arm-linux-gnueabi-gcc
-DCMAKE_C_FLAGS=-march=armv7-a
EMB² can be built with and without C++ exception handling, which has to be
specified on build file generation. When exceptions are turned off, an error
message is emitted and the program aborts in case of an exception within EMB².
To disable exceptions, add the option -DUSE_EXCEPTIONS=OFF.
Similarly, automatic initialization of the task scheduler by the MTAPI C++
interface can be disabled with -DUSE_AUTOMATIC_INITIALIZATION=OFF. This way,
unexpected delays after startup can be avoided, e.g. for timing measurements.
The tutorial of EMB² comes with example source files in doc/examples/. These
can be built with the other source files using CMake option -DBUILD_EXAMPLES=ON
in the generation step. Note, however, that the examples use C++11 features and
......@@ -175,6 +188,10 @@ For a Linux Debug build with exception handling, type
cmake -G "Unix Makefiles" .. -DCMAKE_BUILD_TYPE=Debug
For a default Linux build without automatic MTAPI C++ initialization, type
cmake .. -DUSE_AUTOMATIC_INITIALIZATION=OFF
For a Windows build (VS 2013, x86) without exception handling, type
cmake -G "Visual Studio 12" .. -DUSE_EXCEPTIONS=OFF
......@@ -275,9 +292,13 @@ The C header files can be included as follows:
Documentation
-------------
EMB² comes with a tutorial, example programs, and an HTML reference
documentation describing the APIs, which can be found in the "doc" folder.
The root document of the HTML reference is "doc/reference/index.html".
The release files of EMB² come with a tutorial, example programs, and a
reference manual (HTML) describing the APIs. All documentation is contained in
the "doc" folder. The root document of the HTML reference is
"doc/reference/index.html". Note that generated documentation files are not
under version control and hence not contained in the repository. As mentioned
above, it is therefore recommended to download one of the packaged release
files in order to have ready-to-use documentation.
Code Quality
......@@ -310,6 +331,42 @@ The EMB² team welcomes all kinds of contributions, preferably as pull requests
or patches via the development mailing lists (see above). If possible, please
refer to a current snapshot of the development branch.
EMB² is supposed to be easily portable to platforms unsupported so far. Almost
all platform specific code is located in the base_c and base_cpp modules. All
existing platform specific code is fenced by EMBB_PLATFORM_* defines.
To distinguish between compilers, EMB² currently uses the following defines:
- EMBB_PLATFORM_COMPILER_GNUC
- EMBB_PLATFORM_COMPILER_MSVC
- EMBB_PLATFORM_COMPILER_UNKNOWN
Different architectures are distinguished using:
- EMBB_PLATFORM_ARCH_X86
- EMBB_PLATFORM_ARCH_X86_32
- EMBB_PLATFORM_ARCH_X86_64
- EMBB_PLATFORM_ARCH_ARM
- EMBB_PLATFORM_ARCH_UNKNOWN
Threading APIs are switched by:
- EMBB_PLATFORM_THREADING_WINTHREADS
- EMBB_PLATFORM_THREADING_POSIXTHREADS
Please use these defines for new platform specific code. If additional defines
are needed, they can be defined in the config.h or cmake_config.h.in files.
Important Notes
---------------
- The MTAPI C++ interface supports automatic initialization, which allows for
easy usage of the MTAPI C++, Algorithms, and Dataflow components. For
performance measurements, explicit initialization is strongly recommended
since the measurements will otherwise include the initialization time of
MTAPI.
Links
-----
......
......@@ -17,7 +17,8 @@ include_directories(${EMBB_ALGORITHMS_CPP_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}/../base_cpp/include
${CMAKE_CURRENT_BINARY_DIR}/../base_cpp/include
${CMAKE_CURRENT_SOURCE_DIR}/../mtapi_c/include
${CMAKE_CURRENT_SOURCE_DIR}/../mtapi_cpp/include)
${CMAKE_CURRENT_SOURCE_DIR}/../mtapi_cpp/include
${CMAKE_CURRENT_BINARY_DIR}/../mtapi_cpp/include)
add_library(embb_algorithms_cpp ${EMBB_ALGORITHMS_CPP_SOURCES}
${EMBB_ALGORITHMS_CPP_HEADERS})
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -34,7 +34,6 @@
*/
#include <embb/algorithms/count.h>
#include <embb/algorithms/execution_policy.h>
#include <embb/algorithms/for_each.h>
#include <embb/algorithms/identity.h>
#include <embb/algorithms/invoke.h>
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -27,7 +27,8 @@
#ifndef EMBB_ALGORITHMS_COUNT_H_
#define EMBB_ALGORITHMS_COUNT_H_
#include <embb/algorithms/execution_policy.h>
#include <embb/mtapi/execution_policy.h>
#include <iterator>
namespace embb {
namespace algorithms {
......@@ -55,7 +56,7 @@ namespace algorithms {
* while the algorithm is executed.
* \note No guarantee is given on the execution order of the comparison
* operations.
* \see CountIf(), ExecutionPolicy
* \see CountIf(), embb::mtapi::ExecutionPolicy
* \tparam RAI Random access iterator
* \tparam ValueType Type of \c value that is compared to the elements in the
* range using the \c operator==.
......@@ -70,8 +71,8 @@ typename std::iterator_traits<RAI>::difference_type Count(
const ValueType& value,
/**< [IN] Value that the elements in the range are compared to using
\c operator== */
const ExecutionPolicy& policy = ExecutionPolicy(),
/**< [IN] ExecutionPolicy for the counting algorithm */
const embb::mtapi::ExecutionPolicy& policy = embb::mtapi::ExecutionPolicy(),
/**< [IN] embb::mtapi::ExecutionPolicy for the counting algorithm */
size_t block_size = 0
/**< [IN] Lower bound for partitioning the range of elements into blocks that
are sorted in parallel. Partitioning of a block stops if its size
......@@ -95,7 +96,7 @@ typename std::iterator_traits<RAI>::difference_type Count(
* while the algorithm is executed.
* \note No guarantee is given on the execution order of the comparison
* function.
* \see Count(), ExecutionPolicy
* \see Count(), embb::mtapi::ExecutionPolicy
* \tparam RAI Random access iterator
* \tparam ComparisonFunction Unary predicate with argument of type
* <tt>std::iterator_traits<RAI>::value_type</tt>.
......@@ -110,8 +111,8 @@ typename std::iterator_traits<RAI>::difference_type CountIf(
ComparisonFunction comparison,
/**< [IN] Unary predicate used to test the elements in the range. Elements for
which \c comparison returns true are counted. */
const ExecutionPolicy& policy = ExecutionPolicy(),
/**< [IN] ExecutionPolicy for the counting algorithm */
const embb::mtapi::ExecutionPolicy& policy = embb::mtapi::ExecutionPolicy(),
/**< [IN] embb::mtapi::ExecutionPolicy for the counting algorithm */
size_t block_size = 0
/**< [IN] Lower bound for partitioning the range of elements into blocks that
are sorted in parallel. Partitioning of a block stops if its size
......@@ -124,6 +125,18 @@ typename std::iterator_traits<RAI>::difference_type CountIf(
#else // DOXYGEN
/**
* Overload of above described Doxygen dummy.
*/
template<typename RAI, typename ValueType>
typename std::iterator_traits<RAI>::difference_type Count(
RAI first,
RAI last,
const ValueType& value,
const embb::mtapi::ExecutionPolicy& policy,
size_t block_size
);
/**
* Overload of above described Doxygen dummy with less arguments.
*/
template<typename RAI, typename ValueType>
......@@ -132,7 +145,7 @@ typename std::iterator_traits<RAI>::difference_type Count(
RAI last,
const ValueType& value
) {
return Count(first, last, value, ExecutionPolicy(), 0);
return Count(first, last, value, embb::mtapi::ExecutionPolicy(), 0);
}
/**
......@@ -143,7 +156,7 @@ typename std::iterator_traits<RAI>::difference_type Count(
RAI first,
RAI last,
const ValueType& value,
const ExecutionPolicy& policy
const embb::mtapi::ExecutionPolicy& policy
) {
return Count(first, last, value, policy, 0);
}
......@@ -151,12 +164,12 @@ typename std::iterator_traits<RAI>::difference_type Count(
/**
* Overload of above described Doxygen dummy.
*/
template<typename RAI, typename ValueType>
typename std::iterator_traits<RAI>::difference_type Count(
template<typename RAI, typename ComparisonFunction>
typename std::iterator_traits<RAI>::difference_type CountIf(
RAI first,
RAI last,
const ValueType& value,
const ExecutionPolicy& policy,
ComparisonFunction comparison,
const embb::mtapi::ExecutionPolicy& policy,
size_t block_size
);
......@@ -169,7 +182,7 @@ typename std::iterator_traits<RAI>::difference_type CountIf(
RAI last,
ComparisonFunction comparison
) {
return CountIf(first, last, comparison, ExecutionPolicy(), 0);
return CountIf(first, last, comparison, embb::mtapi::ExecutionPolicy(), 0);
}
/**
......@@ -180,23 +193,11 @@ typename std::iterator_traits<RAI>::difference_type CountIf(
RAI first,
RAI last,
ComparisonFunction comparison,
const ExecutionPolicy& policy
const embb::mtapi::ExecutionPolicy& policy
) {
return CountIf(first, last, comparison, policy, 0);
}
/**
* Overload of above described Doxygen dummy.
*/
template<typename RAI, typename ComparisonFunction>
typename std::iterator_traits<RAI>::difference_type CountIf(
RAI first,
RAI last,
ComparisonFunction comparison,
const ExecutionPolicy& policy,
size_t block_size
);
#endif // else DOXYGEN
/**
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -27,7 +27,7 @@
#ifndef EMBB_ALGORITHMS_FOR_EACH_H_
#define EMBB_ALGORITHMS_FOR_EACH_H_
#include <embb/algorithms/execution_policy.h>
#include <embb/mtapi/execution_policy.h>
namespace embb {
namespace algorithms {
......@@ -53,7 +53,7 @@ namespace algorithms {
* while the algorithm is executed.
* \note No guarantee is given on the order in which the function is applied to
* the elements.
* \see ExecutionPolicy, ZipIterator
* \see embb::mtapi::ExecutionPolicy, ZipIterator
* \tparam RAI Random access iterator
* \tparam Function Unary function with argument of type
* <tt>std::iterator_traits<RAI>::value_type</tt>.
......@@ -67,8 +67,8 @@ void ForEach(
range */
Function unary,
/**< [IN] Unary function applied to each element in the range */
const ExecutionPolicy& policy = ExecutionPolicy(),
/**< [IN] ExecutionPolicy for the foreach loop execution */
const embb::mtapi::ExecutionPolicy& policy = embb::mtapi::ExecutionPolicy(),
/**< [IN] embb::mtapi::ExecutionPolicy for the foreach loop execution */
size_t block_size = 0
/**< [IN] Lower bound for partitioning the range of elements into blocks that
are treated in parallel. Partitioning of a block stops if its size
......@@ -81,16 +81,16 @@ void ForEach(
#else // DOXYGEN
/**
* Overload of above described Doxygen dummy with less arguments.
* Overload of above described Doxygen dummy.
*/
template<typename RAI, typename Function>
void ForEach(
RAI first,
RAI last,
Function unary
) {
ForEach(first, last, unary, ExecutionPolicy(), 0);
}
Function unary,
const embb::mtapi::ExecutionPolicy& policy,
size_t block_size
);
/**
* Overload of above described Doxygen dummy with less arguments.
......@@ -99,23 +99,23 @@ template<typename RAI, typename Function>
void ForEach(
RAI first,
RAI last,
Function unary,
const ExecutionPolicy& policy
Function unary
) {
ForEach(first, last, unary, policy, 0);
ForEach(first, last, unary, embb::mtapi::ExecutionPolicy(), 0);
}
/**
* Overload of above described Doxygen dummy.
* Overload of above described Doxygen dummy with less arguments.
*/
template<typename RAI, typename Function>
void ForEach(
RAI first,
RAI last,
Function unary,
const ExecutionPolicy& policy,
size_t block_size
);
const embb::mtapi::ExecutionPolicy& policy
) {
ForEach(first, last, unary, policy, 0);
}
#endif // else DOXYGEN
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -37,42 +37,45 @@ namespace internal {
template<typename ValueType>
class ValueComparisonFunction{
public:
explicit ValueComparisonFunction(const ValueType &value)
:value_(value) {}
ValueComparisonFunction(const ValueComparisonFunction &other)
:value_(other.value_) {}
explicit ValueComparisonFunction(const ValueType& value)
: value_(value) {}
ValueComparisonFunction(const ValueComparisonFunction& other)
: value_(other.value_) {}
template<typename ElementType>
int operator()(ElementType element) {
if(element == value_)
if (element == value_) {
return 1;
else
} else {
return 0;
}
}
private:
const ValueType &value_;
ValueComparisonFunction &operator=(const ValueComparisonFunction &other);
ValueComparisonFunction &operator=(
const ValueComparisonFunction& other);
};
template<typename Function>
class FunctionComparisonFunction{
public:
explicit FunctionComparisonFunction(Function function)
:function_(function) {}
: function_(function) {}
FunctionComparisonFunction(const FunctionComparisonFunction &other)
:function_(other.function_) {}
: function_(other.function_) {}
template<typename ElementType>
int operator()(ElementType element) {
if(function_(element))
if (function_(element)) {
return 1;
else
} else {
return 0;
}
}
private:
Function function_;
FunctionComparisonFunction &operator=(const FunctionComparisonFunction &
other);
FunctionComparisonFunction &operator=(
const FunctionComparisonFunction& other);
};
} // namespace internal
......@@ -80,7 +83,7 @@ class FunctionComparisonFunction{
template<typename RAI, typename ValueType>
typename std::iterator_traits<RAI>::difference_type
Count(RAI first, RAI last, const ValueType& value,
const ExecutionPolicy& policy, size_t block_size) {
const embb::mtapi::ExecutionPolicy& policy, size_t block_size) {
typedef typename std::iterator_traits<RAI>::difference_type Difference;
return Reduce(first, last, Difference(0), std::plus<Difference>(),
internal::ValueComparisonFunction<ValueType>(value), policy,
......@@ -90,7 +93,7 @@ typename std::iterator_traits<RAI>::difference_type
template<typename RAI, typename ComparisonFunction>
typename std::iterator_traits<RAI>::difference_type
CountIf(RAI first, RAI last, ComparisonFunction comparison,
const ExecutionPolicy& policy, size_t block_size) {
const embb::mtapi::ExecutionPolicy& policy, size_t block_size) {
typedef typename std::iterator_traits<RAI>::difference_type Difference;
return Reduce(first, last, Difference(0), std::plus<Difference>(),
internal::FunctionComparisonFunction<ComparisonFunction>
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -45,44 +45,54 @@ class ForEachFunctor {
/**
* Constructs a for-each functor with arguments.
*/
ForEachFunctor(RAI first, RAI last, Function unary,
const ExecutionPolicy& policy, size_t block_size)
: first_(first), last_(last), unary_(unary), policy_(policy),
block_size_(block_size) {
ForEachFunctor(size_t chunk_first, size_t chunk_last, Function unary,
const embb::mtapi::ExecutionPolicy& policy,
const BlockSizePartitioner<RAI>& partitioner)
: chunk_first_(chunk_first), chunk_last_(chunk_last),
unary_(unary), policy_(policy), partitioner_(partitioner) {
}
void Action(mtapi::TaskContext&) {
size_t distance = static_cast<size_t>(std::distance(first_, last_));
if (distance == 0) return;
if (distance <= block_size_) { // leaf case -> do work
for (RAI curIter(first_); curIter != last_; ++curIter) {
unary_(*curIter);
if (chunk_first_ == chunk_last_) {
// Leaf case, recursed to single chunk. Do work on chunk:
ChunkDescriptor<RAI> chunk = partitioner_[chunk_first_];
RAI first = chunk.GetFirst();
RAI last = chunk.GetLast();
for (RAI it = first; it != last; ++it) {
unary_(*it);
}
} else { // recurse further
ChunkPartitioner<RAI> partitioner(first_, last_, 2);
ForEachFunctor<RAI, Function> functorL(partitioner[0].GetFirst(),
partitioner[0].GetLast(), unary_, policy_, block_size_);
ForEachFunctor<RAI, Function> functorR(partitioner[1].GetFirst(),
partitioner[1].GetLast(), unary_, policy_, block_size_);
mtapi::Node& node = mtapi::Node::GetInstance();
mtapi::Task taskL = node.Spawn(mtapi::Action(base::MakeFunction(
functorL, &ForEachFunctor<RAI, Function>::Action),
policy_.GetAffinity()), policy_.GetPriority());
mtapi::Task taskR = node.Spawn(mtapi::Action(base::MakeFunction(
functorR, &ForEachFunctor<RAI, Function>::Action),
policy_.GetAffinity()), policy_.GetPriority());
taskL.Wait(MTAPI_INFINITE);
taskR.Wait(MTAPI_INFINITE);
} else {
// Recurse further:
size_t chunk_split_index = (chunk_first_ + chunk_last_) / 2;
// Split chunks into left / right branches:
self_t functor_l(chunk_first_,
chunk_split_index,
unary_, policy_, partitioner_);
self_t functor_r(chunk_split_index + 1,
chunk_last_,
unary_, policy_, partitioner_);
mtapi::Task task_l = mtapi::Node::GetInstance().Spawn(
mtapi::Action(
base::MakeFunction(functor_l, &self_t::Action),
policy_));
mtapi::Task task_r = mtapi::Node::GetInstance().Spawn(
mtapi::Action(
base::MakeFunction(functor_r, &self_t::Action),
policy_));
task_l.Wait(MTAPI_INFINITE);
task_r.Wait(MTAPI_INFINITE);
}
}
private:
RAI first_;
RAI last_;
typedef ForEachFunctor<RAI, Function> self_t;
private:
size_t chunk_first_;
size_t chunk_last_;
Function unary_;
const ExecutionPolicy& policy_;
size_t block_size_;
const embb::mtapi::ExecutionPolicy& policy_;
const BlockSizePartitioner<RAI>& partitioner_;
/**
* Disables assignment.
......@@ -92,34 +102,44 @@ class ForEachFunctor {
template<typename RAI, typename Function>
void ForEachRecursive(RAI first, RAI last, Function unary,
const ExecutionPolicy& policy, size_t block_size) {
const embb::mtapi::ExecutionPolicy& policy, size_t block_size) {
typedef typename std::iterator_traits<RAI>::difference_type difference_type;
difference_type distance = std::distance(first, last);
assert(distance > 0);
if (distance == 0) {
return;
}
unsigned int num_cores = policy.GetCoreCount();
if (num_cores == 0) {
EMBB_THROW(embb::base::ErrorException, "No cores in execution policy");
}
mtapi::Node& node = mtapi::Node::GetInstance();
// Determine actually used block size
if (block_size == 0) {
block_size = (static_cast<size_t>(distance) / node.GetCoreCount());
block_size = (static_cast<size_t>(distance) / num_cores);
if (block_size == 0) {
block_size = 1;
}
}
// Perform check of task number sufficiency
// Check task number sufficiency
if (((distance / block_size) * 2) + 1 > MTAPI_NODE_MAX_TASKS_DEFAULT) {
EMBB_THROW(embb::base::ErrorException, "Not enough MTAPI tasks available "
"to perform the parallel foreach loop");
EMBB_THROW(embb::base::ErrorException,
"Not enough MTAPI tasks available for parallel foreach");
}
ForEachFunctor<RAI, Function> functor(first, last, unary, policy, block_size);
BlockSizePartitioner<RAI> partitioner(first, last, block_size);
ForEachFunctor<RAI, Function> functor(0,
partitioner.Size() - 1,
unary, policy, partitioner);
mtapi::Task task = node.Spawn(mtapi::Action(
base::MakeFunction(functor,
&ForEachFunctor<RAI, Function>::Action),
policy.GetAffinity()), policy.GetPriority());
policy));
task.Wait(MTAPI_INFINITE);
}
template<typename RAI, typename Function>
void ForEachIteratorCheck(RAI first, RAI last, Function unary,
const ExecutionPolicy& policy, size_t block_size,
const embb::mtapi::ExecutionPolicy& policy, size_t block_size,
std::random_access_iterator_tag) {
return ForEachRecursive(first, last, unary, policy, block_size);
}
......@@ -127,8 +147,8 @@ void ForEachIteratorCheck(RAI first, RAI last, Function unary,
} // namespace internal
template<typename RAI, typename Function>
void ForEach(RAI first, RAI last, Function unary, const ExecutionPolicy& policy,
size_t block_size) {
void ForEach(RAI first, const RAI last, Function unary,
const embb::mtapi::ExecutionPolicy& policy, size_t block_size) {
typename std::iterator_traits<RAI>::iterator_category category;
internal::ForEachIteratorCheck(first, last, unary, policy, block_size,
category);
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -71,8 +71,8 @@ const ChunkDescriptor<ForwardIterator>
ForwardIterator last_new = first_new;
if (index == elements_count / chunkSize) {
std::advance(last_new, elements_count % chunkSize);
if (index >= chunks - 1) {
last_new = last;
} else {
std::advance(last_new, chunkSize);
}
......@@ -94,7 +94,7 @@ ChunkPartitioner<ForwardIterator>::ChunkPartitioner(ForwardIterator first,
} else {
// if no concrete chunk size was given, use number of cores...
mtapi::Node& node = mtapi::Node::GetInstance();
size = node.GetCoreCount();
size = node.GetWorkerThreadCount();
}
elements_count = static_cast<size_t>(std::distance(first, last));
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -48,7 +48,7 @@ class QuickSortFunctor {
* Constructs a functor.
*/
QuickSortFunctor(RAI first, RAI last, ComparisonFunction comparison,
const ExecutionPolicy& policy, size_t block_size)
const embb::mtapi::ExecutionPolicy& policy, size_t block_size)
: first_(first), last_(last), comparison_(comparison), policy_(policy),
block_size_(block_size) {
}
......@@ -87,7 +87,7 @@ class QuickSortFunctor {
RAI first_;
RAI last_;
ComparisonFunction comparison_;
const ExecutionPolicy& policy_;
const embb::mtapi::ExecutionPolicy& policy_;
size_t block_size_;
typedef typename std::iterator_traits<RAI>::difference_type Difference;
......@@ -190,12 +190,19 @@ class QuickSortFunctor {
template <typename RAI, typename ComparisonFunction>
void QuickSort(RAI first, RAI last, ComparisonFunction comparison,
const ExecutionPolicy& policy, size_t block_size) {
const embb::mtapi::ExecutionPolicy& policy, size_t block_size) {
embb::mtapi::Node& node = embb::mtapi::Node::GetInstance();
typename std::iterator_traits<RAI>::difference_type distance = last - first;
assert(distance > 0);
typedef typename std::iterator_traits<RAI>::difference_type difference_type;
difference_type distance = std::distance(first, last);
if (distance <= 0) {
return;
}
unsigned int num_cores = policy.GetCoreCount();
if (num_cores == 0) {
EMBB_THROW(embb::base::ErrorException, "No cores in execution policy");
}
if (block_size == 0) {
block_size= (static_cast<size_t>(distance) / node.GetCoreCount());
block_size = (static_cast<size_t>(distance) / num_cores);
if (block_size == 0)
block_size = 1;
}
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -42,47 +42,55 @@ template<typename RAI, typename ReturnType, typename ReductionFunction,
typename TransformationFunction>
class ReduceFunctor {
public:
ReduceFunctor(RAI first, RAI last, ReturnType neutral,
ReduceFunctor(size_t chunk_first, size_t chunk_last,
ReturnType neutral,
ReductionFunction reduction,
TransformationFunction transformation,
const ExecutionPolicy &policy, size_t block_size,
const embb::mtapi::ExecutionPolicy& policy,
const BlockSizePartitioner<RAI>& partitioner,
ReturnType& result)
:
first_(first), last_(last), neutral_(neutral), reduction_(reduction),
transformation_(transformation), policy_(policy),
block_size_(block_size), result_(result) {
: chunk_first_(chunk_first), chunk_last_(chunk_last), neutral_(neutral),
reduction_(reduction), transformation_(transformation), policy_(policy),
partitioner_(partitioner), result_(result) {
}
void Action(mtapi::TaskContext&) {
if (first_ == last_) {
return;
}
size_t distance = static_cast<size_t>(std::distance(first_, last_));
if (distance <= block_size_) { // leaf case -> do work
if (chunk_first_ == chunk_last_) {
// Leaf case, recursed to single chunk. Do work on chunk:
ChunkDescriptor<RAI> chunk = partitioner_[chunk_first_];
RAI first = chunk.GetFirst();
RAI last = chunk.GetLast();
ReturnType result(neutral_);
for (RAI iter = first_; iter != last_; ++iter) {
result = reduction_(result, transformation_(*iter));
for (RAI it = first; it != last; ++it) {
result = reduction_(result, transformation_(*it));
}
result_ = result;
} else { // recurse further
internal::ChunkPartitioner<RAI> partitioner(first_, last_, 2);
} else {
// Recurse further:
size_t chunk_split_index = (chunk_first_ + chunk_last_) / 2;
// Split chunks into left / right branches:
ReturnType result_l(neutral_);
ReturnType result_r(neutral_);
ReduceFunctor functor_l(partitioner[0].GetFirst(),
partitioner[0].GetLast(),
neutral_, reduction_, transformation_, policy_,
block_size_, result_l);
ReduceFunctor functor_r(partitioner[1].GetFirst(),
partitioner[1].GetLast(),
neutral_, reduction_, transformation_, policy_,
block_size_, result_r);
mtapi::Node& node = mtapi::Node::GetInstance();
mtapi::Task task_l = node.Spawn(mtapi::Action(base::MakeFunction(
functor_l, &ReduceFunctor::Action), policy_.GetAffinity()),
policy_.GetPriority());
mtapi::Task task_r = node.Spawn(mtapi::Action(base::MakeFunction(
functor_r, &ReduceFunctor::Action), policy_.GetAffinity()),
policy_.GetPriority());
self_t functor_l(chunk_first_,
chunk_split_index,
neutral_, reduction_, transformation_, policy_,
partitioner_,
result_l);
self_t functor_r(chunk_split_index + 1,
chunk_last_,
neutral_, reduction_, transformation_, policy_,
partitioner_,
result_r);
mtapi::Task task_l = mtapi::Node::GetInstance().Spawn(
mtapi::Action(
base::MakeFunction(
functor_l, &self_t::Action),
policy_));
mtapi::Task task_r = mtapi::Node::GetInstance().Spawn(
mtapi::Action(
base::MakeFunction(
functor_r, &self_t::Action),
policy_));
task_l.Wait(MTAPI_INFINITE);
task_r.Wait(MTAPI_INFINITE);
result_ = reduction_(result_l, result_r);
......@@ -90,15 +98,23 @@ class ReduceFunctor {
}
private:
RAI first_;
RAI last_;
typedef ReduceFunctor<RAI, ReturnType,
ReductionFunction,
TransformationFunction> self_t;
private:
size_t chunk_first_;
size_t chunk_last_;
ReturnType neutral_;
ReductionFunction reduction_;
TransformationFunction transformation_;
const ExecutionPolicy& policy_;
size_t block_size_;
const embb::mtapi::ExecutionPolicy& policy_;
const BlockSizePartitioner<RAI>& partitioner_;
ReturnType& result_;
/**
* Disables assignment and copy-construction.
*/
ReduceFunctor& operator=(const ReduceFunctor&);
ReduceFunctor(const ReduceFunctor&);
};
......@@ -108,31 +124,45 @@ template<typename RAI, typename ReturnType, typename ReductionFunction,
ReturnType ReduceRecursive(RAI first, RAI last, ReturnType neutral,
ReductionFunction reduction,
TransformationFunction transformation,
const ExecutionPolicy& policy, size_t block_size) {
const embb::mtapi::ExecutionPolicy& policy,
size_t block_size) {
typedef typename std::iterator_traits<RAI>::difference_type difference_type;
difference_type distance = std::distance(first, last);
assert(distance > 0);
if (distance == 0) {
EMBB_THROW(embb::base::ErrorException, "Distance for Reduce is 0");
}
unsigned int num_cores = policy.GetCoreCount();
if (num_cores == 0) {
EMBB_THROW(embb::base::ErrorException, "No cores in execution policy");
}
mtapi::Node& node = mtapi::Node::GetInstance();
size_t used_block_size = block_size;
if (used_block_size == 0) {
used_block_size = static_cast<size_t>(distance) / node.GetCoreCount();
if (used_block_size == 0) used_block_size = 1;
// Determine actually used block size
if (block_size == 0) {
block_size = (static_cast<size_t>(distance) / num_cores);
if (block_size == 0) {
block_size = 1;
}
}
if (((distance / used_block_size) * 2) + 1 > MTAPI_NODE_MAX_TASKS_DEFAULT) {
// Perform check of task number sufficiency
if (((distance / block_size) * 2) + 1 > MTAPI_NODE_MAX_TASKS_DEFAULT) {
EMBB_THROW(embb::base::ErrorException,
"Number of computation tasks required in reduction would "
"exceed MTAPI maximum number of tasks");
}
ReturnType result = neutral;
typedef ReduceFunctor<RAI, ReturnType, ReductionFunction,
TransformationFunction> Functor;
Functor functor(first, last, neutral, reduction, transformation, policy,
used_block_size, result);
mtapi::Task task = node.Spawn(mtapi::Action(base::MakeFunction(
functor, &Functor::Action), policy.GetAffinity()), policy.GetPriority());
BlockSizePartitioner<RAI> partitioner(first, last, block_size);
ReturnType result = neutral;
Functor functor(0,
partitioner.Size() - 1,
neutral,
reduction, transformation,
policy,
partitioner,
result);
mtapi::Task task = node.Spawn(
mtapi::Action(base::MakeFunction(
functor, &Functor::Action), policy));
task.Wait(MTAPI_INFINITE);
return result;
}
......@@ -142,7 +172,8 @@ template<typename RAI, typename TransformationFunction,
ReturnType ReduceIteratorCheck(RAI first, RAI last, ReductionFunction reduction,
TransformationFunction transformation,
ReturnType neutral,
const ExecutionPolicy& policy, size_t block_size,
const embb::mtapi::ExecutionPolicy& policy,
size_t block_size,
std::random_access_iterator_tag) {
return ReduceRecursive(first, last, neutral, reduction, transformation,
policy, block_size);
......@@ -155,7 +186,8 @@ template<typename RAI, typename ReturnType, typename ReductionFunction,
ReturnType Reduce(RAI first, RAI last, ReturnType neutral,
ReductionFunction reduction,
TransformationFunction transformation,
const ExecutionPolicy& policy, size_t block_size) {
const embb::mtapi::ExecutionPolicy& policy,
size_t block_size) {
typename std::iterator_traits<RAI>::iterator_category category;
return internal::ReduceIteratorCheck(first, last, reduction, transformation,
neutral, policy, block_size, category);
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -28,7 +28,7 @@
#define EMBB_ALGORITHMS_MERGE_SORT_H_
#include <functional>
#include <embb/algorithms/execution_policy.h>
#include <embb/mtapi/execution_policy.h>
#include <embb/base/memory_allocation.h>
namespace embb {
......@@ -59,7 +59,7 @@ namespace algorithms {
* modified by another thread while the algorithm is executed.
* \note No guarantee is given on the execution order of the comparison
operations.
* \see ExecutionPolicy, MergeSort()
* \see embb::mtapi::ExecutionPolicy, MergeSort()
* \tparam RAI Random access iterator
* \tparam ComparisonFunction Binary predicate with both arguments of type
* <tt>std::iterator_traits<RAI>::value_type</tt>.
......@@ -77,8 +77,8 @@ void MergeSortAllocate(
\c a appears before an element \c b in the sorted range if
<tt>comparison(a, b) == true</tt>. The default value uses the
less-than relation. */
const ExecutionPolicy& policy = ExecutionPolicy(),
/**< [IN] ExecutionPolicy for the merge sort algorithm */
const embb::mtapi::ExecutionPolicy& policy = embb::mtapi::ExecutionPolicy(),
/**< [IN] embb::mtapi::ExecutionPolicy for the merge sort algorithm */
size_t block_size = 0
/**< [IN] Lower bound for partitioning the range of elements into blocks that
are sorted in parallel. Partitioning of a block stops if its size
......@@ -105,7 +105,7 @@ void MergeSortAllocate(
* modified by another thread while the algorithm is executed.
* \note No guarantee is given on the execution order of the comparison
* operations.
* \see ExecutionPolicy, MergeSortAllocate()
* \see embb::mtapi::ExecutionPolicy, MergeSortAllocate()
* \tparam RAI Random access iterator
* \tparam RAITemp Random access iterator for temporary memory. Has to have the
* same value type as RAI.
......@@ -127,8 +127,8 @@ void MergeSort(
\c a appears before an element \c b in the sorted range if
<tt>comparison(a, b) == true</tt>. The default value uses the
less-than relation. */
const ExecutionPolicy& policy = ExecutionPolicy(),
/**< [IN] ExecutionPolicy for the merge sort algorithm */
const embb::mtapi::ExecutionPolicy& policy = embb::mtapi::ExecutionPolicy(),
/**< [IN] embb::mtapi::ExecutionPolicy for the merge sort algorithm */
size_t block_size = 0
/**< [IN] Lower bound for partitioning the range of elements into blocks that
are sorted in parallel. Partitioning of a block stops if its size
......@@ -141,28 +141,49 @@ void MergeSort(
#else // DOXYGEN
/**
* Overload of above described Doxygen dummy with less arguments.
* Overload of above described Doxygen dummy.
*/
template<typename RAI>
template<typename RAI, typename RAITemp, typename ComparisonFunction>
void MergeSort(
RAI first,
RAI last,
RAITemp temporary_first,
ComparisonFunction comparison,
const embb::mtapi::ExecutionPolicy& policy,
size_t block_size
);
/**
* Overload of above described Doxygen dummy.
*/
template<typename RAI, typename ComparisonFunction>
void MergeSortAllocate(
RAI first,
RAI last
RAI last,
ComparisonFunction comparison,
const embb::mtapi::ExecutionPolicy& policy,
size_t block_size
) {
MergeSortAllocate(first, last,
std::less<typename std::iterator_traits<RAI>::value_type>(),
ExecutionPolicy(), 0);
typedef base::Allocation Alloc;
typename std::iterator_traits<RAI>::difference_type distance = last - first;
typedef typename std::iterator_traits<RAI>::value_type value_type;
value_type* temporary = static_cast<value_type*>(
Alloc::Allocate(distance * sizeof(value_type)));
MergeSort(first, last, temporary, comparison, policy, block_size);
Alloc::Free(temporary);
}
/**
* Overload of above described Doxygen dummy with less arguments.
*/
template<typename RAI, typename ComparisonFunction>
template<typename RAI>
void MergeSortAllocate(
RAI first,
RAI last,
ComparisonFunction comparison
RAI last
) {
MergeSortAllocate(first, last, comparison, ExecutionPolicy(), 0);
MergeSortAllocate(first, last,
std::less<typename std::iterator_traits<RAI>::value_type>(),
embb::mtapi::ExecutionPolicy(), 0);
}
/**
......@@ -172,30 +193,22 @@ template<typename RAI, typename ComparisonFunction>
void MergeSortAllocate(
RAI first,
RAI last,
ComparisonFunction comparison,
const ExecutionPolicy& policy
ComparisonFunction comparison
) {
MergeSortAllocate(first, last, comparison, policy, 0);
MergeSortAllocate(first, last, comparison, embb::mtapi::ExecutionPolicy(), 0);
}
/**
* Overload of above described Doxygen dummy.
* Overload of above described Doxygen dummy with less arguments.
*/
template<typename RAI, typename ComparisonFunction>
void MergeSortAllocate(
RAI first,
RAI last,
ComparisonFunction comparison,
const ExecutionPolicy& policy,
size_t block_size
const embb::mtapi::ExecutionPolicy& policy
) {
typedef base::Allocation Alloc;
typename std::iterator_traits<RAI>::difference_type distance = last - first;
typedef typename std::iterator_traits<RAI>::value_type value_type;
value_type* temporary = static_cast<value_type*>(
Alloc::Allocate(distance * sizeof(value_type)));
MergeSort(first, last, temporary, comparison, policy, block_size);
Alloc::Free(temporary);
MergeSortAllocate(first, last, comparison, policy, 0);
}
/**
......@@ -209,7 +222,7 @@ void MergeSort(
) {
MergeSort(first, last, temporary_first,
std::less<typename std::iterator_traits<RAI>::value_type>(),
ExecutionPolicy(), 0);
embb::mtapi::ExecutionPolicy(), 0);
}
/**
......@@ -222,7 +235,8 @@ void MergeSort(
RAITemp temporary_first,
ComparisonFunction comparison
) {
MergeSort(first, last, temporary_first, comparison, ExecutionPolicy(), 0);
MergeSort(first, last, temporary_first, comparison,
embb::mtapi::ExecutionPolicy(), 0);
}
/**
......@@ -234,24 +248,11 @@ void MergeSort(
RAI last,
RAITemp temporary_first,
ComparisonFunction comparison,
const ExecutionPolicy& policy
const embb::mtapi::ExecutionPolicy& policy
) {
MergeSort(first, last, temporary_first, comparison, policy, 0);
}
/**
* Overload of above described Doxygen dummy.
*/
template<typename RAI, typename RAITemp, typename ComparisonFunction>
void MergeSort(
const ExecutionPolicy& policy,
RAI first,
RAI last,
RAITemp temporary_first,
ComparisonFunction comparison,
size_t block_size
);
#endif // else DOXYGEN
/**
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -28,7 +28,7 @@
#define EMBB_ALGORITHMS_QUICK_SORT_H_
#include <functional>
#include <embb/algorithms/execution_policy.h>
#include <embb/mtapi/execution_policy.h>
namespace embb {
namespace algorithms {
......@@ -54,7 +54,7 @@ namespace algorithms {
* modified by another thread while the algorithm is executed.
* \note No guarantee is given on the execution order of the comparison
* operations.
* \see ExecutionPolicy, MergeSort()
* \see embb::mtapi::ExecutionPolicy, MergeSort()
* \tparam RAI Random access iterator
* \tparam ComparisonFunction Binary predicate with both arguments of type
* <tt>std::iterator_traits<RAI>::value_type</tt>.
......@@ -72,8 +72,8 @@ void QuickSort(
\c a appears before an element \c b in the sorted range if
<tt>comparison(a, b) == true</tt>. The default value uses the
less-than relation. */
const ExecutionPolicy& policy = ExecutionPolicy(),
/**< [IN] ExecutionPolicy for the quick sort algorithm */
const embb::mtapi::ExecutionPolicy& policy = embb::mtapi::ExecutionPolicy(),
/**< [IN] embb::mtapi::ExecutionPolicy for the quick sort algorithm */
size_t block_size = 0
/**< [IN] Lower bound for partitioning the range of elements into blocks that
are sorted in parallel. Partitioning of a block stops if its size
......@@ -88,6 +88,18 @@ void QuickSort(
#else // DOXYGEN
/**
* Overload of above described Doxygen dummy.
*/
template <typename RAI, typename ComparisonFunction>
void QuickSort(
RAI first,
RAI last,
ComparisonFunction comparison,
const embb::mtapi::ExecutionPolicy& policy,
size_t block_size
);
/**
* Overload of above described Doxygen dummy with less arguments.
*/
template <typename RAI>
......@@ -97,7 +109,7 @@ void QuickSort(
) {
QuickSort(first, last,
std::less<typename std::iterator_traits<RAI>::value_type>(),
ExecutionPolicy(), 0);
embb::mtapi::ExecutionPolicy(), 0);
}
/**
......@@ -109,7 +121,7 @@ void QuickSort(
RAI last,
ComparisonFunction comparison
) {
QuickSort(first, last, comparison, ExecutionPolicy(), 0);
QuickSort(first, last, comparison, embb::mtapi::ExecutionPolicy(), 0);
}
/**
......@@ -120,23 +132,11 @@ void QuickSort(
RAI first,
RAI last,
ComparisonFunction comparison,
const ExecutionPolicy& policy
const embb::mtapi::ExecutionPolicy& policy
) {
QuickSort(first, last, comparison, policy, 0);
}
/**
* Overload of above described Doxygen dummy.
*/
template <typename RAI, typename ComparisonFunction>
void QuickSort(
RAI first,
RAI last,
ComparisonFunction comparison,
const ExecutionPolicy& policy,
size_t block_size
);
#endif // else DOXYGEN
/**
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -27,7 +27,7 @@
#ifndef EMBB_ALGORITHMS_REDUCE_H_
#define EMBB_ALGORITHMS_REDUCE_H_
#include <embb/algorithms/execution_policy.h>
#include <embb/mtapi/execution_policy.h>
#include <embb/algorithms/identity.h>
namespace embb {
......@@ -64,14 +64,14 @@ namespace algorithms {
* associative, i.e., <tt>reduction(x, reduction(y, z)) ==
* reduction(reduction(x, y), z))</tt> for all \c x, \c y, \c z of type
* \c ReturnType.
* \see ExecutionPolicy, ZipIterator, Identity
* \see embb::mtapi::ExecutionPolicy, ZipIterator, Identity
* \tparam RAI Random access iterator
* \tparam ReturnType Type of result of reduction operation, deduced from
* \c neutral
* \tparam ReductionFunction Binary reduction function with signature
* \tparam ReductionFunction Binary reduction function object with signature
* <tt>ReturnType ReductionFunction(ReturnType, ReturnType)</tt>.
* \tparam TransformationFunction Unary transformation function with signature
* <tt>ReturnType TransformationFunction(typename
* \tparam TransformationFunction Unary transformation function object with
* signature <tt>ReturnType TransformationFunction(typename
* std::iterator_traits<RAI>::value_type)</tt>
*/
template<typename RAI, typename ReturnType, typename ReductionFunction,
......@@ -89,8 +89,8 @@ ReturnType Reduce(
TransformationFunction transformation = Identity(),
/**< [IN] Transforms the elements of the range before the reduction operation
is applied */
const ExecutionPolicy& policy = ExecutionPolicy(),
/**< [IN] ExecutionPolicy for the reduction computation */
const embb::mtapi::ExecutionPolicy& policy = embb::mtapi::ExecutionPolicy(),
/**< [IN] embb::mtapi::ExecutionPolicy for the reduction computation */
size_t block_size = 0
/**< [IN] Lower bound for partitioning the range of elements into blocks that
are treated in parallel. Partitioning of a block stops if its size
......@@ -103,6 +103,21 @@ ReturnType Reduce(
#else // DOXYGEN
/**
* Overload of above described Doxygen dummy.
*/
template<typename RAI, typename ReturnType, typename ReductionFunction,
typename TransformationFunction>
ReturnType Reduce(
RAI first,
RAI last,
ReturnType neutral,
ReductionFunction reduction,
TransformationFunction transformation,
const embb::mtapi::ExecutionPolicy& policy,
size_t block_size
);
/**
* Overload of above described Doxygen dummy with less arguments.
*/
template<typename RAI, typename ReturnType, typename ReductionFunction>
......@@ -112,8 +127,8 @@ ReturnType Reduce(
ReturnType neutral,
ReductionFunction reduction
) {
return Reduce(first, last, neutral, reduction, Identity(), ExecutionPolicy(),
0);
return Reduce(first, last, neutral, reduction, Identity(),
embb::mtapi::ExecutionPolicy(), 0);
}
/**
......@@ -129,7 +144,7 @@ ReturnType Reduce(
TransformationFunction transformation
) {
return Reduce(first, last, neutral, reduction, transformation,
ExecutionPolicy(), 0);
embb::mtapi::ExecutionPolicy(), 0);
}
/**
......@@ -143,26 +158,11 @@ ReturnType Reduce(
ReturnType neutral,
ReductionFunction reduction,
TransformationFunction transformation,
const ExecutionPolicy& policy
const embb::mtapi::ExecutionPolicy& policy
) {
return Reduce(first, last, neutral, reduction, transformation, policy, 0);
}
/**
* Overload of above described Doxygen dummy.
*/
template<typename RAI, typename ReturnType, typename ReductionFunction,
typename TransformationFunction>
ReturnType Reduce(
RAI first,
RAI last,
ReturnType neutral,
ReductionFunction reduction,
TransformationFunction transformation,
const ExecutionPolicy& policy,
size_t block_size
);
#endif // else DOXYGEN
/**
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -27,7 +27,7 @@
#ifndef EMBB_ALGORITHMS_SCAN_H_
#define EMBB_ALGORITHMS_SCAN_H_
#include <embb/algorithms/execution_policy.h>
#include <embb/mtapi/execution_policy.h>
#include <embb/algorithms/identity.h>
namespace embb {
......@@ -66,15 +66,15 @@ namespace algorithms {
* associative, i.e., <tt>reduction(x, reduction(y, z)) ==
* reduction(reduction(x, y), z))</tt> for all \c x, \c y, \c z of type
* \c ReturnType.
* \see ExecutionPolicy, Identity, ZipIterator
* \see embb::mtapi::ExecutionPolicy, Identity, ZipIterator
* \tparam RAIIn Random access iterator type of input range
* \tparam RAIOut Random access iterator type of output range
* \tparam ReturnType Type of output elements of scan operation, deduced from
* \c neutral
* \tparam ScanFunction Binary scan function with signature
* \tparam ScanFunction Binary scan function object with signature
* <tt>ReturnType ScanFunction(ReturnType, ReturnType)</tt>
* \tparam TransformationFunction Unary transformation function with signature
* <tt>ReturnType TransformationFunction(typename
* \tparam TransformationFunction Unary transformation function object with
* signature <tt>ReturnType TransformationFunction(typename
* std::iterator_traits<RAIIn>::value_type)</tt>.
*/
template<typename RAIIn, typename RAIOut, typename ReturnType,
......@@ -96,8 +96,8 @@ void Scan(
TransformationFunction transformation = Identity(),
/**< [IN] Transforms the elements of the input range before the scan operation
is applied */
const ExecutionPolicy& policy = ExecutionPolicy(),
/**< [IN] ExecutionPolicy for the scan computation */
const embb::mtapi::ExecutionPolicy& policy = embb::mtapi::ExecutionPolicy(),
/**< [IN] embb::mtapi::ExecutionPolicy for the scan computation */
size_t block_size = 0
/**< [IN] Lower bound for partitioning the range of elements into blocks that
are treated in parallel. Partitioning of a block stops if its size
......@@ -110,36 +110,35 @@ void Scan(
#else // DOXYGEN
/**
* Overload of above described Doxygen dummy with less arguments.
* Overload of above described Doxygen dummy.
*/
template<typename RAIIn, typename RAIOut, typename ReturnType,
typename ScanFunction>
typename ScanFunction, typename TransformationFunction>
void Scan(
RAIIn first,
RAIIn last,
RAIOut output_iterator,
ReturnType neutral,
ScanFunction scan
) {
Scan(first, last, output_iterator, neutral, scan, Identity(),
ExecutionPolicy(), 0);
}
ScanFunction scan,
TransformationFunction transformation,
const embb::mtapi::ExecutionPolicy& policy,
size_t block_size
);
/**
* Overload of above described Doxygen dummy with less arguments.
*/
template<typename RAIIn, typename RAIOut, typename ReturnType,
typename ScanFunction, typename TransformationFunction>
typename ScanFunction>
void Scan(
RAIIn first,
RAIIn last,
RAIOut output_iterator,
ReturnType neutral,
ScanFunction scan,
TransformationFunction transformation
ScanFunction scan
) {
Scan(first, last, output_iterator, neutral, scan, transformation,
ExecutionPolicy(), 0);
Scan(first, last, output_iterator, neutral, scan, Identity(),
embb::mtapi::ExecutionPolicy(), 0);
}
/**
......@@ -153,14 +152,14 @@ void Scan(
RAIOut output_iterator,
ReturnType neutral,
ScanFunction scan,
TransformationFunction transformation,
const ExecutionPolicy& policy
TransformationFunction transformation
) {
Scan(first, last, output_iterator, neutral, scan, transformation, policy, 0);
Scan(first, last, output_iterator, neutral, scan, transformation,
embb::mtapi::ExecutionPolicy(), 0);
}
/**
* Overload of above described Doxygen dummy.
* Overload of above described Doxygen dummy with less arguments.
*/
template<typename RAIIn, typename RAIOut, typename ReturnType,
typename ScanFunction, typename TransformationFunction>
......@@ -171,9 +170,10 @@ void Scan(
ReturnType neutral,
ScanFunction scan,
TransformationFunction transformation,
const ExecutionPolicy& policy,
size_t block_size
);
const embb::mtapi::ExecutionPolicy& policy
) {
Scan(first, last, output_iterator, neutral, scan, transformation, policy, 0);
}
#endif // else DOXYGEN
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -26,7 +26,7 @@
#include <count_test.h>
#include <embb/algorithms/count.h>
#include <embb/algorithms/execution_policy.h>
#include <embb/mtapi/execution_policy.h>
#include <deque>
#include <vector>
#include <functional>
......@@ -59,8 +59,8 @@ CountTest::CountTest() {
void CountTest::TestDataStructures() {
using embb::algorithms::Count;
const int size =10;
int array[] = {10, 20, 30, 30, 20, 10, 10, 20, 20, 20};
const int size = 10;
int array[] = { 10, 20, 30, 30, 20, 10, 10, 20, 20, 20 };
std::vector<int> vector(array, array + size);
std::deque<int> deque(array, array + size);
const std::vector<int> const_vector(array, array + size);
......@@ -73,8 +73,8 @@ void CountTest::TestDataStructures() {
void CountTest::TestCountIf() {
using embb::algorithms::CountIf;
const int size =10;
int array[] = {10, 21, 30, 31, 20, 11, 10, 21, 20, 20};
const int size = 10;
int array[] = { 10, 21, 30, 31, 20, 11, 10, 21, 20, 20 };
PT_EXPECT_EQ(CountIf(array, array + size, IsEven()), 6);
PT_EXPECT_EQ(CountIf(array, array + size, &IsEvenFunction), 6);
}
......@@ -122,14 +122,12 @@ void CountTest::TestBlockSizes() {
void CountTest::TestPolicy() {
using embb::algorithms::Count;
using embb::algorithms::ExecutionPolicy;
using embb::mtapi::ExecutionPolicy;
int a[] = { 10, 20, 30, 30, 20, 10, 10, 20, 20, 20 };
std::vector<int> vector(a, a + (sizeof a / sizeof a[0]));
PT_EXPECT_EQ(Count(vector.begin(), vector.end(), 10, ExecutionPolicy()), 3);
PT_EXPECT_EQ(Count(vector.begin(), vector.end(), 10, ExecutionPolicy(true)),
3);
PT_EXPECT_EQ(Count(vector.begin(), vector.end(), 10, ExecutionPolicy(false)),
3);
PT_EXPECT_EQ(Count(vector.begin(), vector.end(), 10,
ExecutionPolicy(true, 1)), 3);
}
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -26,7 +26,7 @@
#include <for_each_test.h>
#include <embb/algorithms/for_each.h>
#include <embb/algorithms/execution_policy.h>
#include <embb/mtapi/execution_policy.h>
#include <vector>
#include <deque>
#include <sstream>
......@@ -166,7 +166,7 @@ void ForEachTest::TestRanges() {
void ForEachTest::TestBlockSizes() {
using embb::algorithms::ForEach;
using embb::algorithms::ExecutionPolicy;
using embb::mtapi::ExecutionPolicy;
size_t count = 4;
std::vector<int> init(count);
std::vector<int> vector(count);
......@@ -186,7 +186,7 @@ void ForEachTest::TestBlockSizes() {
void ForEachTest::TestPolicy() {
using embb::algorithms::ForEach;
using embb::algorithms::ExecutionPolicy;
using embb::mtapi::ExecutionPolicy;
size_t count = 4;
std::vector<int> init(count);
std::vector<int> vector(count);
......@@ -207,12 +207,6 @@ void ForEachTest::TestPolicy() {
}
vector = init;
ForEach(vector.begin(), vector.end(), Square(), ExecutionPolicy(false));
for (size_t i = 0; i < count; i++) {
PT_EXPECT_EQ(vector[i], init[i]*init[i]);
}
vector = init;
ForEach(vector.begin(), vector.end(), Square(), ExecutionPolicy(true, 1));
for (size_t i = 0; i < count; i++) {
PT_EXPECT_EQ(vector[i], init[i]*init[i]);
......@@ -221,7 +215,7 @@ void ForEachTest::TestPolicy() {
void ForEachTest::StressTest() {
using embb::algorithms::ForEach;
using embb::algorithms::ExecutionPolicy;
using embb::mtapi::ExecutionPolicy;
size_t count = embb::mtapi::Node::GetInstance().GetCoreCount() *10;
std::vector<int> large_vector(count);
for (size_t i = 0; i < count; i++) {
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -67,6 +67,7 @@ int compute1_() {
PT_MAIN("Algorithms") {
embb::mtapi::Node::Initialize(THIS_DOMAIN_ID, THIS_NODE_ID);
PT_RUN(PartitionerTest);
PT_RUN(ForEachTest);
PT_RUN(ReduceTest);
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -26,7 +26,7 @@
#include <merge_sort_test.h>
#include <embb/algorithms/merge_sort.h>
#include <embb/algorithms/execution_policy.h>
#include <embb/mtapi/execution_policy.h>
#include <vector>
#include <deque>
#include <sstream>
......@@ -50,7 +50,7 @@ MergeSortTest::MergeSortTest() {
void MergeSortTest::TestDataStructures() {
using embb::algorithms::MergeSortAllocate;
using embb::algorithms::ExecutionPolicy;
using embb::mtapi::ExecutionPolicy;
int array[kCountSize];
std::vector<int> vector(kCountSize);
std::deque<int> deque(kCountSize);
......@@ -75,7 +75,7 @@ void MergeSortTest::TestDataStructures() {
void MergeSortTest::TestFunctionPointers() {
using embb::algorithms::MergeSortAllocate;
using embb::algorithms::ExecutionPolicy;
using embb::mtapi::ExecutionPolicy;
std::vector<int> vector(kCountSize);
for (size_t i = kCountSize - 1; i > 0; i--) {
......@@ -181,7 +181,7 @@ void MergeSortTest::TestRanges() {
void MergeSortTest::TestPolicy() {
using embb::algorithms::MergeSortAllocate;
using embb::algorithms::ExecutionPolicy;
using embb::mtapi::ExecutionPolicy;
size_t count = 4;
std::vector<int> init(count);
std::vector<int> vector(count);
......@@ -208,13 +208,6 @@ void MergeSortTest::TestPolicy() {
vector = init;
MergeSortAllocate(vector.begin(), vector.end(), std::less<int>(),
ExecutionPolicy(false));
for (size_t i = 0; i < count; i++) {
PT_EXPECT_EQ(vector_copy[i], vector[i]);
}
vector = init;
MergeSortAllocate(vector.begin(), vector.end(), std::less<int>(),
ExecutionPolicy(true, 1));
for (size_t i = 0; i < count; i++) {
PT_EXPECT_EQ(vector_copy[i], vector[i]);
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -26,7 +26,7 @@
#include <quick_sort_test.h>
#include <embb/algorithms/quick_sort.h>
#include <embb/algorithms/execution_policy.h>
#include <embb/mtapi/execution_policy.h>
#include <vector>
#include <deque>
#include <sstream>
......@@ -54,7 +54,7 @@ QuickSortTest::QuickSortTest() {
void QuickSortTest::TestDataStructures() {
using embb::algorithms::QuickSort;
using embb::algorithms::ExecutionPolicy;
using embb::mtapi::ExecutionPolicy;
int array[kCountSize];
std::vector<int> vector(kCountSize);
......@@ -163,7 +163,7 @@ void QuickSortTest::TestRanges() {
void QuickSortTest::TestBlockSizes() {
using embb::algorithms::QuickSort;
using embb::algorithms::ExecutionPolicy;
using embb::mtapi::ExecutionPolicy;
size_t count = 4;
std::vector<int> init(count);
......@@ -187,7 +187,7 @@ void QuickSortTest::TestBlockSizes() {
void QuickSortTest::TestPolicy() {
using embb::algorithms::QuickSort;
using embb::algorithms::ExecutionPolicy;
using embb::mtapi::ExecutionPolicy;
size_t count = 4;
std::vector<int> init(count);
std::vector<int> vector(count);
......@@ -214,13 +214,6 @@ void QuickSortTest::TestPolicy() {
vector = init;
QuickSort(vector.begin(), vector.end(), std::greater<int>(),
ExecutionPolicy(false));
for (size_t i = 0; i < count; i++) {
PT_EXPECT_EQ(vector_copy[i], vector[i]);
}
vector = init;
QuickSort(vector.begin(), vector.end(), std::greater<int>(),
ExecutionPolicy(true, 1));
for (size_t i = 0; i < count; i++) {
PT_EXPECT_EQ(vector_copy[i], vector[i]);
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -26,7 +26,7 @@
#include <reduce_test.h>
#include <embb/algorithms/reduce.h>
#include <embb/algorithms/execution_policy.h>
#include <embb/mtapi/execution_policy.h>
#include <deque>
#include <vector>
#include <functional>
......@@ -163,7 +163,7 @@ void ReduceTest::TestBlockSizes() {
void ReduceTest::TestPolicy() {
using embb::algorithms::Reduce;
using embb::algorithms::ExecutionPolicy;
using embb::mtapi::ExecutionPolicy;
using embb::algorithms::Identity;
size_t count = 4;
int sum = 0;
......@@ -179,15 +179,13 @@ void ReduceTest::TestPolicy() {
Identity(), ExecutionPolicy()), sum);
PT_EXPECT_EQ(Reduce(vector.begin(), vector.end(), 0, std::plus<int>(),
Identity(), ExecutionPolicy(true)), sum);
PT_EXPECT_EQ(Reduce(vector.begin(), vector.end(), 0,
std::plus<int>(), Identity(), ExecutionPolicy(false)), sum);
PT_EXPECT_EQ(Reduce(vector.begin(), vector.end(), 0, std::plus<int>(),
Identity(), ExecutionPolicy(true, 1)), sum);
}
void ReduceTest::StressTest() {
using embb::algorithms::Reduce;
using embb::algorithms::ExecutionPolicy;
using embb::mtapi::ExecutionPolicy;
using embb::algorithms::Identity;
size_t count = embb::mtapi::Node::GetInstance().GetCoreCount() *10;
std::vector<int> large_vector(count);
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -228,7 +228,7 @@ void ScanTest::TestRanges() {
void ScanTest::TestBlockSizes() {
using embb::algorithms::Scan;
using embb::algorithms::ExecutionPolicy;
using embb::mtapi::ExecutionPolicy;
using embb::algorithms::Identity;
size_t count = 4;
std::vector<int> init(count);
......@@ -253,7 +253,7 @@ void ScanTest::TestBlockSizes() {
void ScanTest::TestPolicy() {
using embb::algorithms::Scan;
using embb::algorithms::ExecutionPolicy;
using embb::mtapi::ExecutionPolicy;
using embb::algorithms::Identity;
size_t count = 4;
std::vector<int> init(count);
......@@ -284,15 +284,6 @@ void ScanTest::TestPolicy() {
outputVector = init;
Scan(vector.begin(), vector.end(), outputVector.begin(), 0, std::plus<int>(),
Identity(), ExecutionPolicy(false));
expected = 0;
for (size_t i = 0; i < count; i++) {
expected += vector[i];
PT_EXPECT_EQ(expected, outputVector[i]);
}
outputVector = init;
Scan(vector.begin(), vector.end(), outputVector.begin(), 0, std::plus<int>(),
Identity(), ExecutionPolicy(true, 1));
expected = 0;
for (size_t i = 0; i < count; i++) {
......@@ -304,7 +295,7 @@ void ScanTest::TestPolicy() {
void ScanTest::StressTest() {
using embb::algorithms::Scan;
using embb::algorithms::Identity;
using embb::algorithms::ExecutionPolicy;
using embb::mtapi::ExecutionPolicy;
size_t count = embb::mtapi::Node::GetInstance().GetCoreCount() *10;
std::vector<int> large_vector(count);
std::vector<int> large_vector_output(count);
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -136,7 +136,7 @@ void ZipIteratorTest::TestZipScan() {
Scan(embb::algorithms::Zip(vectorA.begin(), vectorB.begin()),
embb::algorithms::Zip(vectorA.end(), vectorB.end()),
vectorOut.begin(), 0, std::plus<int>(), DotProductFunctor(),
embb::algorithms::ExecutionPolicy(), 0);
embb::mtapi::ExecutionPolicy(), 0);
long sum = 0;
for (size_t i = 0; i < kCountSize; i++) {
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......
......@@ -77,14 +77,14 @@ endif()
# Check headers and create configure file with preprocessor defines
include(CheckIncludeFiles) # Includes module to perform checks
include(CheckSymbolExists) # Includes module to perform symbol checks
check_include_files("sys/sysinfo.h" EMBB_HAS_HEADER_SYSINFO)
check_include_files("sys/types.h;sys/sysctl.h" EMBB_HAS_HEADER_SYSCTL)
check_include_files("sys/param.h;sys/cpuset.h" EMBB_HAS_HEADER_CPUSET)
check_include_files("sys/sysinfo.h" EMBB_PLATFORM_HAS_HEADER_SYSINFO)
check_include_files("sys/types.h;sys/sysctl.h" EMBB_PLATFORM_HAS_HEADER_SYSCTL)
check_include_files("sys/param.h;sys/cpuset.h" EMBB_PLATFORM_HAS_HEADER_CPUSET)
link_libraries(${link_libraries} ${gnu_libs})
set(CMAKE_EXTRA_INCLUDE_FILES sched.h)
check_type_size(cpu_set_t EMBB_HAS_GLIB_CPU)
check_type_size(cpu_set_t EMBB_PLATFORM_HAS_GLIB_CPU)
set(CMAKE_EXTRA_INCLUDE_FILES)
if(DEFINED EMBB_HAS_GLIB_CPU)
if(DEFINED EMBB_PLATFORM_HAS_GLIB_CPU)
add_definitions(-D_GNU_SOURCE) # Needed to activate CPU_ macros
endif()
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -95,7 +95,7 @@
* \ingroup C_BASE_ATOMIC
* \waitfree
*/
EMBB_INLINE void embb_atomic_and_assign_TYPE(
EMBB_PLATFORM_INLINE void embb_atomic_and_assign_TYPE(
embb_atomic_TYPE* variable,
/**< [IN,OUT] Pointer to atomic variable which serves as left-hand side for
the "and" operation and is used to store the result. */
......@@ -120,7 +120,7 @@ EMBB_INLINE void embb_atomic_and_assign_TYPE(
* \ingroup C_BASE_ATOMIC
* \waitfree
*/
EMBB_INLINE int embb_atomic_compare_and_swap_TYPE(
EMBB_PLATFORM_INLINE int embb_atomic_compare_and_swap_TYPE(
embb_atomic_TYPE* variable,
/**< [IN,OUT] Pointer to atomic variable */
TYPE* expected,
......@@ -140,7 +140,7 @@ EMBB_INLINE int embb_atomic_compare_and_swap_TYPE(
* \ingroup C_BASE_ATOMIC
* \waitfree
*/
EMBB_INLINE TYPE embb_atomic_fetch_and_add_TYPE(
EMBB_PLATFORM_INLINE TYPE embb_atomic_fetch_and_add_TYPE(
embb_atomic_TYPE* variable,
/**< [IN,OUT] Pointer to atomic variable*/
TYPE value
......@@ -158,7 +158,7 @@ EMBB_INLINE TYPE embb_atomic_fetch_and_add_TYPE(
* \ingroup C_BASE_ATOMIC
* \waitfree
*/
EMBB_INLINE TYPE embb_atomic_load_TYPE(
EMBB_PLATFORM_INLINE TYPE embb_atomic_load_TYPE(
const embb_atomic_TYPE* variable
/**< [IN] Pointer to atomic variable */
);
......@@ -169,7 +169,7 @@ EMBB_INLINE TYPE embb_atomic_load_TYPE(
* \ingroup C_BASE_ATOMIC
* \waitfree
*/
EMBB_INLINE void embb_atomic_memory_barrier();
EMBB_PLATFORM_INLINE void embb_atomic_memory_barrier();
/**
* Computes the logical "or" of the value stored in \p variable and \c value.
......@@ -182,7 +182,7 @@ EMBB_INLINE void embb_atomic_memory_barrier();
* \ingroup C_BASE_ATOMIC
* \waitfree
*/
EMBB_INLINE void embb_atomic_or_assign_TYPE(
EMBB_PLATFORM_INLINE void embb_atomic_or_assign_TYPE(
embb_atomic_TYPE* variable,
/**< [IN,OUT] Pointer to atomic variable which serves as left-hand side for
the "or" operation and is used to store the result. */
......@@ -199,7 +199,7 @@ EMBB_INLINE void embb_atomic_or_assign_TYPE(
* \ingroup C_BASE_ATOMIC
* \waitfree
*/
EMBB_INLINE void embb_atomic_store_TYPE(
EMBB_PLATFORM_INLINE void embb_atomic_store_TYPE(
embb_atomic_TYPE* variable,
/**< [IN,OUT] Pointer to atomic variable */
int value
......@@ -217,7 +217,7 @@ EMBB_INLINE void embb_atomic_store_TYPE(
* \ingroup C_BASE_ATOMIC
* \waitfree
*/
EMBB_INLINE TYPE embb_atomic_swap_TYPE(
EMBB_PLATFORM_INLINE TYPE embb_atomic_swap_TYPE(
embb_atomic_TYPE* variable,
/**< [IN,OUT] Pointer to atomic variable whose value is swapped */
TYPE value
......@@ -235,7 +235,7 @@ EMBB_INLINE TYPE embb_atomic_swap_TYPE(
* \ingroup C_BASE_ATOMIC
* \waitfree
*/
EMBB_INLINE void embb_atomic_xor_assign_TYPE(
EMBB_PLATFORM_INLINE void embb_atomic_xor_assign_TYPE(
embb_atomic_TYPE* variable,
/**< [IN,OUT] Pointer to atomic variable which serves as left-hand side for
the "xor" operation and is used to store the result. */
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -53,21 +53,21 @@
* BYTE_SIZE is the number of bytes passed to the macro.
*
*/
#ifdef EMBB_ARCH_X86
#ifdef EMBB_PLATFORM_ARCH_X86
#ifdef EMBB_COMPILER_MSVC
#ifdef EMBB_PLATFORM_COMPILER_MSVC
#define EMBB_DEFINE_AND_ASSIGN(EMBB_PARAMETER_SIZE_BYTE, EMBB_ATOMIC_X86_SIZE_SUFFIX) \
extern void __fastcall EMBB_CAT2(embb_internal__atomic_and_assign_, EMBB_PARAMETER_SIZE_BYTE)_asm( \
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* pointer_to_value, EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) value); \
EMBB_INLINE void __fastcall EMBB_CAT2(embb_internal__atomic_and_assign_, EMBB_PARAMETER_SIZE_BYTE)(EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* pointer_to_value, \
EMBB_PLATFORM_INLINE void __fastcall EMBB_CAT2(embb_internal__atomic_and_assign_, EMBB_PARAMETER_SIZE_BYTE)(EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* pointer_to_value, \
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) value) { \
_ReadWriteBarrier(); \
EMBB_CAT2(embb_internal__atomic_and_assign_, EMBB_PARAMETER_SIZE_BYTE)_asm(pointer_to_value, value); \
_ReadWriteBarrier(); \
}
#elif defined(EMBB_COMPILER_GNUC)
#elif defined(EMBB_PLATFORM_COMPILER_GNUC)
#define EMBB_DEFINE_AND_ASSIGN(EMBB_PARAMETER_SIZE_BYTE, EMBB_ATOMIC_X86_SIZE_SUFFIX)\
EMBB_INLINE void EMBB_CAT2(embb_internal__atomic_and_assign_, \
EMBB_PLATFORM_INLINE void EMBB_CAT2(embb_internal__atomic_and_assign_, \
EMBB_PARAMETER_SIZE_BYTE)(EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* pointer_to_value, EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) value) { \
__asm__ __volatile__("lock and" EMBB_ATOMIC_X86_SIZE_SUFFIX " %1, %0" \
: "+m" (*pointer_to_value), "+q" (value) \
......@@ -89,12 +89,12 @@ EMBB_DEFINE_AND_ASSIGN(4, "l")
EMBB_DEFINE_AND_ASSIGN(8, "q")
#endif
#elif defined(EMBB_ARCH_ARM)
#elif defined(EMBB_PLATFORM_ARCH_ARM)
#if defined(EMBB_COMPILER_GNUC)
#if defined(EMBB_PLATFORM_COMPILER_GNUC)
#define EMBB_DEFINE_AND_ASSIGN(EMBB_PARAMETER_SIZE_BYTE, \
EMBB_ATOMIC_ARM_SIZE_SUFFIX) \
EMBB_INLINE \
EMBB_PLATFORM_INLINE \
void EMBB_CAT2(embb_internal__atomic_and_assign_, \
EMBB_PARAMETER_SIZE_BYTE)(\
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) \
......@@ -148,7 +148,7 @@ EMBB_DEFINE_AND_ASSIGN(4, "")
* This generated function is supposed to be called by the user of the lib.
*/
#define EMBB_ATOMIC_INTERNAL_DEFINE_AND_ASSIGN_METHOD(EMBB_ATOMIC_PARAMETER_TYPE_NATIVE, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX, EMBB_ATOMIC_PARAMETER_TYPE_SIZE) \
EMBB_INLINE void EMBB_CAT2(embb_atomic_and_assign_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX)(\
EMBB_PLATFORM_INLINE void EMBB_CAT2(embb_atomic_and_assign_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX)(\
EMBB_CAT2(embb_atomic_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX)* variable, EMBB_ATOMIC_PARAMETER_TYPE_NATIVE value) { \
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_ATOMIC_PARAMETER_TYPE_SIZE) value_pun;\
memcpy(&value_pun, &value, sizeof(EMBB_ATOMIC_PARAMETER_TYPE_NATIVE));\
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -56,7 +56,7 @@ typedef uint64_t EMBB_BASE_BASIC_TYPE_SIZE_8;
#define EMBB_UINTMAX_T_TYPE_SIZE ${EMBB_UINTMAX_T_TYPE_SIZE}
#ifdef EMBB_ARCH_X86_64
#ifdef EMBB_PLATFORM_ARCH_X86_64
# define EMBB_64_BIT_ATOMIC_AVAILABLE_VAL 1
# define EMBB_64_BIT_ATOMIC_AVAILABLE
#else
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -30,7 +30,7 @@
#include <stddef.h>
#include <embb/base/c/internal/macro_helper.h>
#ifdef EMBB_COMPILER_MSVC
#ifdef EMBB_PLATFORM_COMPILER_MSVC
#include <intrin.h>
#endif
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -39,13 +39,13 @@
* See file and_assign.h for a detailed (and operation independent) description
* of the following macro.
*/
#ifdef EMBB_ARCH_X86
#ifdef EMBB_PLATFORM_ARCH_X86
#ifdef EMBB_COMPILER_MSVC
#ifdef EMBB_PLATFORM_COMPILER_MSVC
#define EMBB_DEFINE_COMPARE_AND_SWAP(EMBB_PARAMETER_SIZE_BYTE, EMBB_ATOMIC_X86_SIZE_SUFFIX) \
extern int __fastcall EMBB_CAT2(embb_internal__atomic_compare_and_swap_, EMBB_PARAMETER_SIZE_BYTE)_asm( \
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* pointer_to_value, EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* expected, EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) desired); \
EMBB_INLINE int __fastcall EMBB_CAT2(embb_internal__atomic_compare_and_swap_, EMBB_PARAMETER_SIZE_BYTE)( \
EMBB_PLATFORM_INLINE int __fastcall EMBB_CAT2(embb_internal__atomic_compare_and_swap_, EMBB_PARAMETER_SIZE_BYTE)( \
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* pointer_to_value, EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* expected, EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) desired) { \
int result; \
_ReadWriteBarrier(); \
......@@ -53,9 +53,9 @@
_ReadWriteBarrier(); \
return result; \
}
#elif defined(EMBB_COMPILER_GNUC)
#elif defined(EMBB_PLATFORM_COMPILER_GNUC)
#define EMBB_DEFINE_COMPARE_AND_SWAP(EMBB_PARAMETER_SIZE_BYTE, EMBB_ATOMIC_X86_SIZE_SUFFIX) \
EMBB_INLINE int EMBB_CAT2(embb_internal__atomic_compare_and_swap_, \
EMBB_PLATFORM_INLINE int EMBB_CAT2(embb_internal__atomic_compare_and_swap_, \
EMBB_PARAMETER_SIZE_BYTE)(EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* pointer_to_value, EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* expected, \
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) desired) { \
char result; \
......@@ -82,12 +82,12 @@ EMBB_DEFINE_COMPARE_AND_SWAP(4, "l")
EMBB_DEFINE_COMPARE_AND_SWAP(8, "q")
#endif
#elif defined(EMBB_ARCH_ARM)
#elif defined(EMBB_PLATFORM_ARCH_ARM)
#if defined(EMBB_COMPILER_GNUC)
#if defined(EMBB_PLATFORM_COMPILER_GNUC)
#define EMBB_DEFINE_COMPARE_AND_SWAP(EMBB_PARAMETER_SIZE_BYTE, \
EMBB_ATOMIC_ARM_SIZE_SUFFIX) \
EMBB_INLINE \
EMBB_PLATFORM_INLINE \
int EMBB_CAT2(embb_internal__atomic_compare_and_swap_, \
EMBB_PARAMETER_SIZE_BYTE)(\
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) \
......@@ -134,7 +134,7 @@ EMBB_DEFINE_COMPARE_AND_SWAP(4, "")
* of the following macro.
*/
#define EMBB_ATOMIC_INTERNAL_DEFINE_COMPARE_AND_SWAP_METHOD(EMBB_ATOMIC_PARAMETER_TYPE_NATIVE, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX, EMBB_ATOMIC_PARAMETER_TYPE_SIZE) \
EMBB_INLINE int EMBB_CAT2(embb_atomic_compare_and_swap_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX)(\
EMBB_PLATFORM_INLINE int EMBB_CAT2(embb_atomic_compare_and_swap_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX)(\
EMBB_CAT2(embb_atomic_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX)* variable, EMBB_ATOMIC_PARAMETER_TYPE_NATIVE* expected, EMBB_ATOMIC_PARAMETER_TYPE_NATIVE desired) {\
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_ATOMIC_PARAMETER_TYPE_SIZE) desired_pun;\
memcpy(&desired_pun, &desired, sizeof(EMBB_ATOMIC_PARAMETER_TYPE_NATIVE));\
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -38,13 +38,13 @@
* See file and_assign.h for a detailed (and operation independent) description
* of the following macro.
*/
#ifdef EMBB_ARCH_X86
#ifdef EMBB_PLATFORM_ARCH_X86
#ifdef EMBB_COMPILER_MSVC
#ifdef EMBB_PLATFORM_COMPILER_MSVC
#define EMBB_DEFINE_FETCH_AND_ADD(EMBB_PARAMETER_SIZE_BYTE, EMBB_ATOMIC_X86_SIZE_SUFFIX) \
extern EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) __fastcall EMBB_CAT2(embb_internal__atomic_fetch_and_add_, EMBB_PARAMETER_SIZE_BYTE)_asm( \
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* pointer_to_value, EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) new_value); \
EMBB_INLINE EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) __fastcall EMBB_CAT2(embb_internal__atomic_fetch_and_add_, EMBB_PARAMETER_SIZE_BYTE) (\
EMBB_PLATFORM_INLINE EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) __fastcall EMBB_CAT2(embb_internal__atomic_fetch_and_add_, EMBB_PARAMETER_SIZE_BYTE) (\
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* pointer_to_value, EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) new_value) {\
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) result; \
_ReadWriteBarrier(); \
......@@ -53,9 +53,9 @@
_ReadWriteBarrier(); \
return result; \
}
#elif defined(EMBB_COMPILER_GNUC)
#elif defined(EMBB_PLATFORM_COMPILER_GNUC)
#define EMBB_DEFINE_FETCH_AND_ADD(EMBB_PARAMETER_SIZE_BYTE, EMBB_ATOMIC_X86_SIZE_SUFFIX) \
EMBB_INLINE EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) EMBB_CAT2(embb_internal__atomic_fetch_and_add_, EMBB_PARAMETER_SIZE_BYTE) \
EMBB_PLATFORM_INLINE EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) EMBB_CAT2(embb_internal__atomic_fetch_and_add_, EMBB_PARAMETER_SIZE_BYTE) \
(EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* pointer_to_value, EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) new_value) { \
__asm__ __volatile__ ("lock xadd" EMBB_ATOMIC_X86_SIZE_SUFFIX " %1, %0" \
: "+m" (*pointer_to_value), "+q" (new_value) \
......@@ -78,12 +78,12 @@ EMBB_DEFINE_FETCH_AND_ADD(4, "l")
EMBB_DEFINE_FETCH_AND_ADD(8, "q")
#endif
#elif defined(EMBB_ARCH_ARM)
#elif defined(EMBB_PLATFORM_ARCH_ARM)
#if defined(EMBB_COMPILER_GNUC)
#if defined(EMBB_PLATFORM_COMPILER_GNUC)
#define EMBB_DEFINE_FETCH_AND_ADD(EMBB_PARAMETER_SIZE_BYTE, \
EMBB_ATOMIC_ARM_SIZE_SUFFIX) \
EMBB_INLINE \
EMBB_PLATFORM_INLINE \
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) \
EMBB_CAT2(embb_internal__atomic_fetch_and_add_, \
EMBB_PARAMETER_SIZE_BYTE)(\
......@@ -92,17 +92,17 @@ EMBB_DEFINE_FETCH_AND_ADD(8, "q")
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) \
new_value) { \
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) \
tmp, result; \
tmp1, tmp2, result; \
__asm__ __volatile__ ( \
"dmb\n\t" \
"loop_%=:\n\t" \
"ldrex" EMBB_ATOMIC_ARM_SIZE_SUFFIX " %0, [%2]\n\t" \
"add %1, %0, %3\n\t" \
"strex" EMBB_ATOMIC_ARM_SIZE_SUFFIX " %1, %1, [%2]\n\t" \
"teq %1, #0\n\t" \
"ldrex" EMBB_ATOMIC_ARM_SIZE_SUFFIX " %0, [%3]\n\t" \
"add %1, %0, %4\n\t" \
"strex" EMBB_ATOMIC_ARM_SIZE_SUFFIX " %2, %1, [%3]\n\t" \
"teq %2, #0\n\t" \
"bne loop_%=\n\t" \
"isb" \
: "=&r" (result), "=&r" (tmp) \
: "=&r" (result), "=&r" (tmp1), "=&r" (tmp2) \
: "r" (pointer_to_value), "r" (new_value) \
: "memory", "cc" ); \
return result; \
......@@ -127,7 +127,7 @@ EMBB_DEFINE_FETCH_AND_ADD(4, "")
* of the following macro.
*/
#define EMBB_ATOMIC_INTERNAL_DEFINE_FETCH_AND_ADD_METHOD(EMBB_ATOMIC_PARAMETER_TYPE_NATIVE, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX, EMBB_ATOMIC_PARAMETER_TYPE_SIZE) \
EMBB_INLINE EMBB_ATOMIC_PARAMETER_TYPE_NATIVE EMBB_CAT2(embb_atomic_fetch_and_add_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX)(\
EMBB_PLATFORM_INLINE EMBB_ATOMIC_PARAMETER_TYPE_NATIVE EMBB_CAT2(embb_atomic_fetch_and_add_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX)(\
EMBB_CAT2(embb_atomic_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX)* variable, EMBB_ATOMIC_PARAMETER_TYPE_NATIVE value) { \
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_ATOMIC_PARAMETER_TYPE_SIZE) value_pun; \
memcpy(&value_pun, &value, sizeof(EMBB_ATOMIC_PARAMETER_TYPE_NATIVE)); \
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -39,13 +39,13 @@
* See file and_assign.h for a detailed (and operation independent) description
* of the following macro.
*/
#ifdef EMBB_ARCH_X86
#ifdef EMBB_PLATFORM_ARCH_X86
#ifdef EMBB_COMPILER_MSVC
#ifdef EMBB_PLATFORM_COMPILER_MSVC
#define EMBB_DEFINE_LOAD(EMBB_PARAMETER_SIZE_BYTE, EMBB_ATOMIC_X86_SIZE_SUFFIX) \
extern EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) __fastcall EMBB_CAT2(embb_internal__atomic_load_, EMBB_PARAMETER_SIZE_BYTE)_asm( \
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* pointer_to_value); \
EMBB_INLINE EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) __fastcall EMBB_CAT2(embb_internal__atomic_load_, EMBB_PARAMETER_SIZE_BYTE)(\
EMBB_PLATFORM_INLINE EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) __fastcall EMBB_CAT2(embb_internal__atomic_load_, EMBB_PARAMETER_SIZE_BYTE)(\
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* pointer_to_value) { \
register EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) result; \
_ReadWriteBarrier(); \
......@@ -54,9 +54,9 @@
_ReadWriteBarrier(); \
return result; \
}
#elif defined(EMBB_COMPILER_GNUC)
#elif defined(EMBB_PLATFORM_COMPILER_GNUC)
#define EMBB_DEFINE_LOAD(EMBB_PARAMETER_SIZE_BYTE, EMBB_ATOMIC_X86_SIZE_SUFFIX) \
EMBB_INLINE EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) \
EMBB_PLATFORM_INLINE EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) \
EMBB_CAT2(embb_internal__atomic_load_, EMBB_PARAMETER_SIZE_BYTE)(EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* pointer_to_value) { \
/* no fence required for loads */ \
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) result; \
......@@ -81,11 +81,11 @@ EMBB_DEFINE_LOAD(4, "l")
EMBB_DEFINE_LOAD(8, "q")
#endif
#elif defined(EMBB_ARCH_ARM)
#elif defined(EMBB_PLATFORM_ARCH_ARM)
#if defined(EMBB_COMPILER_GNUC)
#if defined(EMBB_PLATFORM_COMPILER_GNUC)
#define EMBB_DEFINE_LOAD(EMBB_PARAMETER_SIZE_BYTE, EMBB_ATOMIC_ARM_SIZE_SUFFIX) \
EMBB_INLINE \
EMBB_PLATFORM_INLINE \
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) \
EMBB_CAT2(embb_internal__atomic_load_, EMBB_PARAMETER_SIZE_BYTE)(\
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) \
......@@ -118,7 +118,7 @@ EMBB_DEFINE_LOAD(4, "")
* of the following macro.
*/
#define EMBB_ATOMIC_INTERNAL_DEFINE_LOAD_METHOD(EMBB_ATOMIC_PARAMETER_TYPE_NATIVE, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX, EMBB_ATOMIC_PARAMETER_TYPE_SIZE) \
EMBB_INLINE EMBB_ATOMIC_PARAMETER_TYPE_NATIVE EMBB_CAT2(embb_atomic_load_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX)(\
EMBB_PLATFORM_INLINE EMBB_ATOMIC_PARAMETER_TYPE_NATIVE EMBB_CAT2(embb_atomic_load_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX)(\
const EMBB_CAT2(embb_atomic_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX)* variable) { \
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_ATOMIC_PARAMETER_TYPE_SIZE) \
return_val = (EMBB_CAT2(embb_internal__atomic_load_, EMBB_ATOMIC_PARAMETER_TYPE_SIZE)(\
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -31,32 +31,32 @@
#ifndef DOXYGEN
#ifdef EMBB_COMPILER_MSVC
#ifdef EMBB_PLATFORM_COMPILER_MSVC
#include <intrin.h>
#endif
#ifdef EMBB_ARCH_X86
#ifdef EMBB_PLATFORM_ARCH_X86
#ifdef EMBB_COMPILER_MSVC
#ifdef EMBB_PLATFORM_COMPILER_MSVC
extern void __fastcall embb_internal__atomic_memory_barrier_asm();
// Read/write barrier
EMBB_INLINE void __fastcall embb_atomic_memory_barrier() {
EMBB_PLATFORM_INLINE void __fastcall embb_atomic_memory_barrier() {
_ReadWriteBarrier();
embb_internal__atomic_memory_barrier_asm();
_ReadWriteBarrier();
}
#elif defined(EMBB_COMPILER_GNUC)
#elif defined(EMBB_PLATFORM_COMPILER_GNUC)
// Read/write barrier
EMBB_INLINE void embb_atomic_memory_barrier() {
EMBB_PLATFORM_INLINE void embb_atomic_memory_barrier() {
__asm__ __volatile__ ("mfence" : : : "memory");
}
#else
#error "No atomic fetch and store implementation found"
#endif
#elif defined(EMBB_ARCH_ARM)
#elif defined(EMBB_PLATFORM_ARCH_ARM)
EMBB_INLINE void embb_atomic_memory_barrier() {
EMBB_PLATFORM_INLINE void embb_atomic_memory_barrier() {
__asm__ __volatile__ ("dmb" : : : "memory");
}
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -39,22 +39,22 @@
* See file and_assign.h for a detailed (and operation independent) description
* of the following macro.
*/
#ifdef EMBB_ARCH_X86
#ifdef EMBB_PLATFORM_ARCH_X86
#ifdef EMBB_COMPILER_MSVC
#ifdef EMBB_PLATFORM_COMPILER_MSVC
#define EMBB_DEFINE_OR_ASSIGN(EMBB_PARAMETER_SIZE_BYTE, EMBB_ATOMIC_X86_SIZE_SUFFIX) \
extern void __fastcall EMBB_CAT2(embb_internal__atomic_or_assign_, EMBB_PARAMETER_SIZE_BYTE)_asm(\
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* pointer_to_value, EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) value); \
EMBB_INLINE void __fastcall EMBB_CAT2(embb_internal__atomic_or_assign_, EMBB_PARAMETER_SIZE_BYTE)(\
EMBB_PLATFORM_INLINE void __fastcall EMBB_CAT2(embb_internal__atomic_or_assign_, EMBB_PARAMETER_SIZE_BYTE)(\
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* pointer_to_value, \
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) value) { \
_ReadWriteBarrier(); \
EMBB_CAT2(embb_internal__atomic_or_assign_, EMBB_PARAMETER_SIZE_BYTE)_asm(pointer_to_value, value); \
_ReadWriteBarrier(); \
}
#elif defined(EMBB_COMPILER_GNUC)
#elif defined(EMBB_PLATFORM_COMPILER_GNUC)
#define EMBB_DEFINE_OR_ASSIGN(EMBB_PARAMETER_SIZE_BYTE, EMBB_ATOMIC_X86_SIZE_SUFFIX) \
EMBB_INLINE void EMBB_CAT2(embb_internal__atomic_or_assign_, EMBB_PARAMETER_SIZE_BYTE)(\
EMBB_PLATFORM_INLINE void EMBB_CAT2(embb_internal__atomic_or_assign_, EMBB_PARAMETER_SIZE_BYTE)(\
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* pointer_to_value, EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) value) { \
__asm__ __volatile__("lock or" EMBB_ATOMIC_X86_SIZE_SUFFIX " %1, %0" \
: "+m" (*pointer_to_value), "+q" (value) \
......@@ -77,12 +77,12 @@ EMBB_DEFINE_OR_ASSIGN(4, "l")
EMBB_DEFINE_OR_ASSIGN(8, "q")
#endif
#elif defined(EMBB_ARCH_ARM)
#elif defined(EMBB_PLATFORM_ARCH_ARM)
#if defined(EMBB_COMPILER_GNUC)
#if defined(EMBB_PLATFORM_COMPILER_GNUC)
#define EMBB_DEFINE_OR_ASSIGN(EMBB_PARAMETER_SIZE_BYTE, \
EMBB_ATOMIC_ARM_SIZE_SUFFIX) \
EMBB_INLINE \
EMBB_PLATFORM_INLINE \
void EMBB_CAT2(embb_internal__atomic_or_assign_, \
EMBB_PARAMETER_SIZE_BYTE)(\
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) \
......@@ -120,7 +120,7 @@ EMBB_DEFINE_OR_ASSIGN(4, "")
* of the following macro.
*/
#define EMBB_ATOMIC_INTERNAL_DEFINE_OR_ASSIGN_METHOD(EMBB_ATOMIC_PARAMETER_TYPE_NATIVE, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX, EMBB_ATOMIC_PARAMETER_TYPE_SIZE) \
EMBB_INLINE void EMBB_CAT2(embb_atomic_or_assign_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX)(EMBB_CAT2(embb_atomic_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX)* variable, EMBB_ATOMIC_PARAMETER_TYPE_NATIVE value) { \
EMBB_PLATFORM_INLINE void EMBB_CAT2(embb_atomic_or_assign_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX)(EMBB_CAT2(embb_atomic_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX)* variable, EMBB_ATOMIC_PARAMETER_TYPE_NATIVE value) { \
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_ATOMIC_PARAMETER_TYPE_SIZE) value_pun;\
memcpy(&value_pun, &value, sizeof(EMBB_ATOMIC_PARAMETER_TYPE_NATIVE));\
EMBB_CAT2(embb_internal__atomic_or_assign_, EMBB_ATOMIC_PARAMETER_TYPE_SIZE)((EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_ATOMIC_PARAMETER_TYPE_SIZE) volatile *)\
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -39,13 +39,13 @@
* See file and_assign.h for a detailed (and operation independent) description
* of the following macro.
*/
#ifdef EMBB_ARCH_X86
#ifdef EMBB_PLATFORM_ARCH_X86
#ifdef EMBB_COMPILER_MSVC
#ifdef EMBB_PLATFORM_COMPILER_MSVC
#define EMBB_DEFINE_STORE(EMBB_PARAMETER_SIZE_BYTE, EMBB_ATOMIC_X86_SIZE_SUFFIX)\
extern void __fastcall EMBB_CAT2(embb_internal__atomic_store_, EMBB_PARAMETER_SIZE_BYTE)_asm( \
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* pointer_to_value, EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) new_value); \
EMBB_INLINE void __fastcall EMBB_CAT2(embb_internal__atomic_store_, EMBB_PARAMETER_SIZE_BYTE)(\
EMBB_PLATFORM_INLINE void __fastcall EMBB_CAT2(embb_internal__atomic_store_, EMBB_PARAMETER_SIZE_BYTE)(\
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* pointer_to_value, EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) new_value) \
{ \
_ReadWriteBarrier(); \
......@@ -53,9 +53,9 @@
EMBB_PARAMETER_SIZE_BYTE)_asm(pointer_to_value, new_value); \
_ReadWriteBarrier(); \
}
#elif defined(EMBB_COMPILER_GNUC)
#elif defined(EMBB_PLATFORM_COMPILER_GNUC)
#define EMBB_DEFINE_STORE(EMBB_PARAMETER_SIZE_BYTE, EMBB_ATOMIC_X86_SIZE_SUFFIX)\
EMBB_INLINE void EMBB_CAT2(embb_internal__atomic_store_, EMBB_PARAMETER_SIZE_BYTE)(EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* pointer_to_value, \
EMBB_PLATFORM_INLINE void EMBB_CAT2(embb_internal__atomic_store_, EMBB_PARAMETER_SIZE_BYTE)(EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* pointer_to_value, \
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) new_value) {\
/*the lock prefix is implicit for xchg*/ \
__asm__ __volatile__("xchg" EMBB_ATOMIC_X86_SIZE_SUFFIX " %1, %0" \
......@@ -78,11 +78,11 @@ EMBB_DEFINE_STORE(4, "l")
EMBB_DEFINE_STORE(8, "q")
#endif
#elif defined(EMBB_ARCH_ARM)
#elif defined(EMBB_PLATFORM_ARCH_ARM)
#if defined(EMBB_COMPILER_GNUC)
#if defined(EMBB_PLATFORM_COMPILER_GNUC)
#define EMBB_DEFINE_STORE(EMBB_PARAMETER_SIZE_BYTE, EMBB_ATOMIC_ARM_SIZE_SUFFIX)\
EMBB_INLINE \
EMBB_PLATFORM_INLINE \
void EMBB_CAT2(embb_internal__atomic_store_, EMBB_PARAMETER_SIZE_BYTE)(\
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* \
pointer_to_value, \
......@@ -115,7 +115,7 @@ EMBB_DEFINE_STORE(4, "")
* of the following macro.
*/
#define EMBB_ATOMIC_INTERNAL_DEFINE_STORE_METHOD(EMBB_ATOMIC_PARAMETER_TYPE_NATIVE, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX, EMBB_ATOMIC_PARAMETER_TYPE_SIZE) \
EMBB_INLINE void EMBB_CAT2(embb_atomic_store_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX)(EMBB_CAT2(embb_atomic_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX)* variable, EMBB_ATOMIC_PARAMETER_TYPE_NATIVE value) { \
EMBB_PLATFORM_INLINE void EMBB_CAT2(embb_atomic_store_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX)(EMBB_CAT2(embb_atomic_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX)* variable, EMBB_ATOMIC_PARAMETER_TYPE_NATIVE value) { \
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_ATOMIC_PARAMETER_TYPE_SIZE) value_pun; \
memcpy(&value_pun, &value, sizeof(EMBB_ATOMIC_PARAMETER_TYPE_NATIVE)); \
EMBB_CAT2(embb_internal__atomic_store_, EMBB_ATOMIC_PARAMETER_TYPE_SIZE)((EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_ATOMIC_PARAMETER_TYPE_SIZE) volatile *)\
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -39,13 +39,13 @@
* See file and_assign.h for a detailed (and operation independent) description
* of the following macro.
*/
#ifdef EMBB_ARCH_X86
#ifdef EMBB_PLATFORM_ARCH_X86
#ifdef EMBB_COMPILER_MSVC
#ifdef EMBB_PLATFORM_COMPILER_MSVC
#define EMBB_DEFINE_SWAP(EMBB_PARAMETER_SIZE_BYTE, EMBB_ATOMIC_X86_SIZE_SUFFIX) \
extern EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) __fastcall EMBB_CAT2 (embb_internal__atomic_swap_, EMBB_PARAMETER_SIZE_BYTE)_asm(\
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* pointer_to_value, EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) new_value); \
EMBB_INLINE EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) __fastcall EMBB_CAT2 (embb_internal__atomic_swap_, EMBB_PARAMETER_SIZE_BYTE)(\
EMBB_PLATFORM_INLINE EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) __fastcall EMBB_CAT2 (embb_internal__atomic_swap_, EMBB_PARAMETER_SIZE_BYTE)(\
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* pointer_to_value, EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) new_value) { \
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) result; \
_ReadWriteBarrier(); \
......@@ -53,9 +53,9 @@
_ReadWriteBarrier(); \
return result; \
}
#elif defined(EMBB_COMPILER_GNUC)
#elif defined(EMBB_PLATFORM_COMPILER_GNUC)
#define EMBB_DEFINE_SWAP(EMBB_PARAMETER_SIZE_BYTE, EMBB_ATOMIC_X86_SIZE_SUFFIX) \
EMBB_INLINE EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) EMBB_CAT2(embb_internal__atomic_swap_, EMBB_PARAMETER_SIZE_BYTE)(\
EMBB_PLATFORM_INLINE EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) EMBB_CAT2(embb_internal__atomic_swap_, EMBB_PARAMETER_SIZE_BYTE)(\
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* pointer_to_value, EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) new_value)\
{ \
/*the lock prefix is implicit for xchg*/ \
......@@ -80,11 +80,11 @@ EMBB_DEFINE_SWAP(4, "l")
EMBB_DEFINE_SWAP(8, "q")
#endif
#elif defined(EMBB_ARCH_ARM)
#elif defined(EMBB_PLATFORM_ARCH_ARM)
#if defined(EMBB_COMPILER_GNUC)
#if defined(EMBB_PLATFORM_COMPILER_GNUC)
#define EMBB_DEFINE_SWAP(EMBB_PARAMETER_SIZE_BYTE, EMBB_ATOMIC_ARM_SIZE_SUFFIX) \
EMBB_INLINE \
EMBB_PLATFORM_INLINE \
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) EMBB_CAT2 \
(embb_internal__atomic_swap_, EMBB_PARAMETER_SIZE_BYTE)(\
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) \
......@@ -123,7 +123,7 @@ EMBB_DEFINE_SWAP(4, "")
* of the following macro.
*/
#define EMBB_ATOMIC_INTERNAL_DEFINE_SWAP_METHOD(EMBB_ATOMIC_PARAMETER_TYPE_NATIVE, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX, EMBB_ATOMIC_PARAMETER_TYPE_SIZE) \
EMBB_INLINE EMBB_ATOMIC_PARAMETER_TYPE_NATIVE EMBB_CAT2(embb_atomic_swap_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX)(\
EMBB_PLATFORM_INLINE EMBB_ATOMIC_PARAMETER_TYPE_NATIVE EMBB_CAT2(embb_atomic_swap_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX)(\
EMBB_CAT2(embb_atomic_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX)* variable, EMBB_ATOMIC_PARAMETER_TYPE_NATIVE value) { \
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_ATOMIC_PARAMETER_TYPE_SIZE) value_pun; \
memcpy(&value_pun, &value, sizeof(EMBB_ATOMIC_PARAMETER_TYPE_NATIVE)); \
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -39,22 +39,22 @@
* See file and_assign.h for a detailed (and operation independent) description
* of the following macro.
*/
#ifdef EMBB_ARCH_X86
#ifdef EMBB_PLATFORM_ARCH_X86
#ifdef EMBB_COMPILER_MSVC
#ifdef EMBB_PLATFORM_COMPILER_MSVC
#define EMBB_DEFINE_XOR_ASSIGN(EMBB_PARAMETER_SIZE_BYTE, EMBB_ATOMIC_X86_SIZE_SUFFIX) \
extern void __fastcall EMBB_CAT2(embb_internal__atomic_xor_assign_, EMBB_PARAMETER_SIZE_BYTE)_asm(\
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* pointer_to_value, EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) value); \
EMBB_INLINE void __fastcall EMBB_CAT2(embb_internal__atomic_xor_assign_, EMBB_PARAMETER_SIZE_BYTE)(\
EMBB_PLATFORM_INLINE void __fastcall EMBB_CAT2(embb_internal__atomic_xor_assign_, EMBB_PARAMETER_SIZE_BYTE)(\
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* pointer_to_value, EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) value) { \
_ReadWriteBarrier(); \
EMBB_CAT2(embb_internal__atomic_xor_assign_, \
EMBB_PARAMETER_SIZE_BYTE)_asm(pointer_to_value, value); \
_ReadWriteBarrier(); \
}
#elif defined(EMBB_COMPILER_GNUC)
#elif defined(EMBB_PLATFORM_COMPILER_GNUC)
#define EMBB_DEFINE_XOR_ASSIGN(EMBB_PARAMETER_SIZE_BYTE, EMBB_ATOMIC_X86_SIZE_SUFFIX) \
EMBB_INLINE void EMBB_CAT2(embb_internal__atomic_xor_assign_, EMBB_PARAMETER_SIZE_BYTE)(\
EMBB_PLATFORM_INLINE void EMBB_CAT2(embb_internal__atomic_xor_assign_, EMBB_PARAMETER_SIZE_BYTE)(\
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) volatile* pointer_to_value, \
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) value) { \
__asm__ __volatile__("lock xor" EMBB_ATOMIC_X86_SIZE_SUFFIX " %1, %0" \
......@@ -78,12 +78,12 @@ EMBB_DEFINE_XOR_ASSIGN(4, "l")
EMBB_DEFINE_XOR_ASSIGN(8, "q")
#endif
#elif defined(EMBB_ARCH_ARM)
#elif defined(EMBB_PLATFORM_ARCH_ARM)
#if defined(EMBB_COMPILER_GNUC)
#if defined(EMBB_PLATFORM_COMPILER_GNUC)
#define EMBB_DEFINE_XOR_ASSIGN(EMBB_PARAMETER_SIZE_BYTE, \
EMBB_ATOMIC_ARM_SIZE_SUFFIX) \
EMBB_INLINE \
EMBB_PLATFORM_INLINE \
void EMBB_CAT2(embb_internal__atomic_xor_assign_, \
EMBB_PARAMETER_SIZE_BYTE)(\
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_PARAMETER_SIZE_BYTE) \
......@@ -121,7 +121,7 @@ EMBB_DEFINE_XOR_ASSIGN(4, "")
* of the following macro.
*/
#define EMBB_ATOMIC_INTERNAL_DEFINE_XOR_ASSIGN_METHOD(EMBB_ATOMIC_PARAMETER_TYPE_NATIVE, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX, EMBB_ATOMIC_PARAMETER_TYPE_SIZE) \
EMBB_INLINE void EMBB_CAT2(embb_atomic_xor_assign_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX)(\
EMBB_PLATFORM_INLINE void EMBB_CAT2(embb_atomic_xor_assign_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX)(\
EMBB_CAT2(embb_atomic_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX)* variable, EMBB_ATOMIC_PARAMETER_TYPE_NATIVE value) { \
EMBB_CAT2(EMBB_BASE_BASIC_TYPE_SIZE_, EMBB_ATOMIC_PARAMETER_TYPE_SIZE) value_pun;\
memcpy(&value_pun, &value, sizeof(EMBB_ATOMIC_PARAMETER_TYPE_NATIVE));\
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -33,7 +33,7 @@
#include <embb/base/c/internal/config.h>
EMBB_INLINE void embb_bitset_set(
EMBB_PLATFORM_INLINE void embb_bitset_set(
uint64_t * that,
unsigned int bit
) {
......@@ -42,7 +42,7 @@ EMBB_INLINE void embb_bitset_set(
*that |= (1ull << bit);
}
EMBB_INLINE void embb_bitset_set_n(
EMBB_PLATFORM_INLINE void embb_bitset_set_n(
uint64_t * that,
unsigned int count) {
assert(NULL != that);
......@@ -55,7 +55,7 @@ EMBB_INLINE void embb_bitset_set_n(
}
}
EMBB_INLINE void embb_bitset_clear(
EMBB_PLATFORM_INLINE void embb_bitset_clear(
uint64_t * that,
unsigned int bit
) {
......@@ -64,21 +64,21 @@ EMBB_INLINE void embb_bitset_clear(
*that &= ~(1ull << bit);
}
EMBB_INLINE void embb_bitset_clear_all(
EMBB_PLATFORM_INLINE void embb_bitset_clear_all(
uint64_t * that
) {
assert(NULL != that);
*that = 0ull;
}
EMBB_INLINE unsigned int embb_bitset_is_set(
EMBB_PLATFORM_INLINE unsigned int embb_bitset_is_set(
uint64_t const * that,
unsigned int bit
) {
return (unsigned int)((*that & (1ull << bit)) ? 1 : 0);
}
EMBB_INLINE void embb_bitset_intersect(
EMBB_PLATFORM_INLINE void embb_bitset_intersect(
uint64_t * that,
uint64_t mask
) {
......@@ -86,7 +86,7 @@ EMBB_INLINE void embb_bitset_intersect(
*that &= mask;
}
EMBB_INLINE void embb_bitset_union(
EMBB_PLATFORM_INLINE void embb_bitset_union(
uint64_t * that,
uint64_t mask
) {
......@@ -94,7 +94,7 @@ EMBB_INLINE void embb_bitset_union(
*that |= mask;
}
EMBB_INLINE unsigned int embb_bitset_count(
EMBB_PLATFORM_INLINE unsigned int embb_bitset_count(
uint64_t const * that
) {
unsigned int count = 0;
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -36,21 +36,21 @@
/**
* Is used to get the number of cores on certain systems.
*/
#cmakedefine EMBB_HAS_HEADER_SYSINFO
#cmakedefine EMBB_PLATFORM_HAS_HEADER_SYSINFO
/**
* Is used to get the number of cores on certain systems.
*/
#cmakedefine EMBB_HAS_HEADER_SYSCTL
#cmakedefine EMBB_PLATFORM_HAS_HEADER_SYSCTL
/**
* Is used to set thread affinities on certain systems.
*/
#cmakedefine EMBB_HAS_HEADER_CPUSET
#cmakedefine EMBB_PLATFORM_HAS_HEADER_CPUSET
/**
* Is used for Linux thread affinities.
*/
#cmakedefine EMBB_HAS_GLIB_CPU
#cmakedefine EMBB_PLATFORM_HAS_GLIB_CPU
#endif /* EMBB_BASE_INTERNAL_CMAKE_CONFIG_H_ */
\ No newline at end of file
#endif /* EMBB_BASE_INTERNAL_CMAKE_CONFIG_H_ */
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -45,9 +45,9 @@
* which has 128 bytes.
*/
#if defined(_M_IA64) || defined(_IA64)
#define EMBB_CACHE_LINE_SIZE 128
#define EMBB_PLATFORM_CACHE_LINE_SIZE 128
#else
#define EMBB_CACHE_LINE_SIZE 64
#define EMBB_PLATFORM_CACHE_LINE_SIZE 64
#endif
/* For MSVC, if _DEBUG is set, set also EMBB_DEBUG.
......@@ -59,41 +59,41 @@
#endif
#ifdef __GNUC__
#define EMBB_ALIGN(size) __attribute__ ((aligned(size)))
#define EMBB_PLATFORM_ALIGN(size) __attribute__ ((aligned(size)))
#elif defined _MSC_VER || defined __INTEL_COMPILER
#define EMBB_ALIGN(size) __declspec(align(size))
#define EMBB_PLATFORM_ALIGN(size) __declspec(align(size))
#else
#error "Unsupported compiler"
#endif
#if __GNUC__
#define EMBB_INLINE static inline
#define EMBB_COMPILER_GNUC
#define EMBB_PLATFORM_INLINE static inline
#define EMBB_PLATFORM_COMPILER_GNUC
#elif _MSC_VER
#define EMBB_INLINE __inline
#define EMBB_COMPILER_MSVC
#define EMBB_PLATFORM_INLINE __inline
#define EMBB_PLATFORM_COMPILER_MSVC
#else
#define EMBB_INLINE inline
#define EMBB_COMPILER_UNKNOWN
#define EMBB_PLATFORM_INLINE inline
#define EMBB_PLATFORM_COMPILER_UNKNOWN
#endif
#if defined(__x86_64__) || defined(_M_X64)
#define EMBB_ARCH_X86_64
#define EMBB_ARCH_X86
#define EMBB_HAS_CAS_64
#define EMBB_PLATFORM_ARCH_X86_64
#define EMBB_PLATFORM_ARCH_X86
#define EMBB_PLATFORM_HAS_CAS_64
#elif defined(__i386) || defined(_M_IX86)
#define EMBB_ARCH_X86_32
#define EMBB_ARCH_X86
#define EMBB_PLATFORM_ARCH_X86_32
#define EMBB_PLATFORM_ARCH_X86
#elif defined(__arm__)
#define EMBB_ARCH_ARM
#define EMBB_PLATFORM_ARCH_ARM
#else
#define EMBB_ARCH_UNKNOWN
#define EMBB_PLATFORM_ARCH_UNKNOWN
#endif
#if defined(EMBB_COMPILER_MSVC)
#define EMBB_THREADING_WINTHREADS
#elif defined(EMBB_COMPILER_GNUC)
#define EMBB_THREADING_POSIXTHREADS
#if defined(EMBB_PLATFORM_COMPILER_MSVC)
#define EMBB_PLATFORM_THREADING_WINTHREADS
#elif defined(EMBB_PLATFORM_COMPILER_GNUC)
#define EMBB_PLATFORM_THREADING_POSIXTHREADS
#else
#error "No thread implementation could be determined"
#endif
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -37,9 +37,9 @@ extern "C" {
#define EMBB_TIME_MAX_SECONDS ULLONG_MAX
#define EMBB_DURATION_MAX_SECONDS 60 * 60 * 24 * 7
#ifdef EMBB_THREADING_WINTHREADS
#ifdef EMBB_PLATFORM_THREADING_WINTHREADS
#ifdef EMBB_COMPILER_MSVC
#ifdef EMBB_PLATFORM_COMPILER_MSVC
// Suppress virtual functions but non-virtual constructor warning
// in windows headers
#pragma warning(push)
......@@ -49,7 +49,7 @@ extern "C" {
#define NOMINMAX
#include <windows.h>
#ifdef EMBB_COMPILER_MSVC
#ifdef EMBB_PLATFORM_COMPILER_MSVC
#pragma warning(pop) // Reset warning 4640
#endif
......@@ -71,7 +71,7 @@ typedef CONDITION_VARIABLE embb_condition_t;
#define EMBB_THREAD_SPECIFIC static __declspec(thread)
#elif defined EMBB_THREADING_POSIXTHREADS /* EMBB_THREADING_WINTHREADS */
#elif defined EMBB_PLATFORM_THREADING_POSIXTHREADS
#include <pthread.h>
#include <errno.h>
......@@ -95,7 +95,7 @@ typedef pthread_cond_t embb_condition_t;
#define EMBB_THREAD_SPECIFIC __thread
#else /* EMBB_THREADING_POSIXTHREADS */
#else /* EMBB_PLATFORM_THREADING_POSIXTHREADS */
#error "No threading platform defined!"
......@@ -105,4 +105,4 @@ typedef pthread_cond_t embb_condition_t;
} /* Close extern "C" { */
#endif
#endif /* EMBB_BASE_C_INTERNAL_PLATFORM_H_ */
#endif // EMBB_BASE_C_INTERNAL_PLATFORM_H_
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -43,7 +43,7 @@ int embb_condition_wait_for(embb_condition_t* condition_var,
return embb_condition_wait_until(condition_var, mutex, &time);
}
#ifdef EMBB_THREADING_WINTHREADS
#ifdef EMBB_PLATFORM_THREADING_WINTHREADS
int embb_condition_init(embb_condition_t* condition_var) {
assert(condition_var != NULL);
......@@ -108,9 +108,9 @@ int embb_condition_destroy(embb_condition_t* condition_var) {
return EMBB_SUCCESS;
}
#endif /* EMBB_THREADING_WINTHREADS */
#endif /* EMBB_PLATFORM_THREADING_WINTHREADS */
#ifdef EMBB_THREADING_POSIXTHREADS
#ifdef EMBB_PLATFORM_THREADING_POSIXTHREADS
int embb_condition_init(embb_condition_t* condition_var) {
assert(condition_var != NULL);
......@@ -165,4 +165,4 @@ int embb_condition_destroy(embb_condition_t* condition_var) {
return EMBB_SUCCESS;
}
#endif /* EMBB_THREADING_POSIXTHREADS */
#endif /* EMBB_PLATFORM_THREADING_POSIXTHREADS */
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -31,7 +31,7 @@
#include <limits.h>
#include <assert.h>
#ifdef EMBB_THREADING_WINTHREADS
#ifdef EMBB_PLATFORM_THREADING_WINTHREADS
/**
* For handling of more than 64 logical processors on Windows.
......@@ -87,21 +87,21 @@ void embb_core_set_init(embb_core_set_t* core_set, int initializer) {
}
}
#endif /* EMBB_THREADING_WINTHREADS */
#endif /* EMBB_PLATFORM_THREADING_WINTHREADS */
#ifdef EMBB_THREADING_POSIXTHREADS
#ifdef EMBB_PLATFORM_THREADING_POSIXTHREADS
#ifdef EMBB_HAS_HEADER_SYSINFO
#ifdef EMBB_PLATFORM_HAS_HEADER_SYSINFO
#include <sys/sysinfo.h>
#elif defined EMBB_HAS_HEADER_SYSCTL
#elif defined EMBB_PLATFORM_HAS_HEADER_SYSCTL
#include <sys/types.h>
#include <sys/sysctl.h>
#endif
unsigned int embb_core_count_available() {
#ifdef EMBB_HAS_HEADER_SYSINFO
#ifdef EMBB_PLATFORM_HAS_HEADER_SYSINFO
return get_nprocs();
#elif defined EMBB_HAS_HEADER_SYSCTL
#elif defined EMBB_PLATFORM_HAS_HEADER_SYSCTL
const size_t kBufferSize = sizeof(unsigned int);
char buf[kBufferSize];
size_t len = kBufferSize;
......@@ -123,7 +123,7 @@ void embb_core_set_init(embb_core_set_t* core_set, int initializer) {
}
}
#endif /* EMBB_THREADING_POSIXTHREADS */
#endif /* EMBB_PLATFORM_THREADING_POSIXTHREADS */
void embb_core_set_add(embb_core_set_t* core_set, unsigned int core_number) {
assert(core_set != NULL);
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -91,14 +91,14 @@ static void embb_log_write_internal(
log_level_str = " ";
break;
}
#if defined(EMBB_COMPILER_MSVC)
#if defined(EMBB_PLATFORM_COMPILER_MSVC)
char msg_buffer[400];
char buffer[500];
vsprintf_s(msg_buffer, sizeof(msg_buffer), message, argp);
sprintf_s(buffer, sizeof(buffer), "[%s] - [%s] %s",
channel_str, log_level_str, msg_buffer);
embb_log_global_log_function(log_context, buffer);
#elif defined(EMBB_COMPILER_GNUC)
#elif defined(EMBB_PLATFORM_COMPILER_GNUC)
char msg_buffer[400];
char buffer[500];
vsnprintf(msg_buffer, sizeof(msg_buffer), message, argp);
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -166,7 +166,7 @@ void embb_free(void * ptr) {
void *embb_alloc_aligned(size_t alignment, size_t size) {
void* malloc_addr = NULL;
#ifdef EMBB_COMPILER_MSVC
#ifdef EMBB_PLATFORM_COMPILER_MSVC
/*
* From the Documentation:
* Allocates memory on a specified alignment boundary.
......@@ -176,7 +176,7 @@ void *embb_alloc_aligned(size_t alignment, size_t size) {
* failed. The pointer is a multiple of alignment.
*/
malloc_addr = _aligned_malloc(size, alignment);
#elif defined EMBB_COMPILER_GNUC
#elif defined EMBB_PLATFORM_COMPILER_GNUC
/*
* From the Documentation:
* The posix_memalign() function shall allocate size bytes aligned on a
......@@ -193,10 +193,10 @@ void *embb_alloc_aligned(size_t alignment, size_t size) {
}
void embb_free_aligned(void* ptr) {
#ifdef EMBB_COMPILER_MSVC
#ifdef EMBB_PLATFORM_COMPILER_MSVC
_aligned_free(ptr);
#else
#ifdef EMBB_COMPILER_GNUC
#ifdef EMBB_PLATFORM_COMPILER_GNUC
free(ptr);
#else
#error Unsupported compiler
......@@ -211,5 +211,5 @@ size_t embb_get_bytes_allocated() {
#endif
void *embb_alloc_cache_aligned(size_t size) {
return embb_alloc_aligned(EMBB_CACHE_LINE_SIZE, size);
return embb_alloc_aligned(EMBB_PLATFORM_CACHE_LINE_SIZE, size);
}
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -29,7 +29,7 @@
#include <embb/base/c/internal/unused.h>
#ifdef EMBB_THREADING_WINTHREADS
#ifdef EMBB_PLATFORM_THREADING_WINTHREADS
int embb_mutex_init(embb_mutex_t* mutex, int type) {
/* Critical sections in Windows are always recursive */
......@@ -59,9 +59,9 @@ void embb_mutex_destroy(embb_mutex_t* mutex) {
DeleteCriticalSection(mutex);
}
#endif /* EMBB_THREADING_WINTHREADS */
#endif /* EMBB_PLATFORM_THREADING_WINTHREADS */
#ifdef EMBB_THREADING_POSIXTHREADS
#ifdef EMBB_PLATFORM_THREADING_POSIXTHREADS
int embb_mutex_init(embb_mutex_t* mutex, int type) {
if (type == EMBB_MUTEX_PLAIN) {
......@@ -71,9 +71,13 @@ int embb_mutex_init(embb_mutex_t* mutex, int type) {
pthread_mutexattr_t attributes;
if (pthread_mutexattr_init(&attributes) != 0) return EMBB_ERROR;
if (pthread_mutexattr_settype(&attributes, PTHREAD_MUTEX_RECURSIVE) != 0) {
pthread_mutexattr_destroy(&attributes);
return EMBB_ERROR;
}
if (pthread_mutex_init(mutex, &attributes) != 0) {
pthread_mutexattr_destroy(&attributes);
return EMBB_ERROR;
}
if (pthread_mutex_init(mutex, &attributes) != 0) return EMBB_ERROR;
if (pthread_mutexattr_destroy(&attributes) != 0) return EMBB_ERROR;
}
return EMBB_SUCCESS;
......@@ -110,4 +114,4 @@ void embb_mutex_destroy(embb_mutex_t* mutex) {
pthread_mutex_destroy(mutex);
}
#endif /* EMBB_THREADING_POSIXTHREADS */
#endif /* EMBB_PLATFORM_THREADING_POSIXTHREADS */
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -40,7 +40,7 @@ void embb_thread_set_max_count(unsigned int max) {
embb_internal_thread_index_set_max(max);
}
#ifdef EMBB_THREADING_WINTHREADS
#ifdef EMBB_PLATFORM_THREADING_WINTHREADS
/**
* Used to wrap client thread start function and argument when calling internal
......@@ -151,21 +151,21 @@ int embb_thread_equal(const embb_thread_t* lhs, const embb_thread_t* rhs) {
return 0;
}
#endif /* EMBB_THREADING_WINTHREADS */
#endif /* EMBB_PLATFORM_THREADING_WINTHREADS */
#ifdef EMBB_THREADING_POSIXTHREADS
#ifdef EMBB_PLATFORM_THREADING_POSIXTHREADS
#ifdef EMBB_HAS_GLIB_CPU
#ifdef EMBB_PLATFORM_HAS_GLIB_CPU
#include <sched.h>
#elif defined EMBB_HAS_HEADER_CPUSET
#elif defined EMBB_PLATFORM_HAS_HEADER_CPUSET
#include <pthread_np.h>
#include <sys/param.h>
#include <sys/cpuset.h>
#endif
#ifdef EMBB_HAS_HEADER_SYSINFO
#ifdef EMBB_PLATFORM_HAS_HEADER_SYSINFO
#include <sys/sysinfo.h> /* Used to get number of processors */
#endif /* EMBB_HAS_HEADER_SYSINFO */
#endif /* EMBB_PLATFORM_HAS_HEADER_SYSINFO */
/**
* Used to wrap client thread start function and argument when calling internal
......@@ -207,10 +207,11 @@ int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set,
int status = pthread_attr_init(&attr);
if (status != 0) return EMBB_ERROR;
if (core_set != NULL) {
#if defined(EMBB_HAS_GLIB_CPU) || defined(EMBB_HAS_HEADER_CPUSET)
#if defined(EMBB_PLATFORM_HAS_GLIB_CPU) || \
defined(EMBB_PLATFORM_HAS_HEADER_CPUSET)
assert(embb_core_count_available() < CPU_SETSIZE &&
"Core sets are only supported up to CPU_SETSIZE processors!");
#ifdef EMBB_HAS_GLIB_CPU
#ifdef EMBB_PLATFORM_HAS_GLIB_CPU
cpu_set_t cpuset;
#else
cpuset_t cpuset;
......@@ -243,7 +244,7 @@ int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set,
(void*)(thread->embb_internal_arg)); /* arguments to thread start func. */
if (status != 0) return EMBB_ERROR;
pthread_attr_destroy(&attr);
status = pthread_attr_destroy(&attr);
if (status != 0) return EMBB_ERROR;
return EMBB_SUCCESS;
}
......@@ -265,4 +266,4 @@ int embb_thread_equal(const embb_thread_t* lhs, const embb_thread_t* rhs) {
return pthread_equal(lhs->embb_internal_handle, rhs->embb_internal_handle);
}
#endif /* EMBB_THREADING_POSIXTHREADS */
#endif /* EMBB_PLATFORM_THREADING_POSIXTHREADS */
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -57,6 +57,7 @@ int embb_tss_set(embb_tss_t* tss, void* value) {
void* embb_tss_get(const embb_tss_t* tss) {
assert(tss != NULL);
assert(tss->values != NULL);
unsigned int index = 0;
int status = embb_internal_thread_index(&index);
if ((status != EMBB_SUCCESS) || (index >= tss->size)) {
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -53,7 +53,7 @@ int embb_time_compare(const embb_time_t* lhs, const embb_time_t* rhs) {
}
#ifdef EMBB_THREADING_WINTHREADS
#ifdef EMBB_PLATFORM_THREADING_WINTHREADS
int embb_time_in(embb_time_t* time, const embb_duration_t* duration) {
assert(time != NULL);
......@@ -81,10 +81,10 @@ int embb_time_in(embb_time_t* time, const embb_duration_t* duration) {
return EMBB_SUCCESS;
}
#endif /* EMBB_THREADING_WINTHREADS */
#endif /* EMBB_PLATFORM_THREADING_WINTHREADS */
#ifdef EMBB_THREADING_POSIXTHREADS
#ifdef EMBB_PLATFORM_THREADING_POSIXTHREADS
int embb_time_in(embb_time_t* time, const embb_duration_t* duration) {
assert(time != NULL);
......@@ -102,5 +102,5 @@ int embb_time_in(embb_time_t* time, const embb_duration_t* duration) {
return EMBB_SUCCESS;
}
#endif /* EMBB_THREADING_POSIXTHREADS */
#endif /* EMBB_PLATFORM_THREADING_POSIXTHREADS */
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -174,7 +174,7 @@ void AllocTest::TestMixedAllocs() {
PT_EXPECT_NE(cache_aligned, static_cast<void*>(NULL));
allocated = embb_get_bytes_allocated();
#ifdef EMBB_DEBUG
expected += (1 + 1) * EMBB_CACHE_LINE_SIZE + 3 * sizeof(size_t) - 1;
expected += (1 + 1) * EMBB_PLATFORM_CACHE_LINE_SIZE + 3 * sizeof(size_t) - 1;
#endif // else EMBB_DEBUG
PT_EXPECT_EQ(allocated, expected);
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -81,4 +81,4 @@ class AllocTest : public partest::TestCase {
} // namespace base
} // namespace embb
#endif /* BASE_C_TEST_ALLOC_TEST_H_ */
#endif // BASE_C_TEST_ALLOC_TEST_H_
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......@@ -65,4 +65,4 @@ class ConditionVarTest : public partest::TestCase {
} // namespace base
} // namespace embb
#endif /* BASE_C_TEST_CONDITION_VAR_TEST_H_ */
#endif // BASE_C_TEST_CONDITION_VAR_TEST_H_
/*
* Copyright (c) 2014, Siemens AG. All rights reserved.
* 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:
......
This diff is collapsed. Click to expand it.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment