OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [runtime/] [mfixalloc.c] - Blame information for rev 820

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// Copyright 2009 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
4
 
5
// Fixed-size object allocator.  Returned memory is not zeroed.
6
//
7
// See malloc.h for overview.
8
 
9
#include "runtime.h"
10
#include "arch.h"
11
#include "malloc.h"
12
 
13
// Initialize f to allocate objects of the given size,
14
// using the allocator to obtain chunks of memory.
15
void
16
runtime_FixAlloc_Init(FixAlloc *f, uintptr size, void *(*alloc)(uintptr), void (*first)(void*, byte*), void *arg)
17
{
18
        f->size = size;
19
        f->alloc = alloc;
20
        f->first = first;
21
        f->arg = arg;
22
        f->list = nil;
23
        f->chunk = nil;
24
        f->nchunk = 0;
25
        f->inuse = 0;
26
        f->sys = 0;
27
}
28
 
29
void*
30
runtime_FixAlloc_Alloc(FixAlloc *f)
31
{
32
        void *v;
33
 
34
        if(f->list) {
35
                v = f->list;
36
                f->list = *(void**)f->list;
37
                f->inuse += f->size;
38
                return v;
39
        }
40
        if(f->nchunk < f->size) {
41
                f->sys += FixAllocChunk;
42
                f->chunk = f->alloc(FixAllocChunk);
43
                if(f->chunk == nil)
44
                        runtime_throw("out of memory (FixAlloc)");
45
                f->nchunk = FixAllocChunk;
46
        }
47
        v = f->chunk;
48
        if(f->first)
49
                f->first(f->arg, v);
50
        f->chunk += f->size;
51
        f->nchunk -= f->size;
52
        f->inuse += f->size;
53
        return v;
54
}
55
 
56
void
57
runtime_FixAlloc_Free(FixAlloc *f, void *p)
58
{
59
        f->inuse -= f->size;
60
        *(void**)p = f->list;
61
        f->list = p;
62
}
63
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.