cached BBuffer object are not allowed to be deleted until they are Recycled,

temporary changed to never delete them...


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4541 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
beveloper 2003-09-07 22:35:06 +00:00
parent 344122f0e3
commit 8d481eeefd
2 changed files with 21 additions and 69 deletions

View File

@ -10,75 +10,36 @@
#include "BufferIdCache.h"
#include "debug.h"
_buffer_id_cache::_buffer_id_cache() :
in_use(0),
used(0),
stat_missed(0),
stat_hit(0)
// XXX we are not allowed to delete BBuffer objects when they are not recycled
_buffer_id_cache::_buffer_id_cache()
{
for (int i = 0; i < MAX_CACHED_BUFFER; i++) {
info[i].buffer = 0;
info[i].id = 0;
info[i].last_used = 0;
}
}
_buffer_id_cache::~_buffer_id_cache()
{
for (int i = 0; i < MAX_CACHED_BUFFER; i++)
if (info[i].buffer)
delete info[i].buffer;
TRACE("### _buffer_id_cache finished, %ld in_use, %ld used, %ld hit, %ld missed\n",in_use,used,stat_hit,stat_missed);
// XXX deleting buffers here is not save, too
/*
fMap.Rewind();
BBuffer **buffer;
while (fMap.GetNext(&buffer)) {
fMap.RemoveCurrent();
delete *buffer;
}
*/
}
BBuffer *
_buffer_id_cache::GetBuffer(media_buffer_id id)
{
if (id == 0)
debugger("_buffer_id_cache::GetBuffer called with 0 id\n");
used++;
BBuffer **buffer;
if (fMap.Get(id, &buffer))
return *buffer;
// try to find in cache
for (int i = 0; i < MAX_CACHED_BUFFER; i++) {
if (info[i].id == id) {
stat_hit++;
info[i].last_used = used;
return info[i].buffer;
}
}
stat_missed++;
// remove last recently used
if (in_use == MAX_CACHED_BUFFER) {
int32 min_last_used = used;
int index = 0;
for (int i = 0; i < MAX_CACHED_BUFFER; i++) {
if (info[i].last_used < min_last_used) {
min_last_used = info[i].last_used;
index = i;
}
}
delete info[index].buffer;
info[index].buffer = NULL;
in_use--;
}
BBuffer *buffer;
buffer_clone_info ci;
ci.buffer = id;
buffer = new BBuffer(ci);
BBuffer *buf = new BBuffer(ci);
// insert into cache
for (int i = 0; i < MAX_CACHED_BUFFER; i++) {
if (info[i].buffer == NULL) {
info[i].buffer = buffer;
info[i].id = id;
info[i].last_used = used;
in_use++;
break;
}
}
return buffer;
fMap.Insert(id, buf);
return buf;
}

View File

@ -8,6 +8,8 @@
#ifndef _BUFFER_ID_CACHE_H_
#define _BUFFER_ID_CACHE_H_
#include "TMap.h"
class _buffer_id_cache
{
public:
@ -17,18 +19,7 @@ public:
BBuffer *GetBuffer(media_buffer_id id);
private:
enum { MAX_CACHED_BUFFER = 17 };
struct _buffer_id_info
{
BBuffer *buffer;
media_buffer_id id;
int32 last_used;
};
_buffer_id_info info[MAX_CACHED_BUFFER];
int32 in_use;
int32 used;
int32 stat_missed;
int32 stat_hit;
Map<media_buffer_id, BBuffer *> fMap;
};
#endif