/*
 * 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_C_INTERNAL_ATOMIC_SIZES_H_
#define EMBB_BASE_C_INTERNAL_ATOMIC_SIZES_H_

#include <embb/base/c/internal/cmake_config.h>
#include <stdint.h>

typedef uint8_t EMBB_BASE_BASIC_TYPE_SIZE_1;
typedef uint16_t EMBB_BASE_BASIC_TYPE_SIZE_2;
typedef uint32_t EMBB_BASE_BASIC_TYPE_SIZE_4;
typedef uint64_t EMBB_BASE_BASIC_TYPE_SIZE_8;

/**
 * CMake is used to set the correct size for types used in the atomic
 * library.
 *
 */
#define EMBB_CHAR_TYPE_SIZE ${EMBB_CHAR_TYPE_SIZE}
#define EMBB_SHORT_TYPE_SIZE ${EMBB_SHORT_TYPE_SIZE}
#define EMBB_UNSIGNED_SHORT_TYPE_SIZE ${EMBB_UNSIGNED_SHORT_TYPE_SIZE}
#define EMBB_INT_TYPE_SIZE ${EMBB_INT_TYPE_SIZE}
#define EMBB_UNSIGNED_INT_TYPE_SIZE ${EMBB_UNSIGNED_INT_TYPE_SIZE}
#define EMBB_LONG_TYPE_SIZE ${EMBB_LONG_TYPE_SIZE}
#define EMBB_UNSIGNED_LONG_TYPE_SIZE ${EMBB_UNSIGNED_LONG_TYPE_SIZE}
#define EMBB_LONG_LONG_TYPE_SIZE ${EMBB_LONG_LONG_TYPE_SIZE}
#define EMBB_UNSIGNED_LONG_LONG_TYPE_SIZE ${EMBB_UNSIGNED_LONG_LONG_TYPE_SIZE}
#define EMBB_INTPTR_T_TYPE_SIZE ${EMBB_INTPTR_T_TYPE_SIZE}
#define EMBB_UINTPTR_T_TYPE_SIZE ${EMBB_UINTPTR_T_TYPE_SIZE}
#define EMBB_SIZE_T_TYPE_SIZE ${EMBB_SIZE_T_TYPE_SIZE}
#define EMBB_PTRDIFF_T_TYPE_SIZE ${EMBB_PTRDIFF_T_TYPE_SIZE}
#define EMBB_UINTMAX_T_TYPE_SIZE ${EMBB_UINTMAX_T_TYPE_SIZE}


#ifdef EMBB_PLATFORM_ARCH_X86_64
#  define EMBB_64_BIT_ATOMIC_AVAILABLE_VAL 1
#  define EMBB_64_BIT_ATOMIC_AVAILABLE
#else
#  define EMBB_64_BIT_ATOMIC_AVAILABLE_VAL 0
#endif

#if( (EMBB_CHAR_TYPE_SIZE < 8) || (EMBB_64_BIT_ATOMIC_AVAILABLE_VAL == 1) )
#  define EMBB_CHAR_TYPE_IS_ATOMIC
#endif

#if( (EMBB_SHORT_TYPE_SIZE < 8) || (EMBB_64_BIT_ATOMIC_AVAILABLE_VAL == 1) )
#  define EMBB_SHORT_TYPE_IS_ATOMIC
#endif

#if( (EMBB_UNSIGNED_SHORT_TYPE_SIZE < 8) || (EMBB_64_BIT_ATOMIC_AVAILABLE_VAL == 1) )
#  define EMBB_UNSIGNED_SHORT_TYPE_IS_ATOMIC
#endif

#if( (EMBB_INT_TYPE_SIZE < 8) || (EMBB_64_BIT_ATOMIC_AVAILABLE_VAL == 1) )
#  define EMBB_INT_TYPE_IS_ATOMIC
#endif

#if( (EMBB_UNSIGNED_INT_TYPE_SIZE < 8) || (EMBB_64_BIT_ATOMIC_AVAILABLE_VAL == 1) )
#  define EMBB_UNSIGNED_INT_TYPE_IS_ATOMIC
#endif

#if( (EMBB_LONG_TYPE_SIZE < 8) || (EMBB_64_BIT_ATOMIC_AVAILABLE_VAL == 1) )
#  define EMBB_LONG_TYPE_IS_ATOMIC
#endif

#if( (EMBB_UNSIGNED_LONG_TYPE_SIZE < 8) || (EMBB_64_BIT_ATOMIC_AVAILABLE_VAL == 1) )
#  define EMBB_UNSIGNED_LONG_TYPE_IS_ATOMIC
#endif

#if( (EMBB_LONG_LONG_TYPE_SIZE < 8) || (EMBB_64_BIT_ATOMIC_AVAILABLE_VAL == 1) )
#  define EMBB_LONG_LONG_TYPE_IS_ATOMIC
#endif

#if( (EMBB_UNSIGNED_LONG_LONG_TYPE_SIZE < 8) || (EMBB_64_BIT_ATOMIC_AVAILABLE_VAL == 1) )
#  define EMBB_UNSIGNED_LONG_LONG_TYPE_IS_ATOMIC
#endif

#if( (EMBB_INTPTR_T_TYPE_SIZE < 8) || (EMBB_64_BIT_ATOMIC_AVAILABLE_VAL == 1) )
#  define EMBB_INTPTR_T_TYPE_IS_ATOMIC
#endif

#if( (EMBB_UINTPTR_T_TYPE_SIZE < 8) || (EMBB_64_BIT_ATOMIC_AVAILABLE_VAL == 1) )
#  define EMBB_UINTPTR_T_TYPE_IS_ATOMIC
#endif

#if( (EMBB_SIZE_T_TYPE_SIZE < 8) || (EMBB_64_BIT_ATOMIC_AVAILABLE_VAL == 1) )
#  define EMBB_SIZE_T_TYPE_IS_ATOMIC
#endif

#if( (EMBB_PTRDIFF_T_TYPE_SIZE < 8) || (EMBB_64_BIT_ATOMIC_AVAILABLE_VAL == 1) )
#  define EMBB_PTRDIFF_T_TYPE_IS_ATOMIC
#endif

#if( (EMBB_UINTMAX_T_TYPE_SIZE < 8) || (EMBB_64_BIT_ATOMIC_AVAILABLE_VAL == 1) )
#  define EMBB_UINTMAX_T_TYPE_IS_ATOMIC
#endif

#endif //EMBB_BASE_C_INTERNAL_ATOMIC_SIZES_H_
