Skip to content

Commit

Permalink
Squashed 'src/mio/' changes from c7c7163a..88e0263b
Browse files Browse the repository at this point in the history
88e0263b Fix memory mapped data offset
514837b2 Update test.cpp
18fbf199 Fix minor errors in internal docs
cafa3136 Merge pull request #40 from patrick--/single_header
3c655b70 Added single header file information to the README
647e9779 Initial single header support using amalgamate
3c658bf6 Merge pull request #38 from amallia/patch-1
d25c02f0 Update mmap.ipp
d35a6db8 Update mmap.ipp

git-subtree-dir: src/mio
git-subtree-split: 88e0263b075b832e78b9a36df58575a96ffe5e7d
  • Loading branch information
jimhester committed Apr 18, 2019
1 parent 9fdd892 commit ac62e7a
Show file tree
Hide file tree
Showing 8 changed files with 2,140 additions and 26 deletions.
7 changes: 7 additions & 0 deletions README.md
Expand Up @@ -181,6 +181,12 @@ using mmap_sink = mio::basic_mmap_sink<std::byte>;

Though generally not needed, since mio maps users requested offsets to page boundaries, you can query the underlying system's page allocation granularity by invoking `mio::page_size()`, which is located in `mio/page.hpp`.

### Single Header File
Mio can be added to your project as a single header file simply by including `\single_include\mio\mio.hpp`. Single header files can be regenerated at any time by running the `amalgamate.py` script within `\third_party`.
```
python amalgamate.py -c config.json -s ../include
```

## CMake
As a header-only library, mio has no compiled components. Nevertheless, a [CMake](https://cmake.org/overview/) build system is provided to allow easy testing, installation, and subproject composition on many platforms and operating systems.

Expand Down Expand Up @@ -328,3 +334,4 @@ target_link_libraries( MyTarget PUBLIC <mio::mio | mio> )
```

Note that, as a subproject, mio's tests and examples will not be built and CPack integration is deferred to the host project.

11 changes: 6 additions & 5 deletions include/mio/detail/mmap.ipp
Expand Up @@ -124,7 +124,7 @@ file_handle_type open_file(const String& path, const access_mode mode,
return handle;
}

inline int64_t query_file_size(file_handle_type handle, std::error_code& error)
inline size_t query_file_size(file_handle_type handle, std::error_code& error)
{
error.clear();
#ifdef _WIN32
Expand Down Expand Up @@ -201,7 +201,7 @@ inline mmap_context memory_map(const file_handle_type file_handle, const int64_t
}
#endif
mmap_context ctx;
ctx.data = mapping_start + offset - aligned_offset;
ctx.data = mapping_start + offset;
ctx.length = length;
ctx.mapped_length = length_to_map;
#ifdef _WIN32
Expand Down Expand Up @@ -400,9 +400,10 @@ void basic_mmap<AccessMode, ByteT>::unmap()
if(data_) { ::munmap(const_cast<pointer>(get_mapping_start()), mapped_length_); }
#endif

// If file_handle_ was obtained by our opening it (when map is called with a path,
// rather than an existing file handle), we need to close it, otherwise it must not
// be closed as it may still be used outside this instance.
// If `file_handle_` was obtained by our opening it (when map is called with
// a path, rather than an existing file handle), we need to close it,
// otherwise it must not be closed as it may still be used outside this
// instance.
if(is_handle_internal_)
{
#ifdef _WIN32
Expand Down
16 changes: 9 additions & 7 deletions include/mio/mmap.hpp
Expand Up @@ -76,15 +76,17 @@ struct basic_mmap
// Points to the first requested byte, and not to the actual start of the mapping.
pointer data_ = nullptr;

// Length, in bytes, requested by user, which may not be the length of the full
// mapping, and the entire length of the full mapping.
// Length--in bytes--requested by user (which may not be the length of the
// full mapping) and the length of the full mapping.
size_type length_ = 0;
size_type mapped_length_ = 0;

// Letting user map a file using both an existing file handle and a path introcudes
// On POSIX, we only need a file handle to create a mapping, while on Windows
// systems the file handle is necessary to retrieve a file mapping handle, but any
// subsequent operations on the mapped region must be done through the latter.
// Letting user map a file using both an existing file handle and a path
// introcudes some complexity (see `is_handle_internal_`).
// On POSIX, we only need a file handle to create a mapping, while on
// Windows systems the file handle is necessary to retrieve a file mapping
// handle, but any subsequent operations on the mapped region must be done
// through the latter.
handle_type file_handle_ = INVALID_HANDLE_VALUE;
#ifdef _WIN32
handle_type file_mapping_handle_ = INVALID_HANDLE_VALUE;
Expand All @@ -94,7 +96,7 @@ struct basic_mmap
// introcudes some complexity in that we must not close the file handle if
// user provided it, but we must close it if we obtained it using the
// provided path. For this reason, this flag is used to determine when to
// close file_handle_.
// close `file_handle_`.
bool is_handle_internal_;

public:
Expand Down

0 comments on commit ac62e7a

Please sign in to comment.