Mercurial > hg > Members > kono > Cerium
view TaskManager/kernel/ppe/DmaBuffer.cc @ 88:504899860e66
*** empty log message ***
author | gongo |
---|---|
date | Wed, 27 Feb 2008 17:16:29 +0900 |
parents | 61bacd3b4405 |
children | 1733f3cbfa28 |
line wrap: on
line source
#include <stdio.h> #include <stdlib.h> #include "types.h" #include "DmaBuffer.h" #define ALIGN_DOWN(v, align) ((v)&(-align)) #define ALIGN_UP(v, align) ALIGN_DOWN((v)+((align)-1), align) void* new_align(int alignment, int size) { char *nonalign; char *align; nonalign = new char[size + sizeof(void*) + alignment - 1]; align = (char*)(ALIGN_UP((unsigned int)nonalign+sizeof(void*),alignment)); *((void**)align - 1) = (void*)nonalign; return align; } void free_align(void *ptr) { char *real; if (ptr != NULL) { real = (char*)(*((void**)(ptr)-1)); delete real; } } DmaBuffer::DmaBuffer(int size) { buffer[0] = malloc(size); buffer[1] = malloc(size); //posix_memalign(&buffer[0], DEFAULT_ALIGNMENT, size); //posix_memalign(&buffer[1], DEFAULT_ALIGNMENT, size); //buffer[0] = new_align(DEFAULT_ALIGNMENT, size); //buffer[1] = new_align(DEFAULT_ALIGNMENT, size); flag = 0; } DmaBuffer::~DmaBuffer(void) { //free(buffer[0]); //free(buffer[1]); free_align(buffer[0]); free_align(buffer[1]); } void DmaBuffer::swap_buffer(void) { flag ^= 1; } void DmaBuffer::get_buffer(void *_dst) { void **dst = (void**)_dst; *dst = buffer[flag]; }