Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
kill xbt_os_sem_t and the required cmake-detection cruft
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Fri, 4 Jan 2019 23:06:02 +0000 (00:06 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Fri, 4 Jan 2019 23:06:02 +0000 (00:06 +0100)
CMakeLists.txt
ChangeLog
src/xbt/xbt_os_thread.c
tools/cmake/DefinePackages.cmake
tools/cmake/src/internal_config.h.in

index ce93b4a..27cca00 100644 (file)
@@ -406,79 +406,8 @@ endif()
 #--------------------------------------------------------------------------------------------------
 ### Initialize of CONTEXT THREADS
 
 #--------------------------------------------------------------------------------------------------
 ### Initialize of CONTEXT THREADS
 
-set(HAVE_THREAD_CONTEXTS 0)
-if(CMAKE_USE_PTHREADS_INIT)
-  ### Test that we have a way to create semaphores
-
-  set(HAVE_SEM_OPEN 0)
-  CHECK_LIBRARY_EXISTS(pthread sem_open "" HAVE_SEM_OPEN_LIB)
-  if(HAVE_SEM_OPEN_LIB)
-    try_run(semopen_retval semopen_compilable
-            ${CMAKE_BINARY_DIR}
-            ${CMAKE_HOME_DIRECTORY}/tools/cmake/test_prog/prog_sem_open.c
-           LINK_LIBRARIES pthread
-           COMPILE_OUTPUT_VARIABLE semopen_compilmsg
-            RUN_OUTPUT_VARIABLE semopen_runmsg)
-    
-    if(semopen_compilable)
-      if(NOT semopen_retval) # error if not 0
-        message(STATUS "sem_open is compilable and executable")
-       set(HAVE_SEM_OPEN 1)
-      else()
-        message(STATUS "Warning: sem_open seems compilable but not executable")
-        message(STATUS "Compilation output: ${semopen_compilmsg}")
-        message(STATUS "Execution output: ${semopen_runmsg}")
-        message(STATUS "Exit value: ${semopen_retval}")
-      endif()
-    else()
-      message(STATUS "Warning: sem_open not compilable")
-      message(STATUS "Compilation output: ${semopen_compilmsg}")
-    endif()
-    unset(semopen_compilable)
-    unset(semopen_retval)
-    unset(semopen_runmsg)
-    unset(semopen_compilmsg)
-  endif()
-
-  set(HAVE_SEM_INIT 0)  
-  if(NOT APPLE) # OS X El Capitan deprecates this function
-    CHECK_LIBRARY_EXISTS(pthread sem_init "" HAVE_SEM_INIT_LIB)
-  endif()
-  if(HAVE_SEM_INIT_LIB)
-    try_run(seminit_retval seminit_compilable
-            ${CMAKE_BINARY_DIR}
-            ${CMAKE_HOME_DIRECTORY}/tools/cmake/test_prog/prog_sem_init.c
-           LINK_LIBRARIES pthread
-           COMPILE_OUTPUT_VARIABLE seminit_compilmsg
-            RUN_OUTPUT_VARIABLE seminit_runmsg)
-    
-    if(seminit_compilable)
-      if(NOT seminit_retval) # error if not 0
-        message(STATUS "sem_init is compilable and executable")
-       set(HAVE_SEM_INIT 1)
-      else()
-        message(STATUS "Warning: sem_init seems compilable but not executable")
-        message(STATUS "Compilation output: ${seminit_compilmsg}")
-        message(STATUS "Execution output: ${seminit_runmsg}")
-        message(STATUS "Exit value: ${seminit_retval}")
-      endif()
-    else()
-      message(STATUS "Warning: sem_init not compilable")
-      message(STATUS "Compilation output: ${seminit_compilmsg}")
-    endif()
-    unset(seminit_compilable)
-    unset(seminit_retval)
-    unset(seminit_runmsg)
-    unset(seminit_compilmsg)
-  endif()
-
-  if(NOT HAVE_SEM_OPEN AND NOT HAVE_SEM_INIT)
-    message(FATAL_ERROR "Semaphores are not usable (failed to use both sem_open and sem_init), but they are mandatory to threads (you may need to mount /dev).")
-  endif()
-
-  set(HAVE_THREAD_CONTEXTS 1)
-  message(STATUS "Support for thread context factory ok.")
-endif()
+set(HAVE_THREAD_CONTEXTS 1)
+message(STATUS "Support for thread context factory ok.")
 
 set(HAVE_UCONTEXT_CONTEXTS 0)
 if(NOT HAVE_UCONTEXT_H)
 
 set(HAVE_UCONTEXT_CONTEXTS 0)
 if(NOT HAVE_UCONTEXT_H)
index e9981e0..2a0cb75 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -17,8 +17,8 @@ XBT:
  - Drop sg_cmdline. Please use xbt_cmdline instead.
  - Drop the C xbt_os_sem_t; Use the C++ xbt::OsSemaphore.
    OsSemaphore is implemented in a portable way with C++11 threads.
  - Drop sg_cmdline. Please use xbt_cmdline instead.
  - Drop the C xbt_os_sem_t; Use the C++ xbt::OsSemaphore.
    OsSemaphore is implemented in a portable way with C++11 threads.
-   This should introduce a major scalability improvement to the thread
-   backend, from which Mac users and Java users will benefit for free.
+   This should allow much more threads to be created at the same time,
+   allowing Mac and Java users to simulate many more actors.
 
 Fixed bugs:
  - #261: Document the parameters of parallel execution's constructor
 
 Fixed bugs:
  - #261: Document the parameters of parallel execution's constructor
index fdbbd81..4361e41 100644 (file)
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_sync_os, xbt, "Synchronization mechanism (OS-level)");
 
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_sync_os, xbt, "Synchronization mechanism (OS-level)");
 
-/* use named semaphore when sem_init() does not work */
-#if !HAVE_SEM_INIT
-static int next_sem_ID = 0;
-static xbt_os_mutex_t next_sem_ID_lock;
-#endif
-
 typedef struct xbt_os_thread_ {
   pthread_t t;
   char *name;
 typedef struct xbt_os_thread_ {
   pthread_t t;
   char *name;
@@ -97,10 +91,6 @@ void xbt_os_thread_mod_preinit(void)
   pthread_attr_init(&thread_attr);
 
   thread_mod_inited = 1;
   pthread_attr_init(&thread_attr);
 
   thread_mod_inited = 1;
-
-#if !HAVE_SEM_INIT
-  next_sem_ID_lock = xbt_os_mutex_init();
-#endif
 }
 
 void xbt_os_thread_mod_postexit(void)
 }
 
 void xbt_os_thread_mod_postexit(void)
@@ -115,9 +105,6 @@ void xbt_os_thread_mod_postexit(void)
   free(main_thread);
   main_thread = NULL;
   thread_mod_inited = 0;
   free(main_thread);
   main_thread = NULL;
   thread_mod_inited = 0;
-#if !HAVE_SEM_INIT
-  xbt_os_mutex_destroy(next_sem_ID_lock);
-#endif
 }
 
 /** Calls pthread_atfork() if present, and raise an exception otherwise.
 }
 
 /** Calls pthread_atfork() if present, and raise an exception otherwise.
@@ -288,83 +275,6 @@ void xbt_os_mutex_destroy(xbt_os_mutex_t mutex)
   free(mutex);
 }
 
   free(mutex);
 }
 
-typedef struct xbt_os_sem_ {
-#if !HAVE_SEM_INIT
-  char *name;
-#endif
-  sem_t s;
-  sem_t *ps;
-} s_xbt_os_sem_t;
-
-#ifndef SEM_FAILED
-#define SEM_FAILED (-1)
-#endif
-
-xbt_os_sem_t xbt_os_sem_init(unsigned int value)
-{
-  xbt_os_sem_t res = xbt_new(s_xbt_os_sem_t, 1);
-
-  /* On some systems (macOS), only the stub of sem_init is to be found.
-   * Any attempt to use it leads to ENOSYS (function not implemented).
-   * If such a prehistoric system is detected, do the job with sem_open instead
-   */
-#if HAVE_SEM_INIT
-  if (sem_init(&(res->s), 0, value) != 0)
-    THROWF(system_error, errno, "sem_init() failed: %s", strerror(errno));
-  res->ps = &(res->s);
-
-#else                           /* damn, no sem_init(). Reimplement it */
-
-  xbt_os_mutex_acquire(next_sem_ID_lock);
-  res->name = bprintf("/sg-%d", ++next_sem_ID);
-  xbt_os_mutex_release(next_sem_ID_lock);
-
-  sem_unlink(res->name);
-  res->ps = sem_open(res->name, O_CREAT, 0644, value);
-  if ((res->ps == (sem_t *) SEM_FAILED) && (errno == ENAMETOOLONG)) {
-    /* Old darwins only allow 13 chars. Did you create *that* amount of semaphores? */
-    res->name[13] = '\0';
-    sem_unlink(res->name);
-    res->ps = sem_open(res->name, O_CREAT, 0644, value);
-  }
-  if (res->ps == (sem_t *) SEM_FAILED)
-    THROWF(system_error, errno, "sem_open() failed: %s", strerror(errno));
-
-  /* Remove the name from the semaphore namespace: we never join on it */
-  if (sem_unlink(res->name) < 0)
-    THROWF(system_error, errno, "sem_unlink() failed: %s",
-           strerror(errno));
-
-#endif
-
-  return res;
-}
-
-void xbt_os_sem_acquire(xbt_os_sem_t sem)
-{
-  if (sem_wait(sem->ps) < 0)
-    THROWF(system_error, errno, "sem_wait() failed: %s", strerror(errno));
-}
-
-void xbt_os_sem_release(xbt_os_sem_t sem)
-{
-  if (sem_post(sem->ps) < 0)
-    THROWF(system_error, errno, "sem_post() failed: %s", strerror(errno));
-}
-
-void xbt_os_sem_destroy(xbt_os_sem_t sem)
-{
-#if HAVE_SEM_INIT
-  if (sem_destroy(sem->ps) < 0)
-    THROWF(system_error, errno, "sem_destroy() failed: %s", strerror(errno));
-#else
-  if (sem_close(sem->ps) < 0)
-    THROWF(system_error, errno, "sem_close() failed: %s", strerror(errno));
-  xbt_free(sem->name);
-#endif
-  xbt_free(sem);
-}
-
 void xbt_os_thread_set_extra_data(void *data)
 {
   xbt_os_thread_self()->extra_data = data;
 void xbt_os_thread_set_extra_data(void *data)
 {
   xbt_os_thread_self()->extra_data = data;
index 9ed5340..b3bab2d 100644 (file)
@@ -1101,8 +1101,6 @@ set(CMAKE_SOURCE_FILES
   tools/cmake/src/internal_config.h.in
   tools/cmake/test_prog/prog_asan.cpp
   tools/cmake/test_prog/prog_makecontext.c
   tools/cmake/src/internal_config.h.in
   tools/cmake/test_prog/prog_asan.cpp
   tools/cmake/test_prog/prog_makecontext.c
-  tools/cmake/test_prog/prog_sem_init.c
-  tools/cmake/test_prog/prog_sem_open.c
   tools/cmake/test_prog/prog_stackgrowth.c
   tools/cmake/test_prog/prog_stacksetup.c
   tools/cmake/cross-mingw.cmake
   tools/cmake/test_prog/prog_stackgrowth.c
   tools/cmake/test_prog/prog_stacksetup.c
   tools/cmake/cross-mingw.cmake
index d3689a7..97c598b 100644 (file)
@@ -89,8 +89,6 @@
 #cmakedefine01 HAVE_MMAP
 /* Function mremap */
 #cmakedefine01 HAVE_MREMAP
 #cmakedefine01 HAVE_MMAP
 /* Function mremap */
 #cmakedefine01 HAVE_MREMAP
-/* Function sem_init (part of XPG6 standard only) */
-#cmakedefine01 HAVE_SEM_INIT
 /* Function sysconf */
 #cmakedefine01 HAVE_SYSCONF
 /* Function vasprintf */
 /* Function sysconf */
 #cmakedefine01 HAVE_SYSCONF
 /* Function vasprintf */