]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/boost/interprocess/sync/file_lock.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / interprocess / sync / file_lock.hpp
index a488b5ba59b160cf5112a5fd28ef30224e92f4b7..a147837c910f979e7ec039ce33ab57197319b18b 100644 (file)
@@ -24,7 +24,6 @@
 #include <boost/interprocess/exceptions.hpp>
 #include <boost/interprocess/detail/os_file_functions.hpp>
 #include <boost/interprocess/detail/os_thread_functions.hpp>
-#include <boost/interprocess/detail/posix_time_types_wrk.hpp>
 #include <boost/interprocess/sync/detail/common_algorithms.hpp>
 #include <boost/interprocess/sync/detail/locks.hpp>
 #include <boost/move/utility_core.hpp>
@@ -51,7 +50,7 @@ class file_lock
    public:
    //!Constructs an empty file mapping.
    //!Does not throw
-   file_lock()
+   file_lock() BOOST_NOEXCEPT
       :  m_file_hnd(file_handle_t(ipcdetail::invalid_file()))
    {}
 
@@ -59,17 +58,26 @@ class file_lock
    //!exist or there are no operating system resources.
    file_lock(const char *name);
 
+   #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
+   //!Opens a file lock. Throws interprocess_exception if the file does not
+   //!exist or there are no operating system resources.
+   //! 
+   //!Note: This function is only available on operating systems with
+   //!      native wchar_t APIs (e.g. Windows).
+   file_lock(const wchar_t *name);
+   #endif
+
    //!Moves the ownership of "moved"'s file mapping object to *this.
    //!After the call, "moved" does not represent any file mapping object.
    //!Does not throw
-   file_lock(BOOST_RV_REF(file_lock) moved)
+   file_lock(BOOST_RV_REF(file_lock) moved) BOOST_NOEXCEPT
       :  m_file_hnd(file_handle_t(ipcdetail::invalid_file()))
    {  this->swap(moved);   }
 
    //!Moves the ownership of "moved"'s file mapping to *this.
    //!After the call, "moved" does not represent any file mapping.
    //!Does not throw
-   file_lock &operator=(BOOST_RV_REF(file_lock) moved)
+   file_lock &operator=(BOOST_RV_REF(file_lock) moved) BOOST_NOEXCEPT
    {
       file_lock tmp(boost::move(moved));
       this->swap(tmp);
@@ -81,7 +89,7 @@ class file_lock
 
    //!Swaps two file_locks.
    //!Does not throw.
-   void swap(file_lock &other)
+   void swap(file_lock &other) BOOST_NOEXCEPT
    {
       file_handle_t tmp = m_file_hnd;
       m_file_hnd = other.m_file_hnd;
@@ -90,26 +98,55 @@ class file_lock
 
    //Exclusive locking
 
+   //!Requires: The calling thread does not own the mutex.
+   //!
    //!Effects: The calling thread tries to obtain exclusive ownership of the mutex,
    //!   and if another thread has exclusive, or sharable ownership of
    //!   the mutex, it waits until it can obtain the ownership.
    //!Throws: interprocess_exception on error.
+   //!
+   //!Note: A program may deadlock if the thread that has ownership calls 
+   //!   this function. If the implementation can detect the deadlock,
+   //!   an exception could be thrown.
    void lock();
 
+   //!Requires: The calling thread does not own the mutex.
+   //!
    //!Effects: The calling thread tries to acquire exclusive ownership of the mutex
    //!   without waiting. If no other thread has exclusive, or sharable
    //!   ownership of the mutex this succeeds.
    //!Returns: If it can acquire exclusive ownership immediately returns true.
    //!   If it has to wait, returns false.
    //!Throws: interprocess_exception on error.
+   //! 
+   //!Note: A program may deadlock if the thread that has ownership calls 
+   //!   this function. If the implementation can detect the deadlock,
+   //!   an exception could be thrown.
    bool try_lock();
 
+   //!Requires: The calling thread does not own the mutex.
+   //!
    //!Effects: The calling thread tries to acquire exclusive ownership of the mutex
    //!   waiting if necessary until no other thread has exclusive, or sharable
    //!   ownership of the mutex or abs_time is reached.
    //!Returns: If acquires exclusive ownership, returns true. Otherwise returns false.
    //!Throws: interprocess_exception on error.
-   bool timed_lock(const boost::posix_time::ptime &abs_time);
+   //! 
+   //!Note: A program may deadlock if the thread that has ownership calls 
+   //!   this function. If the implementation can detect the deadlock,
+   //!   an exception could be thrown.
+   template<class TimePoint>
+   bool timed_lock(const TimePoint &abs_time);
+
+   //!Same as `timed_lock`, but this function is modeled after the
+   //!standard library interface.
+   template<class TimePoint> bool try_lock_until(const TimePoint &abs_time)
+   {  return this->timed_lock(abs_time);  }
+
+   //!Same as `timed_lock`, but this function is modeled after the
+   //!standard library interface.
+   template<class Duration>  bool try_lock_for(const Duration &dur)
+   {  return this->timed_lock(ipcdetail::duration_to_ustime(dur)); }
 
    //!Precondition: The thread must have exclusive ownership of the mutex.
    //!Effects: The calling thread releases the exclusive ownership of the mutex.
@@ -118,12 +155,23 @@ class file_lock
 
    //Sharable locking
 
+   //!Requires: The calling thread does not own the mutex.
+   //!
    //!Effects: The calling thread tries to obtain sharable ownership of the mutex,
    //!   and if another thread has exclusive ownership of the mutex, waits until
    //!   it can obtain the ownership.
    //!Throws: interprocess_exception on error.
+   //!
+   //!Note: A program may deadlock if the thread that owns a mutex object calls 
+   //!   this function. If the implementation can detect the deadlock,
+   //!   an exception could be thrown.
    void lock_sharable();
 
+   //!Same as `lock_sharable` but with a std-compatible interface
+   //! 
+   void lock_shared()
+   {  this->lock_sharable();  }
+
    //!Effects: The calling thread tries to acquire sharable ownership of the mutex
    //!   without waiting. If no other thread has exclusive ownership of the
    //!   mutex this succeeds.
@@ -132,17 +180,39 @@ class file_lock
    //!Throws: interprocess_exception on error.
    bool try_lock_sharable();
 
+   //!Same as `try_lock_sharable` but with a std-compatible interface
+   //! 
+   bool try_lock_shared()
+   {  return this->try_lock_sharable();  }
+
    //!Effects: The calling thread tries to acquire sharable ownership of the mutex
    //!   waiting if necessary until no other thread has exclusive ownership of
    //!   the mutex or abs_time is reached.
    //!Returns: If acquires sharable ownership, returns true. Otherwise returns false.
    //!Throws: interprocess_exception on error.
-   bool timed_lock_sharable(const boost::posix_time::ptime &abs_time);
+   template<class TimePoint>
+   bool timed_lock_sharable(const TimePoint &abs_time);
+
+   //!Same as `timed_lock_sharable`, but this function is modeled after the
+   //!standard library interface.
+   template<class TimePoint> bool try_lock_shared_until(const TimePoint &abs_time)
+   {  return this->timed_lock_sharable(abs_time);  }
+
+   //!Same as `timed_lock_sharable`, but this function is modeled after the
+   //!standard library interface.
+   template<class Duration>  bool try_lock_shared_for(const Duration &dur)
+   {  return this->timed_lock_sharable(ipcdetail::duration_to_ustime(dur)); }
 
    //!Precondition: The thread must have sharable ownership of the mutex.
    //!Effects: The calling thread releases the sharable ownership of the mutex.
    //!Throws: An exception derived from interprocess_exception on error.
    void unlock_sharable();
+
+   //!Same as `unlock_sharable` but with a std-compatible interface
+   //! 
+   void unlock_shared()
+   {  this->unlock_sharable();  }
+
    #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
    private:
    file_handle_t m_file_hnd;
@@ -160,6 +230,20 @@ inline file_lock::file_lock(const char *name)
    }
 }
 
+#if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
+
+inline file_lock::file_lock(const wchar_t *name)
+{
+   m_file_hnd = ipcdetail::open_existing_file(name, read_write);
+
+   if(m_file_hnd == ipcdetail::invalid_file()){
+      error_info err(system_error_code());
+      throw interprocess_exception(err);
+   }
+}
+
+#endif //defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
+
 inline file_lock::~file_lock()
 {
    if(m_file_hnd != ipcdetail::invalid_file()){
@@ -186,7 +270,8 @@ inline bool file_lock::try_lock()
    return result;
 }
 
-inline bool file_lock::timed_lock(const boost::posix_time::ptime &abs_time)
+template<class TimePoint>
+inline bool file_lock::timed_lock(const TimePoint &abs_time)
 {  return ipcdetail::try_based_timed_lock(*this, abs_time);   }
 
 inline void file_lock::unlock()
@@ -215,7 +300,8 @@ inline bool file_lock::try_lock_sharable()
    return result;
 }
 
-inline bool file_lock::timed_lock_sharable(const boost::posix_time::ptime &abs_time)
+template<class TimePoint>
+inline bool file_lock::timed_lock_sharable(const TimePoint &abs_time)
 {
    ipcdetail::lock_to_sharable<file_lock> lsh(*this);
    return ipcdetail::try_based_timed_lock(lsh, abs_time);