Mercurial > hg > Members > kono > Cerium
changeset 43:db136fb5c21d
*** empty log message ***
author | gongo |
---|---|
date | Thu, 14 Feb 2008 19:37:14 +0900 |
parents | aa11038dbdc1 |
children | b51daa049bc3 |
files | TaskManager/kernel/ppe/BufferManager.cc TaskManager/kernel/ppe/TaskManager.cc include/TaskManager/BufferManager.h include/TaskManager/error.h |
diffstat | 4 files changed, 126 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/kernel/ppe/BufferManager.cc Thu Feb 14 19:37:14 2008 +0900 @@ -0,0 +1,73 @@ +#include <stdlib.h> +#include "BufferManager.h" +#include "error.h" + +BufferManager::BufferManager(int siz) +{ + buffer_db_size = siz; +} + +void +BufferManager::init(void) +{ + buffer_db = new void*[buffer_db_size*4]; + buffer_db_index = 0; +} + +/** + * Fix me + * アライメントできる create も必要 (spe 用に) + * あと、オブジェクトだったら new しないとだめか。 + * コンストラクタ呼ぶ必要があるのかー。 + * 汎用の allocate ってことは templete ?いやだー + */ +void* +BufferManager::create_buffer(int size) +{ + void *buf1, *buf2; + + buf1 = malloc(size); + buf2 = malloc(size); + + register_double_buffer(buf1, buf2); + + return buf1; +} + +void* +BufferManager::switch_buffer(void* cur) +{ + int next_index; + int max = buffer_db_size*4; + + for (int i = 0; i < max; i = i + 2) { + if (cur == buffer_db[i]) { + next_index = (int)(buffer_db[i+1]); + return buffer_db[i + next_index]; + } + } + + __debug_ppe("buffer 0x%x is not registered\n", (unsigned int)cur); + + return NULL; +} + +int +BufferManager::register_double_buffer(void *buf1, void *buf2) +{ + /** + * Fix me + * buffer_db_size 超えた時の処理 + * 今は単純に -1 < 0 を返す + */ + if (buffer_db_index == buffer_db_size) { + return -1; + } + + buffer_db[buffer_db_index++] = buf1; + buffer_db[buffer_db_index++] = (void*)2; + buffer_db[buffer_db_index++] = buf2; + buffer_db[buffer_db_index++] = (void*)-2; + + return 0; +}
--- a/TaskManager/kernel/ppe/TaskManager.cc Thu Feb 14 18:27:37 2008 +0900 +++ b/TaskManager/kernel/ppe/TaskManager.cc Thu Feb 14 19:37:14 2008 +0900 @@ -1,5 +1,6 @@ #include "TaskManager.h" #include "SymTable.h" +#include "BufferManager.h" TaskManager::TaskManager(int num) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/TaskManager/BufferManager.h Thu Feb 14 19:37:14 2008 +0900 @@ -0,0 +1,51 @@ +#ifndef INCLUDED_BUFFER_MANAGER +#define INCLUDED_BUFFER_MANAGER + +#if 0 +buffer database の中身 + ++-----------+ +| buffer 1 | ++-----------+ +| 2 | ++-----------+ +| buffer 2 | ++-----------+ +| -2 | ++-----------+ +| buffer 3 | ++-----------+ +| 2 | ++-----------+ +| buffer 4 | ++-----------+ +| -2 | ++-----------+ +| ... | + +各 buffer の次の buffer を取得する時は +buffer 1 が db[i] とすると + +next_index = db[i+1]; +next_buffer = db[i + next_index]; + +でとれると思ったり思わなかったり。 +各bufferでフラグを持つ必要なくなる(とおもってる) + +#endif + +class BufferManager { +public: + BufferManager(int siz = 10); + + void **buffer_db; + int buffer_db_size; + int buffer_db_index; + + void init(void); + void *create_buffer(int size); + void *switch_buffer(void* buffer); + int register_double_buffer(void *buf1, void *buf2); +}; + +#endif