Skip to content

Commit

Permalink
Merge branch 'development' of https://github.com/siemens/embb into de…
Browse files Browse the repository at this point in the history
…velopment
  • Loading branch information
tobias-schuele committed Feb 24, 2016
2 parents 3866f35 + 36e27d5 commit 9018e0a
Show file tree
Hide file tree
Showing 76 changed files with 746 additions and 167 deletions.
13 changes: 11 additions & 2 deletions CMakeCommon/SetCompilerFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,19 @@ function(SetVisualStudioCompilerFlags)
# Locally suppressed warnings (should not be globally suppressed):
# 4640 -> Information that local static variable initialization is not
# thread-safe.
#
# VS 2015 specific warnings:
# 5026 -> Move constructor was implicitly defined as deleted
# 5027 -> Move assignment operator was implicitly defined as deleted
#
set(warning_flags "/Wall /wd4820 /wd4514 /wd4668 /wd4710 /wd4350 /wd4571 /wd4625 /wd4626 /wd4711 /wd4255")
if (WARNINGS_ARE_ERRORS STREQUAL ON)
if (WARNINGS_ARE_ERRORS STREQUAL ON)
set(warning_flags "${warning_flags} /WX")
endif()
endif()
string(FIND "${CMAKE_GENERATOR}" "Visual Studio 14 2015" vs2015_state)
if (vs2015_state EQUAL 0)
set(warning_flags "${warning_flags} /wd5026 /wd5027")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${warning_flags}" PARENT_SCOPE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${warning_flags}" PARENT_SCOPE)
endif()
Expand Down
15 changes: 5 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,6 @@ if(POLICY CMP0053)
cmake_policy(SET CMP0053 OLD)
endif(POLICY CMP0053)


include(CMakeCommon/FindOpenCL.cmake)
IF(NOT OpenCL_FOUND)
MESSAGE( STATUS "OpenCL is not there, will build without MTAPI OpenCL Plugin." )
ENDIF()

# give the user the possibility, to append compiler flags
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CMAKE_CXX_FLAGS}")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CMAKE_C_FLAGS}")
Expand Down Expand Up @@ -88,6 +82,7 @@ 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)
option(BUILD_OPENCL_PLUGIN "Specify whether the MTAPI OpenCL plugin should be built" OFF)

## LOCAL INSTALLATION OF SUBPROJECT BINARIES
#
Expand Down Expand Up @@ -146,7 +141,7 @@ set(EXPECTED_EMBB_TEST_EXECUTABLES "embb_algorithms_cpp_test"
)

# if opencl is there, we also expect the mtapi opencl test to be generated
if(OpenCL_FOUND)
if(BUILD_OPENCL_PLUGIN STREQUAL ON)
list(APPEND EXPECTED_EMBB_TEST_EXECUTABLES "embb_mtapi_opencl_c_test")
endif()

Expand Down Expand Up @@ -181,9 +176,9 @@ CheckPartestInstall(${BUILD_TESTS} partest_includepath partest_libpath)
add_subdirectory(base_c)
add_subdirectory(base_cpp)
add_subdirectory(mtapi_c)
add_subdirectory(mtapi_network_c)
if(OpenCL_FOUND)
add_subdirectory(mtapi_opencl_c)
add_subdirectory(mtapi_plugins_c/mtapi_network_c)
if(BUILD_OPENCL_PLUGIN STREQUAL ON)
add_subdirectory(mtapi_plugins_c/mtapi_opencl_c)
endif()
add_subdirectory(tasks_cpp)
add_subdirectory(mtapi_cpp)
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ postfixed with either "_cpp" or "_c" for the C++ and C versions, respectively.
Currently, EMB² contains the following components:

- base: base_c, base_cpp
- mtapi: mtapi_c, mtapi_network_c, mtapi_opencl_c, mtapi_cpp
- mtapi: mtapi_c, mtapi_cpp and
mtapi_plugins_c (mtapi_network_c and mtapi_opencl_c)
- tasks: tasks_cpp
- algorithms: algorithms_cpp
- dataflow: dataflow_cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX) \
typedef struct \
{ \
EMBB_ATOMIC_PARAMETER_TYPE_NATIVE internal_variable; \
volatile EMBB_ATOMIC_PARAMETER_TYPE_NATIVE internal_variable; \
} EMBB_CAT2(embb_atomic_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX);

EMBB_ATOMIC_INTERNAL_DEFINE_VARIABLE(char, char)
Expand Down
8 changes: 8 additions & 0 deletions base_c/include/embb/base/c/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#define EMBB_BASE_C_LOG_H_

#include <embb/base/c/internal/config.h>
#include <stdarg.h>

/**
* \defgroup C_LOG Logging
Expand Down Expand Up @@ -197,6 +198,13 @@ void embb_log_error(
\c message */
);

/* function for internal use only */
void embb_log_write_internal(
char const * channel,
embb_log_level_t log_level,
char const * message,
va_list argp);

#ifdef __cplusplus
}
#endif
Expand Down
3 changes: 3 additions & 0 deletions base_c/include/embb/base/c/mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ int embb_spin_init(
/**
* Spins until the spinlock can be locked and locks it.
*
* \note This method yields the current thread in regular,
* implementation-defined intervals.
*
* \pre \c spinlock is initialized \n
* \post If successful, \c spinlock is locked.
* \return EMBB_SUCCESS if spinlock could be locked. \n
Expand Down
2 changes: 1 addition & 1 deletion base_c/src/internal/thread_index.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,4 @@ void embb_internal_thread_index_reset() {
embb_internal_thread_index_var = UINT_MAX;

embb_counter_init(embb_thread_index_counter());
}
}
12 changes: 7 additions & 5 deletions base_c/src/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void embb_log_set_log_function(
embb_log_global_log_function = func;
}

static void embb_log_write_internal(
void embb_log_write_internal(
char const * channel,
embb_log_level_t log_level,
char const * message,
Expand All @@ -75,18 +75,20 @@ static void embb_log_write_internal(
log_context = (void*)stdout;
}
switch (log_level) {
case EMBB_LOG_LEVEL_INFO:
log_level_str = "INFO ";
break;
case EMBB_LOG_LEVEL_ERROR:
log_level_str = "ERROR";
break;
case EMBB_LOG_LEVEL_WARNING:
log_level_str = "WARN ";
break;
case EMBB_LOG_LEVEL_INFO:
log_level_str = "INFO ";
break;
case EMBB_LOG_LEVEL_TRACE:
log_level_str = "TRACE";
break;

case EMBB_LOG_LEVEL_NONE:
case EMBB_LOG_LEVEL_WARNING:
default:
log_level_str = " ";
break;
Expand Down
6 changes: 6 additions & 0 deletions base_c/src/mutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/

#include <embb/base/c/mutex.h>
#include <embb/base/c/thread.h>
#include <assert.h>

#include <embb/base/c/internal/unused.h>
Expand Down Expand Up @@ -125,10 +126,15 @@ int embb_spin_init(embb_spinlock_t* spinlock) {

int embb_spin_lock(embb_spinlock_t* spinlock) {
int expected = 0;
int spins = 1;

// try to swap the
while (0 == embb_atomic_compare_and_swap_int(
&spinlock->atomic_spin_variable_, &expected, 1)) {
if (0 == (spins & 1023)) {
embb_thread_yield();
}
spins++;
// reset expected, as CAS might change it...
expected = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion base_cpp/include/embb/base/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Atomic {
/**
* Default constructor.
*
* Constructs an atomic variable holding an uninitialized value.
* Constructs an atomic variable holding zero.
*
* \waitfree
*
Expand Down
162 changes: 162 additions & 0 deletions base_cpp/include/embb/base/log.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef EMBB_BASE_LOG_H_
#define EMBB_BASE_LOG_H_

#include <embb/base/c/log.h>

/**
* \defgroup CPP_LOG Logging
* \ingroup CPP_BASE
* Simple logging facilities.
*/

namespace embb {
namespace base {

/**
* Simple logging facilities.
*
* \ingroup CPP_LOG
*/
class Log {
private:
// do not allow construction
Log();

public:
/**
* Sets the global log level.
* This determines what messages will be shown, messages with a more detailed
* log level will be filtered out. The default log level is EMBB_LOG_LEVEL_NONE.
* \notthreadsafe
*/
static void SetLogLevel(
embb_log_level_t log_level /**< [in] Log level to use for
filtering */
);

/**
* Sets the global logging function.
* The logging function implements the mechanism for transferring log messages
* to their destination. \c context is a pointer to data the user needs in the
* function to determine where the messages should go (may be NULL if no
* additional data is needed). The default logging function is
* embb_log_write_file() with context set to \c stdout.
* \see embb_log_function_t
* \notthreadsafe
*/
static void SetLogFunction(
void * context, /**< [in] User context to supply as the
first parameter of the logging
function*/
embb_log_function_t func /**< [in] The logging function */
);

/**
* Logs a message to the given channel with the specified log level.
* If the log level is greater than the configured log level for the channel,
* the message will be ignored.
* \see embb::base::Log::SetLogLevel, embb::base::Log::SetLogFunction
* \threadsafe
*/
static void Write(
char const * channel, /**< [in] User specified channel id
for filtering the log later on.
Might be NULL, channel identifier
will be "global" in that case */
embb_log_level_t log_level, /**< [in] Log level to use */
char const * message, /**< [in] Message to convey, may use
\c printf style formatting */
... /**< Additional parameters determined
by the format specifiers in
\c message */
);

/**
* Logs a message to the given channel with EMBB_LOG_LEVEL_TRACE.
* In non-debug builds, this function does nothing.
* \see embb::base::Log::Write
* \threadsafe
*/
static void Trace(
char const * channel, /**< [in] User specified channel id */
char const * message, /**< [in] Message to convey, may use
\c printf style formatting */
... /**< Additional parameters determined
by the format specifiers in
\c message */
);

/**
* Logs a message to the given channel with EMBB_LOG_LEVEL_INFO.
* In non-debug builds, this function does nothing.
* \see embb::base::Log::Write
* \threadsafe
*/
static void Info(
char const * channel, /**< [in] User specified channel id */
char const * message, /**< [in] Message to convey, may use
\c printf style formatting */
... /**< Additional parameters determined
by the format specifiers in
\c message */
);

/**
* Logs a message to the given channel with EMBB_LOG_LEVEL_WARNING.
* \see embb::base::Log::Write
* \threadsafe
*/
static void Warning(
char const * channel, /**< [in] User specified channel id */
char const * message, /**< [in] Message to convey, may use
\c printf style formatting */
... /**< Additional parameters determined
by the format specifiers in
\c message */
);

/**
* Logs a message to the given channel with EMBB_LOG_LEVEL_ERROR.
* \see embb::base::Log::Write
* \threadsafe
*/
static void Error(
char const * channel, /**< [in] User specified channel id */
char const * message, /**< [in] Message to convey, may use
\c printf style formatting */
... /**< Additional parameters determined
by the format specifiers in
\c message */
);
};

} // namespace base
} // namespace embb

#endif // EMBB_BASE_LOG_H_
3 changes: 3 additions & 0 deletions base_cpp/include/embb/base/mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ class Spinlock {
/**
* Waits until the spinlock can be locked and locks it.
*
* \note This method yields the current thread in regular,
* implementation-defined intervals.
*
* \pre The spinlock is not locked by the current thread.
* \post The spinlock is locked.
* \threadsafe
Expand Down
Loading

0 comments on commit 9018e0a

Please sign in to comment.