diff DEPENDENCIES/generic/include/boost/interprocess/sync/posix/semaphore_wrapper.hpp @ 101:c530137014c0

Update Boost headers (1.58.0)
author Chris Cannam
date Mon, 07 Sep 2015 11:12:49 +0100
parents 2665513ce2d3
children
line wrap: on
line diff
--- a/DEPENDENCIES/generic/include/boost/interprocess/sync/posix/semaphore_wrapper.hpp	Fri Sep 04 12:01:02 2015 +0100
+++ b/DEPENDENCIES/generic/include/boost/interprocess/sync/posix/semaphore_wrapper.hpp	Mon Sep 07 11:12:49 2015 +0100
@@ -11,11 +11,19 @@
 #ifndef BOOST_INTERPROCESS_POSIX_SEMAPHORE_WRAPPER_HPP
 #define BOOST_INTERPROCESS_POSIX_SEMAPHORE_WRAPPER_HPP
 
+#ifndef BOOST_CONFIG_HPP
+#  include <boost/config.hpp>
+#endif
+#
+#if defined(BOOST_HAS_PRAGMA_ONCE)
+#  pragma once
+#endif
+
 #include <boost/interprocess/detail/posix_time_types_wrk.hpp>
 #include <boost/interprocess/exceptions.hpp>
 #include <boost/interprocess/creation_tags.hpp>
 #include <boost/interprocess/detail/os_file_functions.hpp>
-#include <boost/interprocess/detail/tmp_dir_helpers.hpp>
+#include <boost/interprocess/detail/shared_dir_helpers.hpp>
 #include <boost/interprocess/permissions.hpp>
 
 #include <fcntl.h>      //O_CREAT, O_*...
@@ -35,13 +43,16 @@
 #include <boost/interprocess/sync/posix/ptime_to_timespec.hpp>
 #else
 #include <boost/interprocess/detail/os_thread_functions.hpp>
-#include <boost/interprocess/sync/spin/wait.hpp>
+#include <boost/interprocess/sync/detail/locks.hpp>
+#include <boost/interprocess/sync/detail/common_algorithms.hpp>
 #endif
 
 namespace boost {
 namespace interprocess {
 namespace ipcdetail {
 
+#ifdef BOOST_INTERPROCESS_POSIX_NAMED_SEMAPHORES
+
 inline bool semaphore_open
    (sem_t *&handle, create_enum_t type, const char *origname,
     unsigned int count = 0, const permissions &perm = permissions())
@@ -50,7 +61,7 @@
    #ifndef BOOST_INTERPROCESS_FILESYSTEM_BASED_POSIX_SEMAPHORES
    add_leading_slash(origname, name);
    #else
-   create_tmp_and_clean_old_and_get_filename(origname, name);
+   create_shared_dir_cleaning_old_and_get_filepath(origname, name);
    #endif
 
    //Create new mapping
@@ -116,7 +127,7 @@
       #ifndef BOOST_INTERPROCESS_FILESYSTEM_BASED_POSIX_SEMAPHORES
       add_leading_slash(semname, sem_str);
       #else
-      tmp_filename(semname, sem_str);
+      shared_filepath(semname, sem_str);
       #endif
       return 0 == sem_unlink(sem_str.c_str());
    }
@@ -125,6 +136,10 @@
    }
 }
 
+#endif   //BOOST_INTERPROCESS_POSIX_NAMED_SEMAPHORES
+
+#ifdef BOOST_INTERPROCESS_POSIX_UNNAMED_SEMAPHORES
+
 inline void semaphore_init(sem_t *handle, unsigned int initialCount)
 {
    int ret = sem_init(handle, 1, initialCount);
@@ -132,7 +147,8 @@
    //sem_init call is not defined, but -1 is returned on failure.
    //In the future, a successful call might be required to return 0.
    if(ret == -1){
-      throw interprocess_exception(system_error_code());
+      error_info err = system_error_code();
+      throw interprocess_exception(err);
    }
 }
 
@@ -144,11 +160,14 @@
    }
 }
 
+#endif   //BOOST_INTERPROCESS_POSIX_UNNAMED_SEMAPHORES
+
 inline void semaphore_post(sem_t *handle)
 {
    int ret = sem_post(handle);
    if(ret != 0){
-      throw interprocess_exception(system_error_code());
+      error_info err = system_error_code();
+      throw interprocess_exception(err);
    }
 }
 
@@ -156,7 +175,8 @@
 {
    int ret = sem_wait(handle);
    if(ret != 0){
-      throw interprocess_exception(system_error_code());
+      error_info err = system_error_code();
+      throw interprocess_exception(err);
    }
 }
 
@@ -168,17 +188,39 @@
    if(system_error_code() == EAGAIN){
       return false;
    }
-   throw interprocess_exception(system_error_code());
-   return false;
+   error_info err = system_error_code();
+   throw interprocess_exception(err);
 }
 
+#ifndef BOOST_INTERPROCESS_POSIX_TIMEOUTS
+
+struct semaphore_wrapper_try_wrapper
+{
+   explicit semaphore_wrapper_try_wrapper(sem_t *handle)
+      : m_handle(handle)
+   {}
+
+   void wait()
+   {  semaphore_wait(m_handle);  }
+
+   bool try_wait()
+   {  return semaphore_try_wait(m_handle);  }
+
+   private:
+   sem_t *m_handle;
+};
+
+#endif
+
 inline bool semaphore_timed_wait(sem_t *handle, const boost::posix_time::ptime &abs_time)
 {
+   #ifdef BOOST_INTERPROCESS_POSIX_TIMEOUTS
+   //Posix does not support infinity absolute time so handle it here
    if(abs_time == boost::posix_time::pos_infin){
       semaphore_wait(handle);
       return true;
    }
-   #ifdef BOOST_INTERPROCESS_POSIX_TIMEOUTS
+
    timespec tspec = ptime_to_timespec(abs_time);
    for (;;){
       int res = sem_timedwait(handle, &tspec);
@@ -191,18 +233,16 @@
       if(system_error_code() == ETIMEDOUT){
          return false;
       }
-      throw interprocess_exception(system_error_code());
+      error_info err = system_error_code();
+      throw interprocess_exception(err);
    }
    return false;
    #else //#ifdef BOOST_INTERPROCESS_POSIX_TIMEOUTS
-   boost::posix_time::ptime now;
-   spin_wait swait;
-   do{
-      if(semaphore_try_wait(handle))
-         return true;
-      swait.yield();
-   }while((now = microsec_clock::universal_time()) < abs_time);
-   return false;
+
+   semaphore_wrapper_try_wrapper swtw(handle);
+   ipcdetail::lock_to_wait<semaphore_wrapper_try_wrapper> lw(swtw);
+   return ipcdetail::try_based_timed_lock(lw, abs_time);
+
    #endif   //#ifdef BOOST_INTERPROCESS_POSIX_TIMEOUTS
 }