Commit 3ad4b725 by Tobias Schuele

Merge branch 'development' of https://github.com/siemens/embb into development

parents 9018e0ad 7b0d2c67
# Copyright (c) 2014-2015, Siemens AG. All rights reserved. # Copyright (c) 2014-2016, Siemens AG. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause # SPDX-License-Identifier: BSD-2-Clause
language: cpp language: cpp
......
# Copyright (c) 2014-2015, Siemens AG. All rights reserved. # Copyright (c) 2014-2016, Siemens AG. All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met: # modification, are permitted provided that the following conditions are met:
......
# Copyright (c) 2014-2015, Siemens AG. All rights reserved. # Copyright (c) 2014-2016, Siemens AG. All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met: # modification, are permitted provided that the following conditions are met:
......
# Copyright (c) 2014-2015, Siemens AG. All rights reserved. # Copyright (c) 2014-2016, Siemens AG. All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met: # modification, are permitted provided that the following conditions are met:
......
# Copyright (c) 2014-2015, Siemens AG. All rights reserved. # Copyright (c) 2014-2016, Siemens AG. All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met: # modification, are permitted provided that the following conditions are met:
......
# Copyright (c) 2014-2015, Siemens AG. All rights reserved. # Copyright (c) 2014-2016, Siemens AG. All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met: # modification, are permitted provided that the following conditions are met:
......
# Copyright (c) 2014-2015, Siemens AG. All rights reserved. # Copyright (c) 2014-2016, Siemens AG. All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met: # modification, are permitted provided that the following conditions are met:
......
# Copyright (c) 2014-2015, Siemens AG. All rights reserved. # Copyright (c) 2014-2016, Siemens AG. All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met: # modification, are permitted provided that the following conditions are met:
......
...@@ -13,7 +13,7 @@ license (see file include\embb\mtapi\c\mtapi.h). ...@@ -13,7 +13,7 @@ license (see file include\embb\mtapi\c\mtapi.h).
License License
------- -------
Copyright (c) 2014-2015, Siemens AG. All rights reserved. Copyright (c) 2014-2016, Siemens AG. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
......
Embedded Multicore Building Blocks (EMB²) Embedded Multicore Building Blocks (EMB²)
========================================= =========================================
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
...@@ -81,6 +81,8 @@ unsigned int embb_core_count_available(); ...@@ -81,6 +81,8 @@ unsigned int embb_core_count_available();
* The second parameter specifies whether the set is initially empty or contains * The second parameter specifies whether the set is initially empty or contains
* all cores. * all cores.
* *
* \pre \c core_set is not NULL.
*
* \notthreadsafe * \notthreadsafe
*/ */
void embb_core_set_init( void embb_core_set_init(
...@@ -96,6 +98,9 @@ void embb_core_set_init( ...@@ -96,6 +98,9 @@ void embb_core_set_init(
* *
* If the core is already contained in the set, the operation has no effect. * If the core is already contained in the set, the operation has no effect.
* *
* \pre \c core_set is not NULL and \c core_number is smaller than
* embb_core_count_available().
*
* \notthreadsafe * \notthreadsafe
* \see embb_core_set_remove() * \see embb_core_set_remove()
*/ */
...@@ -107,13 +112,16 @@ void embb_core_set_add( ...@@ -107,13 +112,16 @@ void embb_core_set_add(
); );
/** /**
* Removes a core from the specified set. * Removes a core from the specified set.
* *
* If the core is not in the set, the operation has no effect. * If the core is not in the set, the operation has no effect.
* *
* \notthreadsafe * \pre \c core_set is not NULL and \c core_number is smaller than
* \see embb_core_set_add() * embb_core_count_available().
*/ *
* \notthreadsafe
* \see embb_core_set_add()
*/
void embb_core_set_remove( void embb_core_set_remove(
embb_core_set_t* core_set, embb_core_set_t* core_set,
/**< [IN/OUT] Core set to be manipulated */ /**< [IN/OUT] Core set to be manipulated */
...@@ -124,8 +132,11 @@ void embb_core_set_remove( ...@@ -124,8 +132,11 @@ void embb_core_set_remove(
/** /**
* Determines whether a core is contained in the specified set. * Determines whether a core is contained in the specified set.
* *
* \return 0 if the core is not contained in the set, otherwise a number greater * \pre \c core_set is not NULL and \c core_number is smaller than
* than zero. * embb_core_count_available().
*
* \return 0 if the core is not contained in the set, otherwise a number
* greater than zero.
* \notthreadsafe * \notthreadsafe
*/ */
int embb_core_set_contains( int embb_core_set_contains(
...@@ -140,6 +151,8 @@ int embb_core_set_contains( ...@@ -140,6 +151,8 @@ int embb_core_set_contains(
* *
* The result is stored in \c set1. * The result is stored in \c set1.
* *
* \pre \c set1 and \c set2 are not NULL.
*
* \notthreadsafe * \notthreadsafe
* \see embb_core_set_union() * \see embb_core_set_union()
*/ */
...@@ -155,6 +168,8 @@ void embb_core_set_intersection( ...@@ -155,6 +168,8 @@ void embb_core_set_intersection(
* *
* The result is stored in \c set1. * The result is stored in \c set1.
* *
* \pre \c set1 and \c set2 are not NULL.
*
* \notthreadsafe * \notthreadsafe
* \see embb_core_set_intersection() * \see embb_core_set_intersection()
*/ */
...@@ -168,6 +183,8 @@ void embb_core_set_union( ...@@ -168,6 +183,8 @@ void embb_core_set_union(
/** /**
* Returns the number of cores contained in the specified set. * Returns the number of cores contained in the specified set.
* *
* \pre \c core_set is not NULL.
*
* \notthreadsafe * \notthreadsafe
* \return Number of cores in \c core_set * \return Number of cores in \c core_set
*/ */
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
...@@ -67,6 +67,8 @@ int embb_counter_init( ...@@ -67,6 +67,8 @@ int embb_counter_init(
/** /**
* Returns the current value of \c counter. * Returns the current value of \c counter.
* *
* \pre \c counter is not NULL.
*
* \return Current value * \return Current value
* *
* \waitfree * \waitfree
...@@ -79,6 +81,8 @@ unsigned int embb_counter_get( ...@@ -79,6 +81,8 @@ unsigned int embb_counter_get(
/** /**
* Increments \c counter and returns the old value. * Increments \c counter and returns the old value.
* *
* \pre \c counter is not NULL.
*
* \return Old, non-incremented value * \return Old, non-incremented value
* \waitfree * \waitfree
*/ */
...@@ -90,6 +94,8 @@ unsigned int embb_counter_increment( ...@@ -90,6 +94,8 @@ unsigned int embb_counter_increment(
/** /**
* Decrements \c counter and returns the old value. * Decrements \c counter and returns the old value.
* *
* \pre \c counter is not NULL.
*
* \return Old, non-decremented value * \return Old, non-decremented value
* \waitfree * \waitfree
*/ */
...@@ -101,8 +107,8 @@ unsigned int embb_counter_decrement( ...@@ -101,8 +107,8 @@ unsigned int embb_counter_decrement(
/** /**
* Destroys an initialized counter. * Destroys an initialized counter.
* *
* \pre Counter is initialized * \pre \c counter is initialized and not NULL.
* \post Counter is invalid and cannot be used anymore * \post \c counter is invalid and cannot be used anymore
* \waitfree * \waitfree
*/ */
void embb_counter_destroy( void embb_counter_destroy(
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
...@@ -249,6 +249,8 @@ int embb_duration_as_seconds( ...@@ -249,6 +249,8 @@ int embb_duration_as_seconds(
/** /**
* Compares two durations. * Compares two durations.
* *
* \pre \c lhs and \c rhs are not NULL and properly initialized.
*
* \return -1 if \c lhs < \c rhs \n * \return -1 if \c lhs < \c rhs \n
* 0 if \c lhs == \c rhs \n * 0 if \c lhs == \c rhs \n
* 1 if \c lhs > \c rhs * 1 if \c lhs > \c rhs
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
...@@ -53,4 +53,10 @@ ...@@ -53,4 +53,10 @@
*/ */
#cmakedefine EMBB_PLATFORM_HAS_GLIB_CPU #cmakedefine EMBB_PLATFORM_HAS_GLIB_CPU
#define EMBB_BASE_VERSION_MAJOR ${EMBB_BASE_VERSION_MAJOR}
#define EMBB_BASE_VERSION_MINOR ${EMBB_BASE_VERSION_MINOR}
#define EMBB_BASE_VERSION_PATCH ${EMBB_BASE_VERSION_PATCH}
#endif /* EMBB_BASE_INTERNAL_CMAKE_CONFIG_H_ */ #endif /* EMBB_BASE_INTERNAL_CMAKE_CONFIG_H_ */
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
...@@ -67,6 +67,7 @@ typedef void(*embb_log_function_t)(void * context, char const * message); ...@@ -67,6 +67,7 @@ typedef void(*embb_log_function_t)(void * context, char const * message);
/** /**
* Default logging function. * Default logging function.
* Writes to the given file (context needs to be a FILE*). * Writes to the given file (context needs to be a FILE*).
* \pre \c context is not NULL.
* \ingroup C_LOG * \ingroup C_LOG
* \threadsafe * \threadsafe
*/ */
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
...@@ -73,6 +73,8 @@ extern "C" { ...@@ -73,6 +73,8 @@ extern "C" {
* *
* Keeps track of freed memory in debug mode. * Keeps track of freed memory in debug mode.
* *
* \pre \c ptr is not NULL.
*
* \threadsafe * \threadsafe
* *
* \see embb_get_bytes_allocated() * \see embb_get_bytes_allocated()
...@@ -161,6 +163,8 @@ extern "C" { ...@@ -161,6 +163,8 @@ extern "C" {
* *
* Keeps track of freed memory in debug mode. * Keeps track of freed memory in debug mode.
* *
* \pre \c ptr is not NULL and was allocated by an aligned method.
*
* \threadsafe * \threadsafe
* *
* \see embb_alloc_aligned(), embb_alloc_cache_aligned(), * \see embb_alloc_aligned(), embb_alloc_cache_aligned(),
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
...@@ -150,7 +150,7 @@ int embb_mutex_unlock( ...@@ -150,7 +150,7 @@ int embb_mutex_unlock(
/** /**
* Destroys a mutex and frees its resources. * Destroys a mutex and frees its resources.
* *
* \pre \c mutex has been initialized * \pre \c mutex is initialized and is not NULL.
* \post \c mutex is uninitialized * \post \c mutex is uninitialized
* \notthreadsafe * \notthreadsafe
* \see embb_mutex_init() * \see embb_mutex_init()
...@@ -233,7 +233,7 @@ int embb_spin_unlock( ...@@ -233,7 +233,7 @@ int embb_spin_unlock(
/** /**
* Destroys a spinlock and frees its resources. * Destroys a spinlock and frees its resources.
* *
* \pre \c spinlock has been initialized * \pre \c spinlock is initialized and is not NULL.
* \post \c spinlock is uninitialized * \post \c spinlock is uninitialized
* \notthreadsafe * \notthreadsafe
* \see embb_spin_init() * \see embb_spin_init()
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
...@@ -112,7 +112,7 @@ void* embb_tss_get( ...@@ -112,7 +112,7 @@ void* embb_tss_get(
* *
* Does not delete the values pointed to. * Does not delete the values pointed to.
* *
* \pre TSS has been created successfully * \pre \c tss has been created successfully and is not NULL.
* \post All slots are deleted * \post All slots are deleted
* \notthreadsafe * \notthreadsafe
* \see embb_tss_create() * \see embb_tss_create()
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
...@@ -89,6 +89,8 @@ int embb_time_in( ...@@ -89,6 +89,8 @@ int embb_time_in(
/** /**
* Compares two time points. * Compares two time points.
* *
* \pre \c lhs and \c rhs are not NULL and properly initialized.
*
* \return -1 if \c lhs < \c rhs \n * \return -1 if \c lhs < \c rhs \n
* 0 if \c lhs == \c rhs \n * 0 if \c lhs == \c rhs \n
* 1 if \c lhs > \c rhs * 1 if \c lhs > \c rhs
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
...@@ -114,7 +114,7 @@ define_or_assign @embb_internal__atomic_or_assign_1_asm@8, byte, dl ...@@ -114,7 +114,7 @@ define_or_assign @embb_internal__atomic_or_assign_1_asm@8, byte, dl
define_store macro name, size, value define_store macro name, size, value
public name public name
name proc name proc
mov size ptr [ecx], value xchg size ptr [ecx], value
ret ret
name endp name endp
endm endm
......
...@@ -107,7 +107,7 @@ define_or_assign embb_internal__atomic_or_assign_1_asm, byte, dl ...@@ -107,7 +107,7 @@ define_or_assign embb_internal__atomic_or_assign_1_asm, byte, dl
define_store macro name, size, value define_store macro name, size, value
public name public name
name proc name proc
mov size ptr [rcx], value xchg size ptr [rcx], value
ret ret
name endp name endp
endm endm
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
...@@ -33,8 +33,9 @@ ...@@ -33,8 +33,9 @@
int embb_condition_wait_for(embb_condition_t* condition_var, int embb_condition_wait_for(embb_condition_t* condition_var,
embb_mutex_t* mutex, embb_mutex_t* mutex,
const embb_duration_t* duration) { const embb_duration_t* duration) {
assert(condition_var != NULL); if (condition_var == NULL || mutex == NULL) {
assert(mutex != NULL); return EMBB_ERROR;
}
embb_time_t time; embb_time_t time;
int status = embb_time_in(&time, duration); int status = embb_time_in(&time, duration);
if (status != EMBB_SUCCESS) { if (status != EMBB_SUCCESS) {
...@@ -46,27 +47,34 @@ int embb_condition_wait_for(embb_condition_t* condition_var, ...@@ -46,27 +47,34 @@ int embb_condition_wait_for(embb_condition_t* condition_var,
#ifdef EMBB_PLATFORM_THREADING_WINTHREADS #ifdef EMBB_PLATFORM_THREADING_WINTHREADS
int embb_condition_init(embb_condition_t* condition_var) { int embb_condition_init(embb_condition_t* condition_var) {
assert(condition_var != NULL); if (condition_var == NULL) {
return EMBB_ERROR;
}
InitializeConditionVariable(condition_var); InitializeConditionVariable(condition_var);
return EMBB_SUCCESS; return EMBB_SUCCESS;
} }
int embb_condition_notify_one(embb_condition_t* condition_var) { int embb_condition_notify_one(embb_condition_t* condition_var) {
assert(condition_var != NULL); if (condition_var == NULL) {
return EMBB_ERROR;
}
WakeConditionVariable(condition_var); WakeConditionVariable(condition_var);
return EMBB_SUCCESS; return EMBB_SUCCESS;
} }
int embb_condition_notify_all(embb_condition_t* condition_var) { int embb_condition_notify_all(embb_condition_t* condition_var) {
assert(condition_var != NULL); if (condition_var == NULL) {
return EMBB_ERROR;
}
WakeAllConditionVariable(condition_var); WakeAllConditionVariable(condition_var);
return EMBB_SUCCESS; return EMBB_SUCCESS;
} }
int embb_condition_wait(embb_condition_t* condition_var, int embb_condition_wait(embb_condition_t* condition_var,
embb_mutex_t* mutex) { embb_mutex_t* mutex) {
assert(condition_var != NULL); if (condition_var == NULL || mutex == NULL) {
assert(mutex != NULL); return EMBB_ERROR;
}
if (SleepConditionVariableCS(condition_var, mutex, INFINITE)) { if (SleepConditionVariableCS(condition_var, mutex, INFINITE)) {
return EMBB_SUCCESS; return EMBB_SUCCESS;
} }
...@@ -75,9 +83,9 @@ int embb_condition_wait(embb_condition_t* condition_var, ...@@ -75,9 +83,9 @@ int embb_condition_wait(embb_condition_t* condition_var,
int embb_condition_wait_until(embb_condition_t* condition_var, int embb_condition_wait_until(embb_condition_t* condition_var,
embb_mutex_t* mutex, const embb_time_t* time) { embb_mutex_t* mutex, const embb_time_t* time) {
assert(condition_var != NULL); if (condition_var == NULL || mutex == NULL || time == NULL) {
assert(mutex != NULL); return EMBB_ERROR;
assert(time != NULL); }
/* The Windows API needs a time duration, so we need to convert the given time /* The Windows API needs a time duration, so we need to convert the given time
by using the time now. */ by using the time now. */
embb_time_t now; embb_time_t now;
...@@ -103,7 +111,9 @@ int embb_condition_wait_until(embb_condition_t* condition_var, ...@@ -103,7 +111,9 @@ int embb_condition_wait_until(embb_condition_t* condition_var,
} }
int embb_condition_destroy(embb_condition_t* condition_var) { int embb_condition_destroy(embb_condition_t* condition_var) {
assert(condition_var != NULL); if (condition_var == NULL) {
return EMBB_ERROR;
}
EMBB_UNUSED_IN_RELEASE(condition_var); EMBB_UNUSED_IN_RELEASE(condition_var);
return EMBB_SUCCESS; return EMBB_SUCCESS;
} }
...@@ -113,35 +123,42 @@ int embb_condition_destroy(embb_condition_t* condition_var) { ...@@ -113,35 +123,42 @@ int embb_condition_destroy(embb_condition_t* condition_var) {
#ifdef EMBB_PLATFORM_THREADING_POSIXTHREADS #ifdef EMBB_PLATFORM_THREADING_POSIXTHREADS
int embb_condition_init(embb_condition_t* condition_var) { int embb_condition_init(embb_condition_t* condition_var) {
assert(condition_var != NULL); if (condition_var == NULL) {
return EMBB_ERROR;
}
int result = pthread_cond_init(condition_var, NULL); int result = pthread_cond_init(condition_var, NULL);
return result == 0 ? EMBB_SUCCESS : EMBB_ERROR; return result == 0 ? EMBB_SUCCESS : EMBB_ERROR;
} }
int embb_condition_notify_one(embb_condition_t* condition_var) { int embb_condition_notify_one(embb_condition_t* condition_var) {
assert(condition_var != NULL); if (condition_var == NULL) {
return EMBB_ERROR;
}
int result = pthread_cond_signal(condition_var); int result = pthread_cond_signal(condition_var);
return result == 0 ? EMBB_SUCCESS : EMBB_ERROR; return result == 0 ? EMBB_SUCCESS : EMBB_ERROR;
} }
int embb_condition_notify_all(embb_condition_t* condition_var) { int embb_condition_notify_all(embb_condition_t* condition_var) {
assert(condition_var != NULL); if (condition_var == NULL) {
return EMBB_ERROR;
}
int result = pthread_cond_broadcast(condition_var); int result = pthread_cond_broadcast(condition_var);
return result == 0 ? EMBB_SUCCESS : EMBB_ERROR; return result == 0 ? EMBB_SUCCESS : EMBB_ERROR;
} }
int embb_condition_wait(embb_condition_t* condition_var, embb_mutex_t* mutex) { int embb_condition_wait(embb_condition_t* condition_var, embb_mutex_t* mutex) {
assert(condition_var != NULL); if (condition_var == NULL || mutex == NULL) {
assert(mutex != NULL); return EMBB_ERROR;
}
int result = pthread_cond_wait(condition_var, mutex); int result = pthread_cond_wait(condition_var, mutex);
return result == 0 ? EMBB_SUCCESS : EMBB_ERROR; return result == 0 ? EMBB_SUCCESS : EMBB_ERROR;
} }
int embb_condition_wait_until(embb_condition_t* condition_var, int embb_condition_wait_until(embb_condition_t* condition_var,
embb_mutex_t* mutex, const embb_time_t* time) { embb_mutex_t* mutex, const embb_time_t* time) {
assert(condition_var != NULL); if (condition_var == NULL || mutex == NULL || time == NULL) {
assert(mutex != NULL); return EMBB_ERROR;
assert(time != NULL); }
/* Convert EMBB time to Unix time format */ /* Convert EMBB time to Unix time format */
struct timespec unix_time; struct timespec unix_time;
unix_time.tv_sec = time->seconds; unix_time.tv_sec = time->seconds;
...@@ -157,7 +174,9 @@ int embb_condition_wait_until(embb_condition_t* condition_var, ...@@ -157,7 +174,9 @@ int embb_condition_wait_until(embb_condition_t* condition_var,
} }
int embb_condition_destroy(embb_condition_t* condition_var) { int embb_condition_destroy(embb_condition_t* condition_var) {
assert(condition_var != NULL); if (condition_var == NULL) {
return EMBB_ERROR;
}
int status = pthread_cond_destroy(condition_var); int status = pthread_cond_destroy(condition_var);
if (status != 0) { if (status != 0) {
return EMBB_ERROR; return EMBB_ERROR;
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
...@@ -146,13 +146,18 @@ int embb_core_set_contains(const embb_core_set_t* core_set, ...@@ -146,13 +146,18 @@ int embb_core_set_contains(const embb_core_set_t* core_set,
void embb_core_set_intersection(embb_core_set_t* set1, void embb_core_set_intersection(embb_core_set_t* set1,
const embb_core_set_t* set2) { const embb_core_set_t* set2) {
assert(set1 != NULL);
assert(set2 != NULL);
embb_bitset_intersect(&set1->rep, set2->rep); embb_bitset_intersect(&set1->rep, set2->rep);
} }
void embb_core_set_union(embb_core_set_t* set1, const embb_core_set_t* set2) { void embb_core_set_union(embb_core_set_t* set1, const embb_core_set_t* set2) {
assert(set1 != NULL);
assert(set2 != NULL);
embb_bitset_union(&set1->rep, set2->rep); embb_bitset_union(&set1->rep, set2->rep);
} }
unsigned int embb_core_set_count(const embb_core_set_t* core_set) { unsigned int embb_core_set_count(const embb_core_set_t* core_set) {
assert(core_set != NULL);
return embb_bitset_count(&core_set->rep); return embb_bitset_count(&core_set->rep);
} }
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
...@@ -30,7 +30,9 @@ ...@@ -30,7 +30,9 @@
#include <assert.h> #include <assert.h>
int embb_counter_init(embb_counter_t* counter) { int embb_counter_init(embb_counter_t* counter) {
assert(counter != NULL); if (counter == NULL) {
return EMBB_ERROR;
}
embb_atomic_store_unsigned_int(&(counter->value), 0); embb_atomic_store_unsigned_int(&(counter->value), 0);
return EMBB_SUCCESS; return EMBB_SUCCESS;
} }
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
...@@ -46,13 +46,19 @@ const embb_duration_t* embb_duration_zero() { ...@@ -46,13 +46,19 @@ const embb_duration_t* embb_duration_zero() {
int embb_duration_set_nanoseconds(embb_duration_t* duration, int embb_duration_set_nanoseconds(embb_duration_t* duration,
unsigned long long nanoseconds) { unsigned long long nanoseconds) {
assert(duration != NULL); if (duration == NULL) {
return EMBB_ERROR;
}
if (nanoseconds > 0) { if (nanoseconds > 0) {
if (embb_duration_min()->nanoseconds > nanoseconds) { if (embb_duration_min()->nanoseconds > nanoseconds) {
duration->seconds = 0;
duration->nanoseconds = 0;
return EMBB_UNDERFLOW; return EMBB_UNDERFLOW;
} }
const embb_duration_t* max = embb_duration_max(); const embb_duration_t* max = embb_duration_max();
if (max->seconds * 1000000000 + max->nanoseconds < nanoseconds) { if (max->seconds * 1000000000 + max->nanoseconds < nanoseconds) {
duration->seconds = max->seconds;
duration->nanoseconds = max->nanoseconds;
return EMBB_OVERFLOW; return EMBB_OVERFLOW;
} }
} }
...@@ -63,13 +69,19 @@ int embb_duration_set_nanoseconds(embb_duration_t* duration, ...@@ -63,13 +69,19 @@ int embb_duration_set_nanoseconds(embb_duration_t* duration,
int embb_duration_set_microseconds(embb_duration_t* duration, int embb_duration_set_microseconds(embb_duration_t* duration,
unsigned long long microseconds) { unsigned long long microseconds) {
assert(duration != NULL); if (duration == NULL) {
return EMBB_ERROR;
}
if (microseconds > 0) { if (microseconds > 0) {
if (embb_duration_min()->nanoseconds > microseconds*1000) { if (embb_duration_min()->nanoseconds > microseconds*1000) {
duration->seconds = 0;
duration->nanoseconds = 0;
return EMBB_UNDERFLOW; return EMBB_UNDERFLOW;
} }
const embb_duration_t* max = embb_duration_max(); const embb_duration_t* max = embb_duration_max();
if (max->seconds * 1000000 + max->nanoseconds / 1000 < microseconds) { if (max->seconds * 1000000 + max->nanoseconds / 1000 < microseconds) {
duration->seconds = max->seconds;
duration->nanoseconds = max->nanoseconds;
return EMBB_OVERFLOW; return EMBB_OVERFLOW;
} }
} }
...@@ -80,13 +92,19 @@ int embb_duration_set_microseconds(embb_duration_t* duration, ...@@ -80,13 +92,19 @@ int embb_duration_set_microseconds(embb_duration_t* duration,
int embb_duration_set_milliseconds(embb_duration_t* duration, int embb_duration_set_milliseconds(embb_duration_t* duration,
unsigned long long milliseconds) { unsigned long long milliseconds) {
assert(duration != NULL); if (duration == NULL) {
return EMBB_ERROR;
}
if (milliseconds > 0) { if (milliseconds > 0) {
if (embb_duration_min()->nanoseconds > milliseconds*1000000) { if (embb_duration_min()->nanoseconds > milliseconds*1000000) {
duration->seconds = 0;
duration->nanoseconds = 0;
return EMBB_UNDERFLOW; return EMBB_UNDERFLOW;
} }
const embb_duration_t* max = embb_duration_max(); const embb_duration_t* max = embb_duration_max();
if (max->seconds * 1000 + max->nanoseconds / 1000000 < milliseconds) { if (max->seconds * 1000 + max->nanoseconds / 1000000 < milliseconds) {
duration->seconds = max->seconds;
duration->nanoseconds = max->nanoseconds;
return EMBB_OVERFLOW; return EMBB_OVERFLOW;
} }
} }
...@@ -97,13 +115,19 @@ int embb_duration_set_milliseconds(embb_duration_t* duration, ...@@ -97,13 +115,19 @@ int embb_duration_set_milliseconds(embb_duration_t* duration,
int embb_duration_set_seconds(embb_duration_t* duration, int embb_duration_set_seconds(embb_duration_t* duration,
unsigned long long seconds) { unsigned long long seconds) {
assert(duration != NULL); if (duration == NULL) {
return EMBB_ERROR;
}
if (seconds > 0) { if (seconds > 0) {
if (embb_duration_min()->nanoseconds > seconds*1000000000) { if (embb_duration_min()->nanoseconds > seconds*1000000000) {
duration->seconds = 0;
duration->nanoseconds = 0;
return EMBB_UNDERFLOW; return EMBB_UNDERFLOW;
} }
const embb_duration_t* max = embb_duration_max(); const embb_duration_t* max = embb_duration_max();
if (max->seconds + max->nanoseconds / 1000000000 < seconds) { if (max->seconds + max->nanoseconds / 1000000000 < seconds) {
duration->seconds = max->seconds;
duration->nanoseconds = max->nanoseconds;
return EMBB_OVERFLOW; return EMBB_OVERFLOW;
} }
} }
...@@ -113,10 +137,13 @@ int embb_duration_set_seconds(embb_duration_t* duration, ...@@ -113,10 +137,13 @@ int embb_duration_set_seconds(embb_duration_t* duration,
} }
int embb_duration_add(embb_duration_t* lhs, const embb_duration_t* rhs) { int embb_duration_add(embb_duration_t* lhs, const embb_duration_t* rhs) {
assert(lhs != NULL); if (lhs == NULL || rhs == NULL) {
assert(rhs != NULL); return EMBB_ERROR;
}
int carry = (int)((lhs->nanoseconds + rhs->nanoseconds) / 1000000000); int carry = (int)((lhs->nanoseconds + rhs->nanoseconds) / 1000000000);
if (lhs->seconds + rhs->seconds + carry > EMBB_DURATION_MAX_SECONDS) { if (lhs->seconds + rhs->seconds + carry > EMBB_DURATION_MAX_SECONDS) {
lhs->seconds = 0;
lhs->nanoseconds = 0;
return EMBB_OVERFLOW; return EMBB_OVERFLOW;
} }
lhs->nanoseconds = (lhs->nanoseconds + rhs->nanoseconds) % 1000000000; lhs->nanoseconds = (lhs->nanoseconds + rhs->nanoseconds) % 1000000000;
...@@ -126,8 +153,9 @@ int embb_duration_add(embb_duration_t* lhs, const embb_duration_t* rhs) { ...@@ -126,8 +153,9 @@ int embb_duration_add(embb_duration_t* lhs, const embb_duration_t* rhs) {
int embb_duration_as_nanoseconds(const embb_duration_t* duration, int embb_duration_as_nanoseconds(const embb_duration_t* duration,
unsigned long long* nanoseconds) { unsigned long long* nanoseconds) {
assert(duration != NULL); if (duration == NULL || nanoseconds == NULL) {
assert(nanoseconds != NULL); return EMBB_ERROR;
}
if (duration->seconds*1000000000 + duration->nanoseconds > ULLONG_MAX) { if (duration->seconds*1000000000 + duration->nanoseconds > ULLONG_MAX) {
return EMBB_OVERFLOW; return EMBB_OVERFLOW;
} }
...@@ -137,8 +165,9 @@ int embb_duration_as_nanoseconds(const embb_duration_t* duration, ...@@ -137,8 +165,9 @@ int embb_duration_as_nanoseconds(const embb_duration_t* duration,
int embb_duration_as_microseconds(const embb_duration_t* duration, int embb_duration_as_microseconds(const embb_duration_t* duration,
unsigned long long* microseconds) { unsigned long long* microseconds) {
assert(duration != NULL); if (duration == NULL || microseconds == NULL) {
assert(microseconds != NULL); return EMBB_ERROR;
}
if (duration->nanoseconds % 1000 > 0) { if (duration->nanoseconds % 1000 > 0) {
return EMBB_UNDERFLOW; return EMBB_UNDERFLOW;
} }
...@@ -151,8 +180,9 @@ int embb_duration_as_microseconds(const embb_duration_t* duration, ...@@ -151,8 +180,9 @@ int embb_duration_as_microseconds(const embb_duration_t* duration,
int embb_duration_as_milliseconds(const embb_duration_t* duration, int embb_duration_as_milliseconds(const embb_duration_t* duration,
unsigned long long* milliseconds) { unsigned long long* milliseconds) {
assert(duration != NULL); if (duration == NULL || milliseconds == NULL) {
assert(milliseconds != NULL); return EMBB_ERROR;
}
if (duration->nanoseconds % 1000000 > 0) { if (duration->nanoseconds % 1000000 > 0) {
return EMBB_UNDERFLOW; return EMBB_UNDERFLOW;
} }
...@@ -165,12 +195,12 @@ int embb_duration_as_milliseconds(const embb_duration_t* duration, ...@@ -165,12 +195,12 @@ int embb_duration_as_milliseconds(const embb_duration_t* duration,
int embb_duration_as_seconds(const embb_duration_t* duration, int embb_duration_as_seconds(const embb_duration_t* duration,
unsigned long long* seconds) { unsigned long long* seconds) {
assert(duration != NULL); if (duration == NULL || seconds == NULL) {
assert(seconds != NULL); return EMBB_ERROR;
}
if (duration->nanoseconds % 1000000000 > 0) { if (duration->nanoseconds % 1000000000 > 0) {
return EMBB_UNDERFLOW; return EMBB_UNDERFLOW;
} }
assert(duration->nanoseconds % 1000000000 == 0);
if (duration->seconds > ULLONG_MAX) { if (duration->seconds > ULLONG_MAX) {
return EMBB_OVERFLOW; return EMBB_OVERFLOW;
} }
...@@ -180,11 +210,8 @@ int embb_duration_as_seconds(const embb_duration_t* duration, ...@@ -180,11 +210,8 @@ int embb_duration_as_seconds(const embb_duration_t* duration,
int embb_duration_compare(const embb_duration_t* lhs, int embb_duration_compare(const embb_duration_t* lhs,
const embb_duration_t* rhs) { const embb_duration_t* rhs) {
assert(lhs != NULL); assert(lhs != NULL && rhs != NULL);
assert(rhs != NULL); assert(lhs->nanoseconds < 1000000000 && rhs->nanoseconds < 1000000000);
assert(lhs->nanoseconds < 1000000000);
assert(rhs->nanoseconds < 1000000000);
if (lhs->seconds > rhs->seconds) { if (lhs->seconds > rhs->seconds) {
return 1; return 1;
} else if (lhs->seconds < rhs->seconds) { } else if (lhs->seconds < rhs->seconds) {
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#include <assert.h>
#include <embb/base/c/log.h> #include <embb/base/c/log.h>
...@@ -35,6 +36,7 @@ ...@@ -35,6 +36,7 @@
void embb_log_write_file( void embb_log_write_file(
void * context, void * context,
char const * message) { char const * message) {
assert(context != NULL);
FILE * ff = (FILE*)context; FILE * ff = (FILE*)context;
fprintf(ff, "%s", message); fprintf(ff, "%s", message);
fflush(ff); fflush(ff);
...@@ -90,7 +92,6 @@ void embb_log_write_internal( ...@@ -90,7 +92,6 @@ void embb_log_write_internal(
case EMBB_LOG_LEVEL_NONE: case EMBB_LOG_LEVEL_NONE:
default: default:
log_level_str = " ";
break; break;
} }
#if defined(EMBB_PLATFORM_COMPILER_MSVC) #if defined(EMBB_PLATFORM_COMPILER_MSVC)
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
...@@ -135,6 +135,7 @@ void* embb_alloc_aligned(size_t alignment, size_t size) { ...@@ -135,6 +135,7 @@ void* embb_alloc_aligned(size_t alignment, size_t size) {
void embb_free_aligned(void* ptr) { void embb_free_aligned(void* ptr) {
assert(ptr != NULL); assert(ptr != NULL);
size_t* ptr_conv = (size_t*)ptr; size_t* ptr_conv = (size_t*)ptr;
// If embb_free_aligned is called, the memory block should have been allocated // If embb_free_aligned is called, the memory block should have been allocated
...@@ -193,6 +194,8 @@ void *embb_alloc_aligned(size_t alignment, size_t size) { ...@@ -193,6 +194,8 @@ void *embb_alloc_aligned(size_t alignment, size_t size) {
} }
void embb_free_aligned(void* ptr) { void embb_free_aligned(void* ptr) {
assert(ptr != NULL);
#ifdef EMBB_PLATFORM_COMPILER_MSVC #ifdef EMBB_PLATFORM_COMPILER_MSVC
_aligned_free(ptr); _aligned_free(ptr);
#else #else
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
...@@ -33,6 +33,9 @@ ...@@ -33,6 +33,9 @@
#ifdef EMBB_PLATFORM_THREADING_WINTHREADS #ifdef EMBB_PLATFORM_THREADING_WINTHREADS
int embb_mutex_init(embb_mutex_t* mutex, int type) { int embb_mutex_init(embb_mutex_t* mutex, int type) {
if (NULL == mutex) {
return EMBB_ERROR;
}
/* Critical sections in Windows are always recursive */ /* Critical sections in Windows are always recursive */
InitializeCriticalSection(mutex); InitializeCriticalSection(mutex);
EMBB_UNUSED(type); EMBB_UNUSED(type);
...@@ -40,11 +43,17 @@ int embb_mutex_init(embb_mutex_t* mutex, int type) { ...@@ -40,11 +43,17 @@ int embb_mutex_init(embb_mutex_t* mutex, int type) {
} }
int embb_mutex_lock(embb_mutex_t* mutex) { int embb_mutex_lock(embb_mutex_t* mutex) {
if (NULL == mutex) {
return EMBB_ERROR;
}
EnterCriticalSection(mutex); EnterCriticalSection(mutex);
return EMBB_SUCCESS; return EMBB_SUCCESS;
} }
int embb_mutex_try_lock(embb_mutex_t* mutex) { int embb_mutex_try_lock(embb_mutex_t* mutex) {
if (NULL == mutex) {
return EMBB_ERROR;
}
BOOL success; BOOL success;
success = TryEnterCriticalSection(mutex); success = TryEnterCriticalSection(mutex);
if (success == FALSE) return EMBB_ERROR; if (success == FALSE) return EMBB_ERROR;
...@@ -52,11 +61,15 @@ int embb_mutex_try_lock(embb_mutex_t* mutex) { ...@@ -52,11 +61,15 @@ int embb_mutex_try_lock(embb_mutex_t* mutex) {
} }
int embb_mutex_unlock(embb_mutex_t* mutex) { int embb_mutex_unlock(embb_mutex_t* mutex) {
if (NULL == mutex) {
return EMBB_ERROR;
}
LeaveCriticalSection(mutex); LeaveCriticalSection(mutex);
return EMBB_SUCCESS; return EMBB_SUCCESS;
} }
void embb_mutex_destroy(embb_mutex_t* mutex) { void embb_mutex_destroy(embb_mutex_t* mutex) {
assert(NULL != mutex);
DeleteCriticalSection(mutex); DeleteCriticalSection(mutex);
} }
...@@ -65,6 +78,9 @@ void embb_mutex_destroy(embb_mutex_t* mutex) { ...@@ -65,6 +78,9 @@ void embb_mutex_destroy(embb_mutex_t* mutex) {
#ifdef EMBB_PLATFORM_THREADING_POSIXTHREADS #ifdef EMBB_PLATFORM_THREADING_POSIXTHREADS
int embb_mutex_init(embb_mutex_t* mutex, int type) { int embb_mutex_init(embb_mutex_t* mutex, int type) {
if (NULL == mutex) {
return EMBB_ERROR;
}
if (type == EMBB_MUTEX_PLAIN) { if (type == EMBB_MUTEX_PLAIN) {
if (pthread_mutex_init(mutex, NULL) != 0) return EMBB_ERROR; if (pthread_mutex_init(mutex, NULL) != 0) return EMBB_ERROR;
} else { } else {
...@@ -85,6 +101,9 @@ int embb_mutex_init(embb_mutex_t* mutex, int type) { ...@@ -85,6 +101,9 @@ int embb_mutex_init(embb_mutex_t* mutex, int type) {
} }
int embb_mutex_lock(embb_mutex_t* mutex) { int embb_mutex_lock(embb_mutex_t* mutex) {
if (NULL == mutex) {
return EMBB_ERROR;
}
int result = pthread_mutex_lock(mutex); int result = pthread_mutex_lock(mutex);
if (result != 0) { if (result != 0) {
return EMBB_ERROR; return EMBB_ERROR;
...@@ -93,6 +112,9 @@ int embb_mutex_lock(embb_mutex_t* mutex) { ...@@ -93,6 +112,9 @@ int embb_mutex_lock(embb_mutex_t* mutex) {
} }
int embb_mutex_try_lock(embb_mutex_t* mutex) { int embb_mutex_try_lock(embb_mutex_t* mutex) {
if (NULL == mutex) {
return EMBB_ERROR;
}
int result = pthread_mutex_trylock(mutex); int result = pthread_mutex_trylock(mutex);
if (result == 0) { if (result == 0) {
return EMBB_SUCCESS; return EMBB_SUCCESS;
...@@ -104,6 +126,9 @@ int embb_mutex_try_lock(embb_mutex_t* mutex) { ...@@ -104,6 +126,9 @@ int embb_mutex_try_lock(embb_mutex_t* mutex) {
} }
int embb_mutex_unlock(embb_mutex_t* mutex) { int embb_mutex_unlock(embb_mutex_t* mutex) {
if (NULL == mutex) {
return EMBB_ERROR;
}
int result = pthread_mutex_unlock(mutex); int result = pthread_mutex_unlock(mutex);
if (result != 0) { if (result != 0) {
return EMBB_ERROR; return EMBB_ERROR;
...@@ -112,12 +137,16 @@ int embb_mutex_unlock(embb_mutex_t* mutex) { ...@@ -112,12 +137,16 @@ int embb_mutex_unlock(embb_mutex_t* mutex) {
} }
void embb_mutex_destroy(embb_mutex_t* mutex) { void embb_mutex_destroy(embb_mutex_t* mutex) {
assert(NULL != mutex);
pthread_mutex_destroy(mutex); pthread_mutex_destroy(mutex);
} }
#endif /* EMBB_PLATFORM_THREADING_POSIXTHREADS */ #endif /* EMBB_PLATFORM_THREADING_POSIXTHREADS */
int embb_spin_init(embb_spinlock_t* spinlock) { int embb_spin_init(embb_spinlock_t* spinlock) {
if (NULL == spinlock) {
return EMBB_ERROR;
}
// For now, store the initial value. In the future will use atomic init // For now, store the initial value. In the future will use atomic init
// function (as soon as available). // function (as soon as available).
embb_atomic_store_int(&spinlock->atomic_spin_variable_, 0); embb_atomic_store_int(&spinlock->atomic_spin_variable_, 0);
...@@ -125,6 +154,9 @@ int embb_spin_init(embb_spinlock_t* spinlock) { ...@@ -125,6 +154,9 @@ int embb_spin_init(embb_spinlock_t* spinlock) {
} }
int embb_spin_lock(embb_spinlock_t* spinlock) { int embb_spin_lock(embb_spinlock_t* spinlock) {
if (NULL == spinlock) {
return EMBB_ERROR;
}
int expected = 0; int expected = 0;
int spins = 1; int spins = 1;
...@@ -143,6 +175,9 @@ int embb_spin_lock(embb_spinlock_t* spinlock) { ...@@ -143,6 +175,9 @@ int embb_spin_lock(embb_spinlock_t* spinlock) {
int embb_spin_try_lock(embb_spinlock_t* spinlock, int embb_spin_try_lock(embb_spinlock_t* spinlock,
unsigned int max_number_spins) { unsigned int max_number_spins) {
if (NULL == spinlock) {
return EMBB_ERROR;
}
if (max_number_spins == 0) if (max_number_spins == 0)
return EMBB_BUSY; return EMBB_BUSY;
...@@ -161,6 +196,9 @@ int embb_spin_try_lock(embb_spinlock_t* spinlock, ...@@ -161,6 +196,9 @@ int embb_spin_try_lock(embb_spinlock_t* spinlock,
} }
int embb_spin_unlock(embb_spinlock_t* spinlock) { int embb_spin_unlock(embb_spinlock_t* spinlock) {
if (NULL == spinlock) {
return EMBB_ERROR;
}
int expected = 1; int expected = 1;
return embb_atomic_compare_and_swap_int(&spinlock->atomic_spin_variable_, return embb_atomic_compare_and_swap_int(&spinlock->atomic_spin_variable_,
&expected, 0) ? &expected, 0) ?
...@@ -168,6 +206,7 @@ int embb_spin_unlock(embb_spinlock_t* spinlock) { ...@@ -168,6 +206,7 @@ int embb_spin_unlock(embb_spinlock_t* spinlock) {
} }
void embb_spin_destroy(embb_spinlock_t* spinlock) { void embb_spin_destroy(embb_spinlock_t* spinlock) {
assert(NULL != spinlock);
// for now, doing nothing here... in future, will call the respective // for now, doing nothing here... in future, will call the respective
// destroy function for atomics... // destroy function for atomics...
EMBB_UNUSED(spinlock); EMBB_UNUSED(spinlock);
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
...@@ -80,10 +80,15 @@ void embb_thread_yield() { ...@@ -80,10 +80,15 @@ void embb_thread_yield() {
int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set, int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set,
embb_thread_start_t func, void *arg) { embb_thread_start_t func, void *arg) {
assert(thread != NULL); if (thread == NULL) {
return EMBB_ERROR;
}
thread->embb_internal_arg = (embb_internal_thread_arg_t*) thread->embb_internal_arg = (embb_internal_thread_arg_t*)
embb_alloc(sizeof(embb_internal_thread_arg_t)); embb_alloc(sizeof(embb_internal_thread_arg_t));
if (thread->embb_internal_arg == NULL) return EMBB_NOMEM; if (thread->embb_internal_arg == NULL) {
thread->embb_internal_handle = NULL;
return EMBB_NOMEM;
}
thread->embb_internal_arg->func = func; thread->embb_internal_arg->func = func;
thread->embb_internal_arg->arg = arg; thread->embb_internal_arg->arg = arg;
...@@ -95,6 +100,8 @@ int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set, ...@@ -95,6 +100,8 @@ int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set,
0, /* no creation arguments */ 0, /* no creation arguments */
0); /* no system thread ID */ 0); /* no system thread ID */
if (thread->embb_internal_handle == NULL) { if (thread->embb_internal_handle == NULL) {
embb_free(thread->embb_internal_arg);
thread->embb_internal_arg = NULL;
return EMBB_ERROR; return EMBB_ERROR;
} }
...@@ -118,6 +125,9 @@ int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set, ...@@ -118,6 +125,9 @@ int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set,
} }
int embb_thread_join(embb_thread_t* thread, int* result_code) { int embb_thread_join(embb_thread_t* thread, int* result_code) {
if (thread == NULL) {
return EMBB_ERROR;
}
BOOL success; BOOL success;
DWORD result; DWORD result;
result = WaitForSingleObject(thread->embb_internal_handle, INFINITE); result = WaitForSingleObject(thread->embb_internal_handle, INFINITE);
...@@ -143,6 +153,9 @@ int embb_thread_join(embb_thread_t* thread, int* result_code) { ...@@ -143,6 +153,9 @@ int embb_thread_join(embb_thread_t* thread, int* result_code) {
} }
int embb_thread_equal(const embb_thread_t* lhs, const embb_thread_t* rhs) { int embb_thread_equal(const embb_thread_t* lhs, const embb_thread_t* rhs) {
if (lhs == NULL || rhs == NULL) {
return 0;
}
embb_thread_id_t idLhs = GetThreadId(lhs->embb_internal_handle); embb_thread_id_t idLhs = GetThreadId(lhs->embb_internal_handle);
embb_thread_id_t idRhs = GetThreadId(rhs->embb_internal_handle); embb_thread_id_t idRhs = GetThreadId(rhs->embb_internal_handle);
if (idLhs == idRhs) { if (idLhs == idRhs) {
...@@ -203,6 +216,9 @@ void embb_thread_yield() { ...@@ -203,6 +216,9 @@ void embb_thread_yield() {
int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set, int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set,
embb_thread_start_t func, void* arg) { embb_thread_start_t func, void* arg) {
if (thread == NULL) {
return EMBB_ERROR;
}
pthread_attr_t attr; /* Used to set thread affinities */ pthread_attr_t attr; /* Used to set thread affinities */
int status = pthread_attr_init(&attr); int status = pthread_attr_init(&attr);
if (status != 0) return EMBB_ERROR; if (status != 0) return EMBB_ERROR;
...@@ -223,7 +239,11 @@ int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set, ...@@ -223,7 +239,11 @@ int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set,
} }
} }
status = pthread_attr_setaffinity_np(&attr, sizeof(cpuset), &cpuset); status = pthread_attr_setaffinity_np(&attr, sizeof(cpuset), &cpuset);
if (status != 0) return EMBB_ERROR; if (status != 0) {
thread->embb_internal_arg = NULL;
thread->embb_internal_handle = 0;
return EMBB_ERROR;
}
#else #else
embb_log_write("base_c", EMBB_LOG_LEVEL_WARNING, "Could not set thread " embb_log_write("base_c", EMBB_LOG_LEVEL_WARNING, "Could not set thread "
"affinity, since no implementation available!\n"); "affinity, since no implementation available!\n");
...@@ -233,6 +253,11 @@ int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set, ...@@ -233,6 +253,11 @@ int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set,
/* Dynamic allocation of thread arguments. Freed on call of join. */ /* Dynamic allocation of thread arguments. Freed on call of join. */
thread->embb_internal_arg = (embb_internal_thread_arg_t*) thread->embb_internal_arg = (embb_internal_thread_arg_t*)
embb_alloc(sizeof(embb_internal_thread_arg_t)); embb_alloc(sizeof(embb_internal_thread_arg_t));
if (thread->embb_internal_arg == NULL) {
thread->embb_internal_handle = 0;
pthread_attr_destroy(&attr);
return EMBB_NOMEM;
}
thread->embb_internal_arg->func = func; thread->embb_internal_arg->func = func;
thread->embb_internal_arg->arg = arg; thread->embb_internal_arg->arg = arg;
...@@ -250,12 +275,17 @@ int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set, ...@@ -250,12 +275,17 @@ int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set,
} }
int embb_thread_join(embb_thread_t* thread, int *result_code) { int embb_thread_join(embb_thread_t* thread, int *result_code) {
if (thread == NULL) {
return EMBB_ERROR;
}
int status = 0; int status = 0;
status = pthread_join(thread->embb_internal_handle, NULL); status = pthread_join(thread->embb_internal_handle, NULL);
if (thread->embb_internal_arg != NULL) {
if (result_code != NULL) { if (result_code != NULL) {
*result_code = thread->embb_internal_arg->result; *result_code = thread->embb_internal_arg->result;
} }
embb_free(thread->embb_internal_arg); embb_free(thread->embb_internal_arg);
}
if (status != 0) { if (status != 0) {
return EMBB_ERROR; return EMBB_ERROR;
} }
...@@ -263,6 +293,9 @@ int embb_thread_join(embb_thread_t* thread, int *result_code) { ...@@ -263,6 +293,9 @@ int embb_thread_join(embb_thread_t* thread, int *result_code) {
} }
int embb_thread_equal(const embb_thread_t* lhs, const embb_thread_t* rhs) { int embb_thread_equal(const embb_thread_t* lhs, const embb_thread_t* rhs) {
if (lhs == NULL || rhs == NULL) {
return 0;
}
return pthread_equal(lhs->embb_internal_handle, rhs->embb_internal_handle); return pthread_equal(lhs->embb_internal_handle, rhs->embb_internal_handle);
} }
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
...@@ -32,7 +32,9 @@ ...@@ -32,7 +32,9 @@
#include <assert.h> #include <assert.h>
int embb_tss_create(embb_tss_t* tss) { int embb_tss_create(embb_tss_t* tss) {
assert(tss != NULL); if (tss == NULL) {
return EMBB_ERROR;
}
tss->size = embb_thread_get_max_count(); tss->size = embb_thread_get_max_count();
tss->values = (void**) embb_alloc_cache_aligned(tss->size * sizeof(void*)); tss->values = (void**) embb_alloc_cache_aligned(tss->size * sizeof(void*));
if (tss->values == NULL) { if (tss->values == NULL) {
...@@ -45,7 +47,9 @@ int embb_tss_create(embb_tss_t* tss) { ...@@ -45,7 +47,9 @@ int embb_tss_create(embb_tss_t* tss) {
} }
int embb_tss_set(embb_tss_t* tss, void* value) { int embb_tss_set(embb_tss_t* tss, void* value) {
assert(tss != NULL); if (tss == NULL) {
return EMBB_ERROR;
}
unsigned int index = 0; unsigned int index = 0;
int status = embb_internal_thread_index(&index); int status = embb_internal_thread_index(&index);
if ((status != EMBB_SUCCESS) || (index >= tss->size)) { if ((status != EMBB_SUCCESS) || (index >= tss->size)) {
...@@ -56,8 +60,12 @@ int embb_tss_set(embb_tss_t* tss, void* value) { ...@@ -56,8 +60,12 @@ int embb_tss_set(embb_tss_t* tss, void* value) {
} }
void* embb_tss_get(const embb_tss_t* tss) { void* embb_tss_get(const embb_tss_t* tss) {
assert(tss != NULL); if (tss == NULL) {
assert(tss->values != NULL); return NULL;
}
if (tss->values == NULL) {
return NULL;
}
unsigned int index = 0; unsigned int index = 0;
int status = embb_internal_thread_index(&index); int status = embb_internal_thread_index(&index);
if ((status != EMBB_SUCCESS) || (index >= tss->size)) { if ((status != EMBB_SUCCESS) || (index >= tss->size)) {
...@@ -68,5 +76,7 @@ void* embb_tss_get(const embb_tss_t* tss) { ...@@ -68,5 +76,7 @@ void* embb_tss_get(const embb_tss_t* tss) {
void embb_tss_delete(embb_tss_t* tss) { void embb_tss_delete(embb_tss_t* tss) {
assert(tss != NULL); assert(tss != NULL);
if (tss->values != NULL) {
embb_free_aligned(tss->values); embb_free_aligned(tss->values);
}
} }
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
...@@ -33,11 +33,8 @@ void embb_time_now(embb_time_t* time) { ...@@ -33,11 +33,8 @@ void embb_time_now(embb_time_t* time) {
} }
int embb_time_compare(const embb_time_t* lhs, const embb_time_t* rhs) { int embb_time_compare(const embb_time_t* lhs, const embb_time_t* rhs) {
assert(lhs != NULL); assert(lhs != NULL && rhs != NULL);
assert(rhs != NULL); assert(lhs->nanoseconds < 1000000000 && rhs->nanoseconds < 1000000000);
assert(lhs->nanoseconds < 1000000000);
assert(rhs->nanoseconds < 1000000000);
if (lhs->seconds > rhs->seconds) { if (lhs->seconds > rhs->seconds) {
return 1; return 1;
} else if (lhs->seconds < rhs->seconds) { } else if (lhs->seconds < rhs->seconds) {
...@@ -56,8 +53,9 @@ int embb_time_compare(const embb_time_t* lhs, const embb_time_t* rhs) { ...@@ -56,8 +53,9 @@ int embb_time_compare(const embb_time_t* lhs, const embb_time_t* rhs) {
#ifdef EMBB_PLATFORM_THREADING_WINTHREADS #ifdef EMBB_PLATFORM_THREADING_WINTHREADS
int embb_time_in(embb_time_t* time, const embb_duration_t* duration) { int embb_time_in(embb_time_t* time, const embb_duration_t* duration) {
assert(time != NULL); if (time == NULL || duration == NULL) {
assert(duration != NULL); return EMBB_ERROR;
}
/* Get system time */ /* Get system time */
SYSTEMTIME system_time; SYSTEMTIME system_time;
GetLocalTime(&system_time); GetLocalTime(&system_time);
...@@ -87,8 +85,9 @@ int embb_time_in(embb_time_t* time, const embb_duration_t* duration) { ...@@ -87,8 +85,9 @@ int embb_time_in(embb_time_t* time, const embb_duration_t* duration) {
#ifdef EMBB_PLATFORM_THREADING_POSIXTHREADS #ifdef EMBB_PLATFORM_THREADING_POSIXTHREADS
int embb_time_in(embb_time_t* time, const embb_duration_t* duration) { int embb_time_in(embb_time_t* time, const embb_duration_t* duration) {
assert(time != NULL); if (time == NULL || duration == NULL) {
assert(duration != NULL); return EMBB_ERROR;
}
struct timespec unix_time; struct timespec unix_time;
clock_gettime(CLOCK_REALTIME, &unix_time); clock_gettime(CLOCK_REALTIME, &unix_time);
time->seconds = unix_time.tv_sec; time->seconds = unix_time.tv_sec;
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
...@@ -152,6 +152,9 @@ void AllocTest::TestMixedAllocs() { ...@@ -152,6 +152,9 @@ void AllocTest::TestMixedAllocs() {
void* plain = NULL; void* plain = NULL;
plain = embb_alloc(2); plain = embb_alloc(2);
PT_EXPECT_NE(plain, static_cast<void*>(NULL)); PT_EXPECT_NE(plain, static_cast<void*>(NULL));
if (NULL == plain) {
return;
}
allocated = embb_get_bytes_allocated(); allocated = embb_get_bytes_allocated();
#ifdef EMBB_DEBUG #ifdef EMBB_DEBUG
expected += 2 + 2*sizeof(size_t); expected += 2 + 2*sizeof(size_t);
...@@ -162,6 +165,10 @@ void AllocTest::TestMixedAllocs() { ...@@ -162,6 +165,10 @@ void AllocTest::TestMixedAllocs() {
void* aligned = NULL; void* aligned = NULL;
aligned = embb_alloc_aligned(2*sizeof(void*), 2); aligned = embb_alloc_aligned(2*sizeof(void*), 2);
PT_EXPECT_NE(aligned, static_cast<void*>(NULL)); PT_EXPECT_NE(aligned, static_cast<void*>(NULL));
if (NULL == aligned) {
embb_free(plain);
return;
}
allocated = embb_get_bytes_allocated(); allocated = embb_get_bytes_allocated();
#ifdef EMBB_DEBUG #ifdef EMBB_DEBUG
expected += (1 + 1) * 2 * sizeof(void*) + 3 * sizeof(size_t) - 1; expected += (1 + 1) * 2 * sizeof(void*) + 3 * sizeof(size_t) - 1;
...@@ -172,6 +179,11 @@ void AllocTest::TestMixedAllocs() { ...@@ -172,6 +179,11 @@ void AllocTest::TestMixedAllocs() {
void* cache_aligned = NULL; void* cache_aligned = NULL;
cache_aligned = embb_alloc_cache_aligned(2); cache_aligned = embb_alloc_cache_aligned(2);
PT_EXPECT_NE(cache_aligned, static_cast<void*>(NULL)); PT_EXPECT_NE(cache_aligned, static_cast<void*>(NULL));
if (NULL == cache_aligned) {
embb_free(plain);
embb_free_aligned(aligned);
return;
}
allocated = embb_get_bytes_allocated(); allocated = embb_get_bytes_allocated();
#ifdef EMBB_DEBUG #ifdef EMBB_DEBUG
expected += (1 + 1) * EMBB_PLATFORM_CACHE_LINE_SIZE + 3 * sizeof(size_t) - 1; expected += (1 + 1) * EMBB_PLATFORM_CACHE_LINE_SIZE + 3 * sizeof(size_t) - 1;
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
/* /*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved. * Copyright (c) 2014-2016, Siemens AG. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
......
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