From: Martin Quinson Date: Tue, 8 Mar 2016 23:40:50 +0000 (+0100) Subject: thread_local is C++11, remove the portability layer X-Git-Tag: v3_13~463 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/3893493151bcdbed55ef359cdfea4563ee8cddb8 thread_local is C++11, remove the portability layer --- diff --git a/CMakeLists.txt b/CMakeLists.txt index b0a6d3c96c..7a211133eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -307,19 +307,6 @@ if(MINGW) set(HAVE_VASPRINTF 1) endif() - -#Check if __thread is defined -execute_process( - COMMAND "${CMAKE_C_COMPILER} ${CMAKE_HOME_DIRECTORY}/tools/cmake/test_prog/prog_thread_storage.c -o testprog" - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - RESULT_VARIABLE HAVE_thread_storage_run) -file(REMOVE testprog) -if(HAVE_thread_storage_run) - set(HAVE_THREAD_LOCAL_STORAGE 1) -else() - set(HAVE_THREAD_LOCAL_STORAGE 0) -endif() - # Our usage of mmap is Linux-specific (flag MAP_ANONYMOUS), but kFreeBSD uses a GNU libc IF(HAVE_MMAP AND NOT "${CMAKE_SYSTEM}" MATCHES "Linux" AND @@ -330,7 +317,7 @@ IF(HAVE_MMAP AND message(STATUS "Warning: MMAP is thought as non functional on this architecture (${CMAKE_SYSTEM})") ENDIF() -if(HAVE_MMAP AND HAVE_THREAD_LOCAL_STORAGE) +if(HAVE_MMAP) SET(HAVE_MMALLOC 1) else() SET(HAVE_MMALLOC 0) diff --git a/include/xbt/base.h b/include/xbt/base.h index 4347e66ffd..e461880bb5 100644 --- a/include/xbt/base.h +++ b/include/xbt/base.h @@ -56,14 +56,6 @@ # endif # undef _XBT_NEED_INIT_PRAGMA -#elif defined(_MSC_VER) /* Microsoft Visual Thing */ -# define XBT_ATTRIB_PRINTF( format_idx, arg_idx ) -# define XBT_ATTRIB_SCANF( format_idx, arg_idx ) -# define XBT_ATTRIB_NORETURN __declspec(noreturn) -# define XBT_ATTRIB_UNUSED -# define _XBT_GNUC_CONSTRUCTOR(prio) -# define _XBT_GNUC_DESTRUCTOR(prio) -# define _XBT_NEED_INIT_PRAGMA 1 #else # define XBT_ATTRIB_PRINTF( format_idx, arg_idx ) # define XBT_ATTRIB_SCANF( format_idx, arg_idx ) @@ -91,14 +83,6 @@ # define XBT_ALWAYS_INLINE inline #endif -#if defined(__GNUC__) -# define XBT_THREAD_LOCAL __thread -#elif defined(_MSC_VER) -# define XBT_THREAD_LOCAL __declspec(thread) -#else -# define XBT_THREAD_LOCAL No thread local on this architecture -#endif - /* improvable on gcc (by evaluating arguments only once), but wouldn't be portable */ #ifdef MIN # undef MIN diff --git a/src/simix/smx_context.cpp b/src/simix/smx_context.cpp index 82a78fd036..f1caa05bbf 100644 --- a/src/simix/smx_context.cpp +++ b/src/simix/smx_context.cpp @@ -40,11 +40,7 @@ int smx_context_stack_size; int smx_context_stack_size_was_set = 0; int smx_context_guard_size; int smx_context_guard_size_was_set = 0; -#ifdef HAVE_THREAD_LOCAL_STORAGE -static XBT_THREAD_LOCAL smx_context_t smx_current_context_parallel; -#else -static xbt_os_thread_key_t smx_current_context_key = 0; -#endif +static thread_local smx_context_t smx_current_context_parallel; static smx_context_t smx_current_context_serial; static int smx_parallel_contexts = 1; static int smx_parallel_threshold = 2; @@ -55,11 +51,6 @@ static e_xbt_parmap_mode_t smx_parallel_synchronization_mode = XBT_PARMAP_DEFAUL */ void SIMIX_context_mod_init(void) { -#if defined(HAVE_THREAD_CONTEXTS) && !defined(HAVE_THREAD_LOCAL_STORAGE) - /* the __thread storage class is not available on this platform: - * use getspecific/setspecific instead to store the current context in each thread */ - xbt_os_thread_key_create(&smx_current_context_key); -#endif if (!simix_global->context_factory) { /* select the context factory to use to create the contexts */ if (simgrid::simix::factory_initializer) @@ -281,16 +272,10 @@ void SIMIX_context_set_parallel_mode(e_xbt_parmap_mode_t mode) { */ smx_context_t SIMIX_context_get_current(void) { - if (SIMIX_context_is_parallel()) { -#ifdef HAVE_THREAD_LOCAL_STORAGE + if (SIMIX_context_is_parallel()) return smx_current_context_parallel; -#else - return xbt_os_thread_get_specific(smx_current_context_key); -#endif - } - else { + else return smx_current_context_serial; - } } /** @@ -299,14 +284,8 @@ smx_context_t SIMIX_context_get_current(void) */ void SIMIX_context_set_current(smx_context_t context) { - if (SIMIX_context_is_parallel()) { -#ifdef HAVE_THREAD_LOCAL_STORAGE + if (SIMIX_context_is_parallel()) smx_current_context_parallel = context; -#else - xbt_os_thread_set_specific(smx_current_context_key, context); -#endif - } - else { + else smx_current_context_serial = context; - } } diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index abbd3b1ff6..9a56744460 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -1114,7 +1114,6 @@ set(CMAKE_SOURCE_FILES tools/cmake/test_prog/prog_snprintf.c tools/cmake/test_prog/prog_stackgrowth.c tools/cmake/test_prog/prog_stacksetup.c - tools/cmake/test_prog/prog_thread_storage.c tools/cmake/test_prog/prog_vsnprintf.c tools/cmake/cross-mingw.cmake tools/stack-cleaner/as diff --git a/tools/cmake/src/internal_config.h.in b/tools/cmake/src/internal_config.h.in index e64a9210b7..49dfc3e45d 100644 --- a/tools/cmake/src/internal_config.h.in +++ b/tools/cmake/src/internal_config.h.in @@ -30,7 +30,6 @@ /* Variables for the thread contexts (and parallel mode of raw contexts) */ #cmakedefine HAVE_PTHREAD @HAVE_PTHREAD@ /* Define to 1 if threads are usable . */ #cmakedefine HAVE_PTHREAD_SETAFFINITY @HAVE_PTHREAD_SETAFFINITY@ /* Does not seems defined on Mac nor Windows */ -#cmakedefine HAVE_THREAD_LOCAL_STORAGE @HAVE_THREAD_LOCAL_STORAGE@ /* If __thread is available */ /* Variables for the raw contexts (to select the right assembly code) */ #cmakedefine PROCESSOR_i686 @PROCESSOR_i686@ diff --git a/tools/cmake/test_prog/prog_thread_storage.c b/tools/cmake/test_prog/prog_thread_storage.c deleted file mode 100644 index edcab030ca..0000000000 --- a/tools/cmake/test_prog/prog_thread_storage.c +++ /dev/null @@ -1,21 +0,0 @@ -/* Copyright (c) 2010-2011, 2013-2014. The SimGrid Team. - * All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -#include - -#ifdef _MSC_VER -__declspec(thread) -#else -__thread -#endif -int thread_specific_variable = 0; - -int main(void) { - - thread_specific_variable++; - printf("%d\n", thread_specific_variable); - return 0; -}