]> git.alsa-project.org Git - alsa-lib.git/commitdiff
Transformed PAGE_SIZE in sysconf(_SC_PAGE_SIZE)
authorAbramo Bagnara <abramo@alsa-project.org>
Wed, 21 Feb 2001 21:59:35 +0000 (21:59 +0000)
committerAbramo Bagnara <abramo@alsa-project.org>
Wed, 21 Feb 2001 21:59:35 +0000 (21:59 +0000)
include/local.h
src/pcm/pcm_hw.c
src/pcm/pcm_mmap.c
src/rawmidi/rawmidi.c

index 38b1b22e13fa83bd39fd3bd3cb66edc49e62df4e..ef8c5dfe246f4f0cb489fcd580409da1ed326025 100644 (file)
@@ -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
index d38e53b108d98bbb20234a524bf44cd84af699ce..8c4714eca5fd96494a123e4b62c2b4c1470e5e4f 100644 (file)
@@ -28,7 +28,6 @@
 #include <sys/ioctl.h>
 #include <sys/mman.h>
 #include <sys/shm.h>
-#include <asm/page.h>
 #include "pcm_local.h"
 #include "../control/control_local.h"
 
 #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;
        }
index 1e4cd20dd746a9d726269b3e5576db04ef21a6fe..1eee430bd67184047f90b72008e1c66fa9afbe55 100644 (file)
 #include <sys/poll.h>
 #include <sys/mman.h>
 #include <sys/shm.h>
-#include <asm/page.h>
 #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
index 7dd902e0625119aba758855d7ac22161276ef415..5297c648206ad12526cbc6bbc8b5736807e24ca1 100644 (file)
@@ -25,7 +25,6 @@
 #include <unistd.h>
 #include <string.h>
 #include <dlfcn.h>
-#include <asm/page.h>
 #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;