From: Abramo Bagnara Date: Wed, 21 Feb 2001 21:59:35 +0000 (+0000) Subject: Transformed PAGE_SIZE in sysconf(_SC_PAGE_SIZE) X-Git-Tag: v1.0.3~943 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=c663f4f4f700529fca28c71ec39d77e35a4d6508;p=alsa-lib.git Transformed PAGE_SIZE in sysconf(_SC_PAGE_SIZE) --- diff --git a/include/local.h b/include/local.h index 38b1b22e..ef8c5dfe 100644 --- a/include/local.h +++ b/include/local.h @@ -68,4 +68,7 @@ typedef enum _snd_set_mode snd_set_mode_t; #define SND_TRY ((snd_set_mode_t) SND_TRY) #define SND_TEST ((snd_set_mode_t) SND_TEST) +size_t page_align(size_t size); +size_t page_size(void); + #endif diff --git a/src/pcm/pcm_hw.c b/src/pcm/pcm_hw.c index d38e53b1..8c4714ec 100644 --- a/src/pcm/pcm_hw.c +++ b/src/pcm/pcm_hw.c @@ -28,7 +28,6 @@ #include #include #include -#include #include "pcm_local.h" #include "../control/control_local.h" @@ -36,10 +35,6 @@ #define F_SETSIG 10 #endif -#ifndef PAGE_ALIGN -#define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK) -#endif - typedef struct { int fd; int card, device, subdevice; @@ -366,7 +361,7 @@ static int snd_pcm_hw_mmap_status(snd_pcm_t *pcm) { snd_pcm_hw_t *hw = pcm->private_data; void *ptr; - ptr = mmap(NULL, PAGE_ALIGN(sizeof(struct sndrv_pcm_mmap_status)), PROT_READ, MAP_FILE|MAP_SHARED, + ptr = mmap(NULL, page_align(sizeof(struct sndrv_pcm_mmap_status)), PROT_READ, MAP_FILE|MAP_SHARED, hw->fd, SND_PCM_MMAP_OFFSET_STATUS); if (ptr == MAP_FAILED || ptr == NULL) { SYSERR("status mmap failed"); @@ -381,7 +376,7 @@ static int snd_pcm_hw_mmap_control(snd_pcm_t *pcm) { snd_pcm_hw_t *hw = pcm->private_data; void *ptr; - ptr = mmap(NULL, PAGE_ALIGN(sizeof(struct sndrv_pcm_mmap_control)), PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, + ptr = mmap(NULL, page_align(sizeof(struct sndrv_pcm_mmap_control)), PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, hw->fd, SND_PCM_MMAP_OFFSET_CONTROL); if (ptr == MAP_FAILED || ptr == NULL) { SYSERR("control mmap failed"); @@ -395,7 +390,7 @@ static int snd_pcm_hw_mmap_control(snd_pcm_t *pcm) static int snd_pcm_hw_munmap_status(snd_pcm_t *pcm) { snd_pcm_hw_t *hw = pcm->private_data; - if (munmap((void*)hw->mmap_status, PAGE_ALIGN(sizeof(*hw->mmap_status))) < 0) { + if (munmap((void*)hw->mmap_status, page_align(sizeof(*hw->mmap_status))) < 0) { SYSERR("status munmap failed"); return -errno; } @@ -405,7 +400,7 @@ static int snd_pcm_hw_munmap_status(snd_pcm_t *pcm) static int snd_pcm_hw_munmap_control(snd_pcm_t *pcm) { snd_pcm_hw_t *hw = pcm->private_data; - if (munmap(hw->mmap_control, PAGE_ALIGN(sizeof(*hw->mmap_control))) < 0) { + if (munmap(hw->mmap_control, page_align(sizeof(*hw->mmap_control))) < 0) { SYSERR("control munmap failed"); return -errno; } diff --git a/src/pcm/pcm_mmap.c b/src/pcm/pcm_mmap.c index 1e4cd20d..1eee430b 100644 --- a/src/pcm/pcm_mmap.c +++ b/src/pcm/pcm_mmap.c @@ -24,14 +24,25 @@ #include #include #include -#include #include "pcm_local.h" +size_t page_size(void) +{ + long s = sysconf(_SC_PAGE_SIZE); + assert(s > 0); + return s; +} -#ifndef PAGE_ALIGN -#define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK) -#endif - +size_t page_align(size_t size) +{ + size_t r; + long psz = sysconf(_SC_PAGE_SIZE); + assert(psz > 0); + r = size % psz; + if (r) + return size + psz - r; + return size; +} const snd_pcm_channel_area_t *snd_pcm_mmap_running_areas(snd_pcm_t *pcm) { @@ -304,7 +315,7 @@ int snd_pcm_mmap(snd_pcm_t *pcm) size = s; } size = (size + 7) / 8; - size = PAGE_ALIGN(size); + size = page_align(size); switch (i->type) { case SND_PCM_AREA_MMAP: ptr = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, i->u.mmap.fd, i->u.mmap.offset); @@ -384,7 +395,7 @@ int snd_pcm_munmap(snd_pcm_t *pcm) size = s; } size = (size + 7) / 8; - size = PAGE_ALIGN(size); + size = page_align(size); switch (i->type) { case SND_PCM_AREA_MMAP: #if 0 diff --git a/src/rawmidi/rawmidi.c b/src/rawmidi/rawmidi.c index 7dd902e0..5297c648 100644 --- a/src/rawmidi/rawmidi.c +++ b/src/rawmidi/rawmidi.c @@ -25,7 +25,6 @@ #include #include #include -#include #include "rawmidi_local.h" const char *snd_rawmidi_name(snd_rawmidi_t *rawmidi) @@ -160,7 +159,7 @@ int snd_rawmidi_params_default(snd_rawmidi_t *rmidi, snd_rawmidi_params_t *param { assert(rmidi); assert(params); - params->buffer_size = PAGE_SIZE; + params->buffer_size = page_size(); params->avail_min = 1; params->no_active_sensing = 0; return 0;