mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-15 07:00:05 -05:00
mem: add mmap helper
Add function and structure to help with mmap and mlock
This commit is contained in:
parent
3a9070ee10
commit
ccd19f1e49
2 changed files with 21 additions and 1 deletions
|
|
@ -118,7 +118,8 @@ struct spa_fraction {
|
||||||
#define SPA_DEPRECATED
|
#define SPA_DEPRECATED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SPA_ROUND_UP_N(num,align) ((((num) + ((align) - 1)) & ~((align) - 1)))
|
#define SPA_ROUND_DOWN_N(num,align) ((num) & ~((align) - 1))
|
||||||
|
#define SPA_ROUND_UP_N(num,align) SPA_ROUND_DOWN_N((num) + ((align) - 1),align)
|
||||||
|
|
||||||
#ifndef SPA_LIKELY
|
#ifndef SPA_LIKELY
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,25 @@ pw_memblock_free(struct pw_memblock *mem);
|
||||||
/** Find memblock for given \a ptr */
|
/** Find memblock for given \a ptr */
|
||||||
struct pw_memblock * pw_memblock_find(const void *ptr);
|
struct pw_memblock * pw_memblock_find(const void *ptr);
|
||||||
|
|
||||||
|
/** parameters to map a memory range */
|
||||||
|
struct pw_map_range {
|
||||||
|
uint32_t start; /** offset in first page with start of data */
|
||||||
|
uint32_t offset; /** page aligned offset to map */
|
||||||
|
uint32_t size; /** size to map */
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Calculate parameters to mmap() memory into \a range so that
|
||||||
|
* \a size bytes at \a offset can be mapped with mmap(). */
|
||||||
|
static inline void pw_map_range_init(struct pw_map_range *range,
|
||||||
|
uint32_t offset, uint32_t size,
|
||||||
|
uint32_t page_size)
|
||||||
|
{
|
||||||
|
range->offset = SPA_ROUND_DOWN_N(offset, page_size);
|
||||||
|
range->start = offset - range->offset;
|
||||||
|
range->size = offset + size - range->offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue