Skip to content

Instantly share code, notes, and snippets.

@npentrel
Created March 16, 2020 14:32
Show Gist options
  • Save npentrel/e602db9143fae92678487e6d567faf8a to your computer and use it in GitHub Desktop.
Save npentrel/e602db9143fae92678487e6d567faf8a to your computer and use it in GitHub Desktop.
read_mmap:
/* Atomically increment the reference counter,
* so no one unmaps the buffer while we use it. */
atomic_add(mmap_use_count, 1);
/* If the buffer is being resized, use the system call instead of the mapped buffer. */
if (mmap_resizing)
atomic_decr(mmap_use_count, 1);
read_syscall(...);
else
memcpy(dst_buffer, mapped_buffer, …);
atomic_decr(mmap_use_count, 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment