Mercurial > hg > Game > Cerium
view TaskManager/kernel/ppe/DmaBuffer.cc @ 498:bce667ff20b9 draft
double linked HTaskInfo/HTask
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 11 Oct 2009 11:46:41 +0900 |
parents | 504899860e66 |
children | 92b0d490e839 |
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]; }