bc6600175c
Many bug fixes Some formatting changes. Introduction of vnodeManager - to allow cached, opened and mmapped files to work together in love, peace and harmony. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2012 a95241bf-73f2-0310-859d-f6bbb57e9c96
51 lines
1.2 KiB
C++
51 lines
1.2 KiB
C++
#include "pageManager.h"
|
|
|
|
#include "vmHeaderBlock.h"
|
|
|
|
extern vmHeaderBlock *vmBlock;
|
|
/* This is the template
|
|
* replace TYPE with the type you need a pool for
|
|
*
|
|
class poolTYPE
|
|
{
|
|
private:
|
|
list unused;
|
|
sem_id inUse;
|
|
public:
|
|
poolTYPE(void) { inUse = create_sem(1,"TYPEpool");
|
|
}
|
|
TYPE *get(void) {
|
|
TYPE *ret=NULL;
|
|
if (unused.count()) {
|
|
error ("poolTYPE::get: Getting an unused one!\n");
|
|
acquire_sem(inUse);
|
|
ret=(TYPE *)unused.next();
|
|
release_sem(inUse);
|
|
}
|
|
if (ret) {
|
|
error ("poolTYPE::get: Returning address:%x \n",ret);
|
|
return ret;
|
|
}
|
|
else {
|
|
error ("poolTYPE::get: Getting a new page!\n");
|
|
page *newPage=vmBlock->pageMan->getPage();
|
|
if (!newPage)
|
|
throw ("Out of pages to allocate a pool!");
|
|
int newCount=PAGE_SIZE/sizeof(TYPE);
|
|
acquire_sem(inUse);
|
|
error ("poolTYPE::get: Adding %d new elements to the pool!\n",newCount);
|
|
for (int i=0;i<newCount;i++)
|
|
unused.add(((void *)(newPage->getAddress()+(i*sizeof(TYPE)))));
|
|
release_sem(inUse);
|
|
return (get()); // A little cheat - call self again to get the first one from stack...
|
|
}
|
|
}
|
|
|
|
void put(TYPE *in) {
|
|
acquire_sem(inUse);
|
|
unused.add(in);
|
|
release_sem(inUse);
|
|
}
|
|
};
|
|
*/
|