diff options
author | Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com> | 2016-03-24 12:29:19 +0300 |
---|---|---|
committer | Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com> | 2016-03-24 12:38:21 +0300 |
commit | 0d0de6d69a4e49cd7691fffd302be651d3ccdbce (patch) | |
tree | 3230d1fd79e41577cdc579dc5295352aa6915b9f | |
parent | 3b463748668e69ed87ec5369963f2244428d77cf (diff) |
Add algorithm/multiple_shared_lock.hpp.
-rw-r--r-- | Doxyfile | 2 | ||||
-rw-r--r-- | build/afio_v2.vcxproj | 1 | ||||
-rw-r--r-- | build/afio_v2.vcxproj.filters | 6 | ||||
-rw-r--r-- | include/boost/afio/v2/afio.hpp | 2 | ||||
-rw-r--r-- | include/boost/afio/v2/algorithm/multiple_shared_lock.hpp | 97 | ||||
-rw-r--r-- | include/boost/afio/v2/config.hpp | 4 |
6 files changed, 111 insertions, 1 deletions
@@ -765,7 +765,7 @@ WARN_LOGFILE = # spaces. See also FILE_PATTERNS and EXTENSION_MAPPING # Note: If this tag is empty the current directory is searched. -INPUT = include/boost/afio/v2 release_notes.md +INPUT = include/boost/afio/v2 include/boost/afio/v2/algorithm release_notes.md # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses diff --git a/build/afio_v2.vcxproj b/build/afio_v2.vcxproj index 01003978..45e1ee51 100644 --- a/build/afio_v2.vcxproj +++ b/build/afio_v2.vcxproj @@ -28,6 +28,7 @@ </ItemGroup> <ItemGroup> <ClInclude Include="..\include\boost\afio\v2\afio.hpp" /> + <ClInclude Include="..\include\boost\afio\v2\algorithm\multiple_shared_lock.hpp" /> <ClInclude Include="..\include\boost\afio\v2\async_file_handle.hpp" /> <ClInclude Include="..\include\boost\afio\v2\config.hpp" /> <ClInclude Include="..\include\boost\afio\v2\deadline.h" /> diff --git a/build/afio_v2.vcxproj.filters b/build/afio_v2.vcxproj.filters index 712ac9ac..63cd46c0 100644 --- a/build/afio_v2.vcxproj.filters +++ b/build/afio_v2.vcxproj.filters @@ -16,6 +16,9 @@ <Filter Include="src\windows"> <UniqueIdentifier>{1df00b33-25a0-48b7-9246-595e32c0b58e}</UniqueIdentifier> </Filter> + <Filter Include="include\algorithm"> + <UniqueIdentifier>{fc296930-fe1b-408e-be8f-bc9b8b27bd4b}</UniqueIdentifier> + </Filter> </ItemGroup> <ItemGroup> <ClInclude Include="..\include\boost\afio\v2\afio.hpp"> @@ -60,6 +63,9 @@ <ClInclude Include="..\include\boost\afio\v2\detail\impl\windows\import.hpp"> <Filter>src\windows</Filter> </ClInclude> + <ClInclude Include="..\include\boost\afio\v2\algorithm\multiple_shared_lock.hpp"> + <Filter>include\algorithm</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <None Include="..\include\boost\afio\v2\detail\impl\storage_profile.ipp"> diff --git a/include/boost/afio/v2/afio.hpp b/include/boost/afio/v2/afio.hpp index 1cd1ef04..6d32964f 100644 --- a/include/boost/afio/v2/afio.hpp +++ b/include/boost/afio/v2/afio.hpp @@ -2,4 +2,6 @@ #include "statfs.hpp" #include "storage_profile.hpp" +#include "algorithm/multiple_shared_lock.hpp" + #include "detail/child_process.hpp" diff --git a/include/boost/afio/v2/algorithm/multiple_shared_lock.hpp b/include/boost/afio/v2/algorithm/multiple_shared_lock.hpp new file mode 100644 index 00000000..4908b5be --- /dev/null +++ b/include/boost/afio/v2/algorithm/multiple_shared_lock.hpp @@ -0,0 +1,97 @@ +/* multiple_shared_lock.hpp +Efficient many actor read-write lock +(C) 2016 Niall Douglas http://www.nedprod.com/ +File Created: March 2016 + + +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. +*/ + +#ifndef BOOST_AFIO_MULTIPLE_SHARED_LOCK_HPP +#define BOOST_AFIO_MULTIPLE_SHARED_LOCK_HPP + +#include "../file_handle.hpp" + +BOOST_AFIO_V2_NAMESPACE_BEGIN + +namespace algorithm +{ + /*! \class multiple_shared_lock + \brief Efficient many actor shared/exclusive file system based lock + + Lock files scale poorly to the number of items being concurrently locked with typically an exponential + drop off in performance as the number of items being concurrently locked rises. This file system + algorithm solves this problem using IPC via a shared append-only lock file. + + - Compatible with networked file systems (NFS too if the special nfs_compatibility flag is true). + - Invariant complexity to number of items being locked. + - Linear complexity to number of processes concurrently using the lock (i.e. number of waiters). + + Caveats: + - Wasteful of disk space if used on a non-extents based filing system (e.g. FAT32, ext3). + It is best used in `/tmp` if possible. If you really must use a non-extents based filing + system, destroy and recreate the object instance periodically to force resetting the lock + file's length to zero. + - Similarly older operating systems (e.g. Linux < 3.0) do not implement extent hole punching + and therefore will also see excessive disk space consumption. Note at the time of writing + OS X doesn't implement hole punching at all. + - Byte range locks need to work properly on your system. Misconfiguring NFS or Samba + to cause byte range locks to not work right will produce bad outcomes. + - If your OS doesn't have sane byte range locks (OS X, BSD, older Linuxes) and multiple + threads in your process use the same lock file, bad things will happen due to the lack + of sanity in POSIX byte range locks. This may get fixed with a process-local byte range + lock implementation if there is demand, otherwise simply don't use the same lock file + from more than one thread on such systems. + */ + + class multiple_shared_lock + { + file_handle _h; + + public: + multiple_shared_lock() {} + multiple_shared_lock(const multiple_shared_lock &) = delete; + multiple_shared_lock &operator=(const multiple_shared_lock &) = delete; + multiple_shared_lock(multiple_shared_lock &&o) noexcept : _h(std::move(o._h)) {} + multiple_shared_lock &operator=(multiple_shared_lock &&o) noexcept + { + _h = std::move(o._h); + return *this; + } + + static result<multiple_shared_lock> init(file_handle::path_type lockfile) noexcept {} + + void lock(); + bool try_lock(); + result<void> try_lock_timed(deadline d); + void unlock(); + }; + +} // namespace + +BOOST_AFIO_V2_NAMESPACE_END + + +#endif diff --git a/include/boost/afio/v2/config.hpp b/include/boost/afio/v2/config.hpp index e9a3acf1..d73f015f 100644 --- a/include/boost/afio/v2/config.hpp +++ b/include/boost/afio/v2/config.hpp @@ -153,6 +153,10 @@ namespace boost //! Inline namespace for this version of AFIO inline namespace v2 { + //! Collection of file system based algorithms + namespace algorithm + { + } } } } |