mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-20 05:33:47 -04:00
shm: prefer posix_fallocate over ftruncate
This commit is contained in:
parent
291410bd71
commit
db830643d2
1 changed files with 14 additions and 3 deletions
17
shm.c
17
shm.c
|
|
@ -6,6 +6,7 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <linux/memfd.h>
|
#include <linux/memfd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
#include <pixman.h>
|
#include <pixman.h>
|
||||||
|
|
||||||
|
|
@ -123,9 +124,19 @@ shm_get_buffer(struct wl_shm *shm, int width, int height, unsigned long cookie)
|
||||||
size = stride * height;
|
size = stride * height;
|
||||||
LOG_DBG("cookie=%lx: allocating new buffer: %zu KB", cookie, size / 1024);
|
LOG_DBG("cookie=%lx: allocating new buffer: %zu KB", cookie, size / 1024);
|
||||||
|
|
||||||
if (ftruncate(pool_fd, size) == -1) {
|
int err = posix_fallocate(pool_fd, 0, size);
|
||||||
LOG_ERRNO("failed to truncate SHM pool");
|
if (err != 0) {
|
||||||
goto err;
|
static bool failure_logged = false;
|
||||||
|
|
||||||
|
if (!failure_logged) {
|
||||||
|
failure_logged = true;
|
||||||
|
LOG_ERRNO_P("failed to fallocate", err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ftruncate(pool_fd, size) == -1) {
|
||||||
|
LOG_ERRNO("failed to truncate SHM pool");
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mmapped = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, pool_fd, 0);
|
mmapped = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, pool_fd, 0);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue