commit fac8495082d91c28e69bf68f2fcf365933cfe628
parent 07b377929d857a151a0871c9e83dc923d828ca21
Author: vaplv <vaplv@free.fr>
Date: Sat, 1 Feb 2014 19:36:46 +0100
Remove any support of the MSVC compiler
Add cmake config scripts and finalize the install
Diffstat:
8 files changed, 223 insertions(+), 221 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -0,0 +1,146 @@
+cmake_minimum_required(VERSION 2.6)
+project(rsys C)
+enable_testing()
+
+if(NOT CMAKE_COMPILER_IS_GNUCC)
+ message(FATAL_ERROR "Unsupported compiler")
+endif(NOT CMAKE_COMPILER_IS_GNUCC)
+
+set(CMAKE_CURRENT_SOURCE_DIR ${PROJECT_SOURCE_DIR}/../src)
+set(CMAKE_DEBUG_POSTFIX "-dbg")
+
+find_package(Threads)
+find_package(OpenMP)
+
+################################################################################
+# Setup compile flags/parameters
+################################################################################
+if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+ set(BUILD_32-BIT OFF CACHE BOOL "Force code generation for 32-bit environment")
+endif(CMAKE_SIZEOF_VOID_P EQUAL 8)
+
+set(C_FLAGS "-pedantic -std=c89 -fvisibility=hidden -fstrict-aliasing")
+set(C_FLAGS_WARN "-Wall -Wextra -Wcast-align -Wmissing-declarations -Wmissing-prototypes -Wconversion")
+set(C_FLAGS_LINK "-Wl,--no-undefined")
+if(CMAKE_HOST_UNIX)
+ set(C_FLAGS_UNIX "-fPIC")
+endif(CMAKE_HOST_UNIX)
+if(BUILD_32-BIT)
+ set(C_FLAGS "${C_FLAGS} -m32")
+endif(BUILD_32-BIT)
+
+set(CMAKE_C_FLAGS "${C_FLAGS} ${C_FLAGS_UNIX} ${C_FLAGS_WARN} ${C_FLAGS_LINK}")
+set(CMAKE_C_FLAGS_DEBUG "-g -DDEBUG")
+set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
+
+if(CMAKE_USE_PTHREADS_INIT)
+ add_definitions(-DRSYS_USE_PTHREADS)
+endif()
+
+################################################################################
+# Helper macros
+################################################################################
+# Prepend each file in the `_files' list by `_path'
+macro(prepend_path _files _path)
+ unset(_tmp)
+ foreach(f ${${_files}})
+ list(APPEND _tmp ${_path}/${f})
+ endforeach(f)
+ set(${_files} ${_tmp})
+endmacro(prepend_path)
+
+################################################################################
+# Define targets
+################################################################################
+set(VERSION_MAJOR 0)
+set(VERSION_MINOR 0)
+set(VERSION_PATCH 0)
+set(RSYS_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
+message(STATUS "Current library version: ${RSYS_VERSION}")
+
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/rsys_version.h.in
+ ${CMAKE_CURRENT_SOURCE_DIR}/rsys_version.h)
+configure_file(${PROJECT_SOURCE_DIR}/config/rsys-config-version.cmake.in
+ ${PROJECT_SOURCE_DIR}/config/rsys-config-version.cmake)
+
+set(RSYS_FILES_CMAKE
+ rsys-config.cmake
+ rsys-config-version.cmake)
+set(RSYS_FILES_SRC
+ clock_time.c
+ image.c
+ library.c
+ mem_allocator.c
+ pthread/pthread_condition.c
+ pthread/pthread_mutex.c)
+set(RSYS_FILES_INC_COMMON
+ atomic.h
+ clock_time.h
+ free_list.h
+ image.h
+ library.h
+ list.h
+ mem_allocator.h
+ mutex.h
+ ref_count.h
+ rsys.h
+ signal.h)
+set(RSYS_FILES_INC_EDIT ${RSYS_FILES_INC_COMMON} rsys_version.h.in)
+set(RSYS_FILES_INC_INSTALL ${RSYS_FILES_INC_COMMON} rsys_version.h)
+
+prepend_path(RSYS_FILES_CMAKE ${PROJECT_SOURCE_DIR}/config)
+prepend_path(RSYS_FILES_SRC ${CMAKE_CURRENT_SOURCE_DIR})
+prepend_path(RSYS_FILES_INC_EDIT ${CMAKE_CURRENT_SOURCE_DIR})
+prepend_path(RSYS_FILES_INC_INSTALL ${CMAKE_CURRENT_SOURCE_DIR})
+
+add_library(rsys SHARED ${RSYS_FILES_SRC} ${RSYS_FILES_INC})
+target_link_libraries(rsys ${CMAKE_THREAD_LIBS_INIT})
+set_target_properties(rsys PROPERTIES
+ DEFINE_SYMBOL RSYS_SHARED_BUILD
+ VERSION ${RSYS_VERSION}
+ SOVERSION ${VERSION_MAJOR})
+
+if(CMAKE_HOST_UNIX)
+ target_link_libraries(rsys dl)
+endif(CMAKE_HOST_UNIX)
+
+################################################################################
+# Add tests
+################################################################################
+macro(new_test _name)
+ add_executable(${_name} ${CMAKE_CURRENT_SOURCE_DIR}/${_name}.c)
+ set(_libraries ${ARGN})
+ foreach(_lib ${_libraries})
+ target_link_libraries(${_name} ${_lib})
+ endforeach(_lib)
+ add_test(${_name} ${_name})
+endmacro(new_test)
+
+new_test(test_atomic)
+new_test(test_free_list rsys)
+new_test(test_library rsys)
+new_test(test_list rsys)
+new_test(test_mem_allocator rsys)
+new_test(test_ref)
+new_test(test_signal rsys)
+new_test(test_time rsys)
+
+if(NOT OPENMP_FOUND)
+ message(STATUS "No OpenMP support: multi-threaded tests cannot be generated")
+else(NOT OPENMP_FOUND)
+ new_test(test_condition rsys)
+ new_test(test_mutex rsys)
+ set_target_properties(test_mutex test_condition PROPERTIES COMPILE_FLAGS ${OpenMP_C_FLAGS})
+ set_target_properties(test_mutex test_condition PROPERTIES LINK_FLAGS ${OpenMP_C_FLAGS})
+endif()
+
+################################################################################
+# Define output & install directories
+################################################################################
+install(TARGETS rsys
+ ARCHIVE DESTINATION bin
+ LIBRARY DESTINATION lib
+ RUNTIME DESTINATION bin)
+install(FILES ${RSYS_FILES_INC} DESTINATION include/rsys)
+install(FILES ${RSYS_FILES_CMAKE} DESTINATION cmake)
+
diff --git a/cmake/config/rsys-config-version.cmake.in b/cmake/config/rsys-config-version.cmake.in
@@ -0,0 +1,40 @@
+set(VERSION_MAJOR @VERSION_MAJOR@)
+set(VERSION_MINOR @VERSION_MINOR@)
+set(VERSION_PATCH @VERSION_PATCH@)
+set(PACKAGE_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
+
+if(NOT PACKAGE_FIND_VERSION
+ OR PACKAGE_VERSION VERSION_EQUAL PACKAGE_FIND_VERSION)
+ set(PACKAGE_VERSION_COMPATIBLE TRUE)
+ set(PACKAGE_VERSION_EXACT TRUE)
+ set(PACKAGE_VERSION_UNSUITABLE FALSE)
+ return()
+endif(NOT PACKAGE_FIND_VERSION
+ OR PACKAGE_VERSION VERSION_EQUAL PACKAGE_FIND_VERSION)
+
+if(NOT VERSION_MAJOR VERSION_EQUAL PACKAGE_FIND_VERSION_MAJOR)
+ set(PACKAGE_VERSION_COMPATIBLE FALSE)
+ set(PACKAGE_VERSION_EXACT FALSE)
+ set(PACKAGE_VERSION_UNSUITABLE TRUE)
+ return()
+endif(NOT VERSION_MAJOR VERSION_EQUAL PACKAGE_FIND_VERSION_MAJOR)
+
+if(VERSION_MINOR VERSION_LESS PACKAGE_FIND_VERSION_MINOR)
+ set(PACKAGE_VERSION_COMPATIBLE FALSE)
+ set(PACKAGE_VERSION_EXACT FALSE)
+ set(PACKAGE_VERSION_UNSUITABLE TRUE)
+ return()
+endif(VERSION_MINOR VERSION_LESS PACKAGE_FIND_VERSION_MINOR)
+
+if(VERSION_MINOR VERSION_EQUAL PACKAGE_FIND_VERSION_MINOR )
+ if(VERSION_PATCH VERSION_LESS PACKAGE_FIND_VERSION_PATCH)
+ set(PACKAGE_VERSION_COMPATIBLE FALSE)
+ set(PACKAGE_VERSION_EXACT FALSE)
+ set(PACKAGE_VERSION_UNSUITABLE TRUE)
+ return()
+ endif()
+endif()
+
+set(PACKAGE_VERSION_COMPATIBLE TRUE)
+set(PACKAGE_VERSION_EXACT FALSE)
+set(PACKAGE_VERSION_UNSUITABLE FALSE)
diff --git a/cmake/config/rsys-config.cmake b/cmake/config/rsys-config.cmake
@@ -0,0 +1,11 @@
+# Try to find the rsys devel. Once done this will define:
+# - RSYS_FOUND - system has foundation
+# - RSYS_INCLUDE_DIR - the foundation include directory
+# - RSYS_LIBRARIES - Link these to use foundation
+include(FindPackageHandleStandardArgs)
+find_path(RSYS_INCLUDE_DIR rsys/rsys.h)
+find_library(RSYS_LIBRARIES rsys)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(Foundation DEFAULT_MSG
+ RSYS_LIBRARIES
+ RSYS_INCLUDE_DIR)
+
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
@@ -1,124 +0,0 @@
-cmake_minimum_required(VERSION 2.6)
-project(rsys C)
-enable_testing()
-
-if(NOT CMAKE_COMPILER_IS_GNUCC)
- message(FATAL_ERROR "Unsupported compiler")
-endif(NOT CMAKE_COMPILER_IS_GNUCC)
-
-find_package(Threads)
-find_package(OpenMP)
-
-################################################################################
-# Setup compile flags/parameters
-################################################################################
-if(CMAKE_SIZEOF_VOID_P EQUAL 8)
- set(BUILD_32-BIT OFF CACHE BOOL "Force code generation for 32-bit environment")
-endif(CMAKE_SIZEOF_VOID_P EQUAL 8)
-
-set(C_FLAGS "-pedantic -std=c89 -fvisibility=hidden -fstrict-aliasing")
-set(C_FLAGS_WARN "-Wall -Wextra -Wcast-align -Wmissing-declarations -Wmissing-prototypes -Wconversion")
-set(C_FLAGS_LINK "-Wl,--no-undefined")
-if(CMAKE_HOST_UNIX)
- set(C_FLAGS_UNIX "-fPIC")
-endif(CMAKE_HOST_UNIX)
-if(BUILD_32-BIT)
- set(C_FLAGS "${C_FLAGS} -m32")
-endif(BUILD_32-BIT)
-
-set(CMAKE_C_FLAGS "${C_FLAGS} ${C_FLAGS_UNIX} ${C_FLAGS_WARN} ${C_FLAGS_LINK}")
-set(CMAKE_C_FLAGS_DEBUG "-g -DDEBUG")
-set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
-
-if(CMAKE_USE_PTHREADS_INIT)
- add_definitions(-DRSYS_USE_PTHREADS)
-endif()
-
-################################################################################
-# Define targets
-################################################################################
-set(VERSION_MAJOR 0)
-set(VERSION_MINOR 0)
-set(VERSION_PATCH 0)
-configure_file(rsys_version.h.in ${CMAKE_CURRENT_SOURCE_DIR}/rsys_version.h)
-
-set(RSYS_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
-message(STATUS "Current library version: ${RSYS_VERSION}")
-
-set(RSYS_FILES_SRC
- clock_time.c
- image.c
- library.c
- mem_allocator.c
- pthread/pthread_condition.c
- pthread/pthread_mutex.c)
-set(RSYS_FILES_INC_COMMON
- atomic.h
- clock_time.h
- free_list.h
- image.h
- library.h
- list.h
- mem_allocator.h
- mutex.h
- ref_count.h
- rsys.h
- signal.h)
-
-set(RSYS_FILES_INC_INSTALL ${RSYS_FILES_INC_COMMON} rsys_version.h)
-set(RSYS_FILES_INC_EDIT ${RSYS_FILES_INC_COMMON} rsys_version.h.in)
-
-add_library(rsys SHARED ${RSYS_FILES_SRC} ${RSYS_FILES_INC})
-target_link_libraries(rsys ${CMAKE_THREAD_LIBS_INIT})
-set_target_properties(rsys PROPERTIES
- DEFINE_SYMBOL RSYS_SHARED_BUILD
- VERSION ${RSYS_VERSION}
- SOVERSION ${VERSION_MAJOR})
-
-if(CMAKE_HOST_UNIX)
- target_link_libraries(rsys dl)
-endif(CMAKE_HOST_UNIX)
-
-source_group(src FILES ${RSYS_FILES_SRC} ${RSYS_FILES_INC_EDIT})
-
-################################################################################
-# Add tests
-################################################################################
-macro(new_test _name)
- add_executable(${_name} ${_name}.c)
-
- set(_libraries ${ARGN})
- foreach(_lib ${_libraries})
- target_link_libraries(${_name} ${_lib})
- endforeach(_lib)
-
- add_test(${_name} ${_name})
-endmacro(new_test)
-
-new_test(test_atomic)
-new_test(test_free_list rsys)
-new_test(test_library rsys)
-new_test(test_list rsys)
-new_test(test_mem_allocator rsys)
-new_test(test_ref)
-new_test(test_signal rsys)
-new_test(test_time rsys)
-
-if(NOT OPENMP_FOUND)
- message(STATUS "No OpenMP support: multi-threaded tests cannot be generated")
-else()
- new_test(test_condition rsys)
- new_test(test_mutex rsys)
- set_target_properties(test_mutex test_condition PROPERTIES COMPILE_FLAGS ${OpenMP_C_FLAGS})
- set_target_properties(test_mutex test_condition PROPERTIES LINK_FLAGS ${OpenMP_C_FLAGS})
-endif()
-
-################################################################################
-# Define output & install directories
-################################################################################
-install(TARGETS rsys
- ARCHIVE DESTINATION bin
- LIBRARY DESTINATION lib
- RUNTIME DESTINATION bin)
-install(FILES ${RSYS_FILES_INC} DESTINATION include/rsys)
-
diff --git a/src/atomic.h b/src/atomic.h
@@ -3,64 +3,20 @@
#include "rsys.h"
-/*
- * GCC implementation
- */
-#ifdef COMPILER_GCC
+#ifndef COMPILER_GCC
+ #error "Unsupported compiler"
+#endif
typedef int32_t atomic32_T;
typedef int64_t atomic64_T;
#define ATOMIC_INCR(A) __sync_add_and_fetch((A), 1)
#define ATOMIC_DECR(A) __sync_sub_and_fetch((A), 1)
-#define ATOMIC_ADD(A, V) __sync_fetch_and_add((A), (int32_t)V)
-#define ATOMIC_SUB(A, V) __sync_fetch_and_sub((A), (int32_t)V)
+#define ATOMIC_ADD(A, V) __sync_add_and_fetch((A), V)
+#define ATOMIC_SUB(A, V) __sync_sub_and_fetch((A), V)
#define ATOMIC_CAS(Atom, NewVal, Comparand) /* Return the initial value */ \
- __sync_val_compare_and_swap((Atom), (int32_t)(Comparand), (int32_t)(NewVal))
+ __sync_val_compare_and_swap((Atom), (Comparand), (NewVal))
#define ATOMIC_SET(A, V) ATOMIC_CAS((A), V, (*A)) /*Return the initial value*/
-/*
- * MSVC implementation
- */
-#elif defined COMPILER_MSVC
-# include <Windows.h>
-
-typedef long atomic32_T;
-typedef LONGLONG atomic64_T;
-
-#define ATOMIC_INCR(A) \
- sizeof(*A) == 32 ? _InterlockedIncrement(A) \
-: (sizeof(*A) == 64 ? _InterlockedIncrement64(A) \
-: FATAL("Unexpected atomic type"), (void)0)
-#define ATOMIC_DECR(A) \
- sizeof(*A) == 32 ? _InterlockedDecrement(A) \
-: (sizeof(*A) == 64 ? _InterlockedDecrement64(A) \
-: FATAL("Unexpected atomic type"), (void)0)
-#define ATOMIC_ADD(A, V) \
- sizeof(*A) == 32 ? _InterlockedExchangeAdd((A), (long)(V)) \
-: (sizeof(*A) == 64 ? _InterlockedExchangeAdd64((A), (LONGLONG)(V)) \
-: FATAL("Unexpected atomic type"), (void)0)
-#define ATOMIC_SUB(A, V) \
- sizeof(*A) == 32 ? _InterlockedExchangeAdd((A), -(long)(V)) \
-: (sizeof(*A) == 64 ? _InterlockedExchangeAdd64((A), -(LONGLONG)(V)) \
-: FATAL("Unexpected atomic type"), (void)0)
-#define ATOMIC_CAS(Atom, NewVal, Cmp) \
- sizeof(*A) == 32 \
-? _InterlockedCompareExchange((Atom), (long)(NewVal), (long)(Cmp)) \
-: (sizeof(*A) == 64 \
-? _InterlockedCompareExchange64((A), -(LONGLONG)(NewVal), (LONGLONG)(Cmp)) \
-: FATAL("Unexpected atomic type"), (void)0)
-#define ATOMIC_SET(A, V) \
- sizeof(*A) == 32 ? _InterlockedExchange((A), (long)(V)) \
-: (sizeof(*A) == 64 ? _InterlockedExchange64((A), (LONGLONG)(V)) \
-: FATAL("Unexpected atomic type"), (void)0)
-
-/*
- * Terra incognita
- */
-#else
-# error "Unsupported compiler"
-#endif /* COMPILER_XXX */
-
#endif /* ATOMIC_H */
diff --git a/src/mem_allocator.c b/src/mem_allocator.c
@@ -9,14 +9,10 @@
#define IS_POWER_OF_2(i) ((i) > 0 && ((i) & ((i)-1)) == 0)
-#ifdef OS_WINDOWS
-# ifdef MINGW
- /* On MINGW the _aligned_msize function is not defined. THe size is thus
- * stored into the memory block header */
-# define MEM_HEADER_SIZE (2 * sizeof(size_t))
-# else
-# define MEM_HEADER_SIZE (1 * sizeof(size_t))
-# endif
+#ifdef MINGW
+ /* On MINGW the _aligned_msize function is not defined. The size is thus
+ * stored into the memory block header */
+ #define MEM_HEADER_SIZE (2 * sizeof(size_t))
#endif
struct alloc_counter {
@@ -36,14 +32,12 @@ mem_alloc(const size_t size)
if(size) {
#if defined(OS_UNIX)
mem = malloc(size);
-#elif defined(OS_WINDOWS)
+#elif defined(MINGW)
const size_t DEFAULT_ALIGNMENT = 16;
mem = _aligned_offset_malloc
(size + MEM_HEADER_SIZE, DEFAULT_ALIGNMENT, MEM_HEADER_SIZE);
-# ifdef MINGW
((size_t*)mem)[0] = DEFAULT_ALIGNMENT;
((size_t*)mem)[1] = size + MEM_HEADER_SIZE;
-# endif
mem = ((char*)mem) + MEM_HEADER_SIZE;
#endif
}
@@ -83,13 +77,11 @@ mem_realloc(void* mem, const size_t size)
&& g_alloc_counter.allocated_size >= (int64_t)old_size);
ATOMIC_SUB( &g_alloc_counter.allocated_size, old_size);
-#if defined(OS_WINDOWS)
+#if defined(MINGW)
mem = ((char*)mem) - MEM_HEADER_SIZE;
new_mem = _aligned_offset_realloc
(mem, size + MEM_HEADER_SIZE, ((size_t*)mem)[0], MEM_HEADER_SIZE);
-# ifdef MINGW
((size_t*)new_mem)[1] = size + MEM_HEADER_SIZE;
-# endif
new_mem = ((char*)new_mem) + MEM_HEADER_SIZE;
#elif defined(OS_UNIX)
new_mem = realloc( mem, size );
@@ -107,13 +99,11 @@ mem_alloc_aligned(const size_t size, const size_t alignment)
if(size
&& IS_POWER_OF_2( alignment )
&& alignment <= 32768 /* 32 KB */) {
-#if defined(OS_WINDOWS)
+#if defined(MINGW)
mem = _aligned_offset_malloc
(size + MEM_HEADER_SIZE, alignment, MEM_HEADER_SIZE);
((size_t*)mem)[0] = alignment;
-# ifdef MINGW
((size_t*)mem)[1] = size + MEM_HEADER_SIZE;
-# endif
mem = ((char*)mem) + MEM_HEADER_SIZE;
#elif defined(OS_UNIX)
const int result = posix_memalign
@@ -141,7 +131,7 @@ mem_free(void* mem)
&& g_alloc_counter.allocated_size >= (int64_t)mem_size(mem));
ATOMIC_SUB(&g_alloc_counter.allocated_size, mem_size(mem));
ATOMIC_DECR(&g_alloc_counter.nb_allocs);
-#if defined(OS_WINDOWS)
+#if defined(MINGW)
mem = ((char*)mem) - MEM_HEADER_SIZE;
_aligned_free( mem );
#elif defined(OS_UNIX)
@@ -155,13 +145,9 @@ mem_size(void* mem)
{
size_t mem_size = 0;
if(mem) {
-#if defined(OS_WINDOWS)
+#if defined(MINGW)
void* raw_mem = ((char*)mem) - MEM_HEADER_SIZE;
-# ifdef MINGW
mem_size = ((size_t*)raw_mem)[1];
-# else
- mem_size = _aligned_msize(raw_mem, ((size_t*)raw_mem)[0], sizeof(size_t));
-# endif
#elif defined(OS_UNIX)
mem_size = malloc_usable_size(mem);
#endif
diff --git a/src/rsys.h b/src/rsys.h
@@ -17,21 +17,18 @@
#define OS_UNIX
#elif defined(_WIN32)
#define OS_WINDOWS
+ #if defined(__MINGW32__)
+ #define MINGW
+ #endif
#else
#error "Unsupported OS"
#endif
-#if defined(__MINGW32__)
- #define MINGW
-#endif
-
/*******************************************************************************
* Compiler
******************************************************************************/
#if defined(__GNUC__)
#define COMPILER_GCC
-#elif defined(_MSC_VER)
- #define COMPILER_MSVC
#else
#error "Unsupported compiler"
#endif
@@ -43,21 +40,13 @@
#define EXPORT_SYM __attribute__((visibility("default")))
#define IMPORT_SYM
#define LOCAL_SYM __attribute__((visibility("hidden")))
-#elif defined(COMPILER_MSVC)
- #define FDN_SYMBOL_EXPORT __declspec(dllexport)
- #define FDN_SYMBOL_IMPORT __declspec(dllimport)
- #define FDN_SYMBOL_LOCAL
#endif
#if defined(OS_UNIX)
#define SHARED_LIBRARY_PREFIX "lib"
#define SHARED_LIBRARY_SUFFIX ".so"
-#elif defined(OS_WINDOWS)
- #if defined(MINGW)
- #define SHARED_LIBRARY_PREFIX "lib"
- #else
- #define SHARED_LIBRARY_PREFIX
- #endif
+#elif defined(OS_WINDOWS) && defined(MINGW)
+ #define SHARED_LIBRARY_PREFIX "lib"
#define SHARED_LIBRARY_SUFFIX ".dll"
#endif
@@ -76,10 +65,6 @@
#define FINLINE __inline__ __attribute__((always_inline))
#define INLINE __inline__
#define NOINLINE __attribute__((noinline))
-#elif defined(COMPILER_MSVC)
- #define FINLINE __forceinline
- #define INLINE __inline
- #define NOINLINE __declspec(noinline)
#endif
/*******************************************************************************
@@ -125,8 +110,10 @@
/*******************************************************************************
* Branch prediction information
******************************************************************************/
-#define LIKELY(X) __builtin_expect((X), 1)
-#define UNLIKELY(X) __builtin_expect((X), 0)
+#ifdef COMPILER_GCC
+ #define LIKELY(X) __builtin_expect((X), 1)
+ #define UNLIKELY(X) __builtin_expect((X), 0)
+#endif
/*******************************************************************************
* Iteration
diff --git a/src/test_atomic.c b/src/test_atomic.c
@@ -13,13 +13,13 @@ main(int argc, char** argv)
CHECK(tmp, 1);
tmp = ATOMIC_ADD(&atom, 5);
CHECK(atom, 6);
- CHECK(tmp, 1);
+ CHECK(tmp, 6);
tmp = ATOMIC_DECR(&atom);
CHECK(atom, 5);
CHECK(tmp, 5);
tmp = ATOMIC_SUB(&atom, 7);
CHECK(atom, -2);
- CHECK(tmp, 5);
+ CHECK(tmp, -2);
tmp = ATOMIC_CAS(&atom, 0, -1);
CHECK(atom, -2);