1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
/*
* Purpose: OSS memory block allocation and management routines.
*/
/*
*
* This file is part of Open Sound System.
*
* Copyright (C) 4Front Technologies 1996-2008.
*
* This this source file is released under GPL v2 license (no other versions).
* See the COPYING file included in the main directory of this source
* distribution for the license terms and conditions.
*
*/
#include <oss_config.h>
struct _oss_memblk_t
{
oss_memblk_t *next;
void *addr;
};
oss_memblk_t *oss_global_memblk=NULL;
void
*oss_memblk_malloc(oss_memblk_t **blk, int size)
{
oss_memblk_t *newblk;
newblk = KERNEL_MALLOC (sizeof(oss_memblk_t) + size);
newblk->addr = newblk +1;
newblk->next = NULL;
if (*blk == NULL)
{
/*
* No earlier memory blocks in the chain.
*/
*blk = newblk;
return newblk->addr;
}
/*
* Add this block to the chain.
*/
newblk->next = *blk;
*blk = newblk;
return newblk->addr;
}
void
oss_memblk_free(oss_memblk_t **blk, void *addr)
{
oss_memblk_t *this_one = *blk, *prev = NULL;
while (this_one != NULL)
{
if (this_one->addr == addr)
{
if (prev == NULL) /* First one in the chain */
{
*blk = this_one->next;
KERNEL_FREE (this_one);
}
else
{
prev->next = this_one->next;
KERNEL_FREE (this_one);
}
return;
}
this_one = this_one->next;
}
}
void
oss_memblk_unalloc(oss_memblk_t **blk)
{
/*
* Free all memory allocations on the chain.
*/
oss_memblk_t *this_one = *blk;
while (this_one != NULL)
{
oss_memblk_t *next_one;
next_one = this_one->next;
KERNEL_FREE(this_one);
this_one = next_one;
}
*blk = NULL;
}
|