Skip to content

Commit

Permalink
Some small correction, nothing serious. #48
Browse files Browse the repository at this point in the history
  • Loading branch information
fijiol committed Apr 16, 2010
1 parent 6bd04a5 commit 6a81873
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 48 deletions.
12 changes: 8 additions & 4 deletions extended_test/page_alloc/test_page_alloc.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @file
* @brief test page allocator
* @details
* @details Some random or interactive tests for page allocator
*
* @date 04.04.10
* @author Fedor Burdun
Expand Down Expand Up @@ -190,7 +190,7 @@ void pop() {
}

/**
* Debug output memory
* Debug output memory (print list of markers)
*/
void do_allpage() {
pmark_t* pcur = get_cmark_p();
Expand All @@ -207,8 +207,14 @@ void do_allpage() {
} while (pcur != get_cmark_p());
}

/**
* memory error counter
*/
int count_of_error = 0;

/**
* simply memory checker (sum free and alocated memory must be equal size of pool)
*/
void memory_check() {
size_t allocp = allow_page_count();
size_t freep = free_page_count();
Expand All @@ -228,7 +234,6 @@ int main() {

page_alloc_init();

//#if 0
#ifdef INTERACTIVE_TEST
printf("Input: number of tests :: ");
scanf("%d",&test_count);
Expand Down Expand Up @@ -280,6 +285,5 @@ int main() {
memory_check();

printf("\n\nMEMORY BAD SITUATION: %d\n",count_of_error);
//#endif
}

4 changes: 4 additions & 0 deletions src/include/lib/page_alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ void page_free(pmark_t *paddr);
#define PAGE_QUANTITY 0x100000
#define PAGE_SIZE 0x100

/* return pool pointer, need for test */
pmark_t* get_cmark_p();

/* evident initialize of page alloc, need for test */
int page_alloc_init(void);

#endif

#endif /* __PAGE_ALLOC_H_ */
Expand Down
67 changes: 23 additions & 44 deletions src/lib/page_alloc/page_alloc.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
/**
* @file
* @brief page allocator
* @details
* @details Use `page allocator' when we need allocate or free only one page,
* else see `multipage allocator' or `malloc'.
*
* @date 04.04.10
* @author Fedor Burdun
*/

/*
* TODO:
* rewrite (long) to (void *) or something
* :98
*/

#include <errno.h>
#include <lib/page_alloc.h>

Expand All @@ -27,8 +22,6 @@ int page_alloc_hasinit = 0;

#ifdef EXTENDED_TEST

//very TEMP!!!
// #include <stdio.h>
static uint8_t page_pool[PAGE_QUANTITY][PAGE_SIZE];
static pmark_t *cmark_p = (pmark_t *) page_pool;
#else
Expand Down Expand Up @@ -66,10 +59,8 @@ int page_alloc_init(void) {
}

/* allocate page */
pmark_t *page_alloc(void) { /* Don't work!!!! */
pmark_t *page_alloc(void) {
size_t psize = 1;
//int has_only_one_block = 0;

pmark_t *pcur,*tmp,*tt;

if (!page_alloc_hasinit) {
Expand All @@ -87,41 +78,29 @@ pmark_t *page_alloc(void) { /* Don't work!!!! */
/* find first proper block */
pcur = cmark_p;

#if 0
if (pcur->pnext == pcur) {
has_only_one_block = 1;
}
#endif

/* check finded block */
//if ( pcur->psize >= psize ) {
/* change list and return value */
if (pcur->psize > psize ) {
tt = (unsigned long) pcur + (unsigned long) PAGE_SIZE *
(unsigned long) psize; /* I'm not sure that it's good idea */
pcur->psize -= psize;
tmp = cmark_p->pnext;
//cmark_p->pprev->pnext = pcur + PAGE_SIZE * psize;
//tmp->pprev = pcur + PAGE_SIZE * psize;
//cmark_p = copy_mark( pcur , pcur + PAGE_SIZE * psize );
cmark_p->pprev->pnext = tt;
tmp->pprev = tt;
cmark_p = copy_mark( pcur , tt );

/* change list and return value */
if (pcur->psize > psize ) {
tt = (unsigned long) pcur + (unsigned long) PAGE_SIZE *
(unsigned long) psize;
pcur->psize -= psize;
tmp = cmark_p->pnext;
cmark_p->pprev->pnext = tt;
tmp->pprev = tt;
cmark_p = copy_mark( pcur , tt );
return pcur;
} else {
if (pcur->pnext == pcur) {
cmark_p = NULL;
return NULL;
} else { /* psize == pcur->psize */
pcur->pprev->pnext = pcur->pnext;
pcur->pnext->pprev = pcur->pprev;
cmark_p = pcur->pnext;
return pcur;
} else {
if (pcur->pnext == pcur) {
cmark_p = NULL;
return NULL;
} else {
/* psize == pcur->psize */
pcur->pprev->pnext = pcur->pnext;
pcur->pnext->pprev = pcur->pprev;
cmark_p = pcur->pnext;
return pcur;
}
}
//}

}
return NULL;
}

Expand Down

0 comments on commit 6a81873

Please sign in to comment.