template<class T>
class llfio_v2_xxx::algorithm::cached_parent_handle_adapter< T >
Adapts any construct()
-able implementation to cache its parent directory handle in a process wide cache.
For some use cases where one is calling parent_path_handle()
or code which calls that function very frequently e.g. calling relink()
or unlink()
a lot on many files with the same parent directory, having to constantly fetch the current path, open the parent directory and verify inodes becomes unhelpfully inefficient. This adapter keeps a process-wide hash table of directory handles shared between all instances of this adapter, thus making calling parent_path_handle()
almost zero cost.
This adapter is of especial use on platforms which do not reliably implement per-fd path tracking for regular files (Apple MacOS, FreeBSD) as current_path()
is reimplemented to use the current path of the shared parent directory instead. One loses race freedom within the contained directory, but that is the case on POSIX anyway.
This adapter is also of use on platforms which do not implement path tracking for open handles at all (e.g. Linux without /proc
mounted) as the process-wide cache of directory handles retains the path of the directory handle at the time of creation. Third party changes to the part of the filesystem you are working upon will result in the inability to do race free unlinking etc, but if no third party changes are encountered it ought to work well.
- Todo:
- I have been lazy and used public inheritance from that base i/o handle. I should use protected inheritance to prevent slicing, and expose all the public functions by hand.