Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
thread_local is C++11, remove the portability layer
authorMartin Quinson <martin.quinson@loria.fr>
Tue, 8 Mar 2016 23:40:50 +0000 (00:40 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Tue, 8 Mar 2016 23:41:21 +0000 (00:41 +0100)
CMakeLists.txt
include/xbt/base.h
src/simix/smx_context.cpp
tools/cmake/DefinePackages.cmake
tools/cmake/src/internal_config.h.in
tools/cmake/test_prog/prog_thread_storage.c [deleted file]

index b0a6d3c..7a21113 100644 (file)
@@ -307,19 +307,6 @@ if(MINGW)
   set(HAVE_VASPRINTF 1)
 endif()
 
   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 
 # 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()
 
   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)
   SET(HAVE_MMALLOC 1)
 else()
   SET(HAVE_MMALLOC 0)
index 4347e66..e461880 100644 (file)
 # endif
 # undef _XBT_NEED_INIT_PRAGMA
 
 # 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 )
 #else
 # define XBT_ATTRIB_PRINTF( format_idx, arg_idx )
 # define XBT_ATTRIB_SCANF( format_idx, arg_idx )
 #   define XBT_ALWAYS_INLINE inline
 #endif
 
 #   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
 /* improvable on gcc (by evaluating arguments only once), but wouldn't be portable */
 #ifdef MIN
 # undef MIN
index 82a78fd..f1caa05 100644 (file)
@@ -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;
 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;
 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)
 {
  */
 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)
   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)
 {
  */
 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;
     return smx_current_context_parallel;
-#else
-    return xbt_os_thread_get_specific(smx_current_context_key);
-#endif
-  }
-  else {
+  else
     return smx_current_context_serial;
     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)
 {
  */
 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;
     smx_current_context_parallel = context;
-#else
-    xbt_os_thread_set_specific(smx_current_context_key, context);
-#endif
-  }
-  else {
+  else
     smx_current_context_serial = context;
     smx_current_context_serial = context;
-  }
 }
 }
index abbd3b1..9a56744 100644 (file)
@@ -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_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
   tools/cmake/test_prog/prog_vsnprintf.c
   tools/cmake/cross-mingw.cmake
   tools/stack-cleaner/as
index e64a921..49dfc3e 100644 (file)
@@ -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 */
 /* 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@
 
 /* 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 (file)
index edcab03..0000000
+++ /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 <stdio.h>
-
-#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;
-}