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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [services/] [memalloc/] [common/] [current/] [include/] [dlmallocimpl.hxx] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
#ifndef CYGONCE_MEMALLOC_DLMALLOCIMPL_HXX
2
#define CYGONCE_MEMALLOC_DLMALLOCIMPL_HXX
3
 
4
//==========================================================================
5
//
6
//      dlmallocimpl.hxx
7
//
8
//      Interface to the port of Doug Lea's malloc implementation
9
//
10
//==========================================================================
11
// ####ECOSGPLCOPYRIGHTBEGIN####
12
// -------------------------------------------
13
// This file is part of eCos, the Embedded Configurable Operating System.
14
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
15
//
16
// eCos is free software; you can redistribute it and/or modify it under
17
// the terms of the GNU General Public License as published by the Free
18
// Software Foundation; either version 2 or (at your option) any later
19
// version.
20
//
21
// eCos is distributed in the hope that it will be useful, but WITHOUT
22
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
24
// for more details.
25
//
26
// You should have received a copy of the GNU General Public License
27
// along with eCos; if not, write to the Free Software Foundation, Inc.,
28
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
29
//
30
// As a special exception, if other files instantiate templates or use
31
// macros or inline functions from this file, or you compile this file
32
// and link it with other works to produce a work based on this file,
33
// this file does not by itself cause the resulting work to be covered by
34
// the GNU General Public License. However the source code for this file
35
// must still be made available in accordance with section (3) of the GNU
36
// General Public License v2.
37
//
38
// This exception does not invalidate any other reasons why a work based
39
// on this file might be covered by the GNU General Public License.
40
// -------------------------------------------
41
// ####ECOSGPLCOPYRIGHTEND####
42
//==========================================================================
43
//#####DESCRIPTIONBEGIN####
44
//
45
// Author(s):    jlarmour
46
// Contributors:
47
// Date:         2000-06-18
48
// Purpose:      Define standard interface to Doug Lea's malloc implementation
49
// Description:  Doug Lea's malloc has been ported to eCos. This file provides
50
//               the interface between the implementation and the standard
51
//               memory allocator interface required by eCos
52
// Usage:        #include 
53
//
54
//
55
//####DESCRIPTIONEND####
56
//
57
//==========================================================================
58
 
59
// CONFIGURATION
60
 
61
#include 
62
 
63
// INCLUDES
64
 
65
#include                     // size_t, ptrdiff_t
66
#include         // types
67
 
68
#include      // Common memory allocator infra
69
 
70
// As a special case, override CYGIMP_MEMALLOC_ALLOCATOR_DLMALLOC_SAFE_MULTIPLE
71
// if the malloc config says so
72
#ifdef CYGIMP_MEMALLOC_MALLOC_DLMALLOC
73
// forward declaration to prevent header dependency problems
74
class Cyg_Mempool_dlmalloc;
75
# include 
76
# if (CYGMEM_HEAP_COUNT > 1) && \
77
     !defined(CYGIMP_MEMALLOC_ALLOCATOR_DLMALLOC_SAFE_MULTIPLE)
78
#  define CYGIMP_MEMALLOC_ALLOCATOR_DLMALLOC_SAFE_MULTIPLE 1
79
# endif
80
#endif
81
 
82
// CONSTANTS
83
 
84
// number of bins - but changing this alone will not change the number of
85
// bins!
86
#define CYGPRI_MEMALLOC_ALLOCATOR_DLMALLOC_NAV 128
87
 
88
// TYPE DEFINITIONS
89
 
90
 
91
class Cyg_Mempool_dlmalloc_Implementation
92
{
93
public:
94
    /* cyg_dlmalloc_size_t is the word-size used for internal bookkeeping
95
       of chunk sizes. On a 64-bit machine, you can reduce malloc
96
       overhead, especially for very small chunks, by defining
97
       cyg_dlmalloc_size_t to be a 32-bit type at the expense of not
98
       being able to handle requests greater than 2^31. This limitation is
99
       hardly ever a concern; you are encouraged to set this. However, the
100
       default version is the same as size_t. */
101
 
102
    typedef size_t Cyg_dlmalloc_size_t;
103
 
104
    struct malloc_chunk
105
    {
106
        Cyg_dlmalloc_size_t prev_size; /* Size of previous chunk (if free). */
107
        Cyg_dlmalloc_size_t size;      /* Size in bytes, including overhead. */
108
        struct malloc_chunk* fd;   /* double links -- used only if free. */
109
        struct malloc_chunk* bk;
110
    };
111
 
112
protected:
113
    /* The first value returned from sbrk */
114
    cyg_uint8 *arenabase;
115
 
116
    /* The total memory in the pool */
117
    cyg_int32 arenasize;
118
 
119
#ifdef CYGIMP_MEMALLOC_ALLOCATOR_DLMALLOC_SAFE_MULTIPLE
120
    struct Cyg_Mempool_dlmalloc_Implementation::malloc_chunk *
121
    av_[ CYGPRI_MEMALLOC_ALLOCATOR_DLMALLOC_NAV * 2 + 2 ];
122
#endif
123
 
124
#ifdef CYGDBG_MEMALLOC_ALLOCATOR_DLMALLOC_DEBUG
125
 
126
    void
127
    do_check_chunk( struct malloc_chunk * );
128
 
129
    void
130
    do_check_free_chunk( struct malloc_chunk * );
131
 
132
    void
133
    do_check_inuse_chunk( struct malloc_chunk * );
134
 
135
    void
136
    do_check_malloced_chunk( struct malloc_chunk *, Cyg_dlmalloc_size_t );
137
#endif
138
 
139
public:
140
    // Constructor: gives the base and size of the arena in which memory is
141
    // to be carved out, note that management structures are taken from the
142
    // same arena.
143
    Cyg_Mempool_dlmalloc_Implementation( cyg_uint8 *  /* base */,
144
                                         cyg_int32    /* size */,
145
                                         CYG_ADDRWORD /* argthru */ );
146
 
147
    // Destructor
148
    ~Cyg_Mempool_dlmalloc_Implementation() {}
149
 
150
    // get some memory, return NULL if none available
151
    cyg_uint8 *
152
    try_alloc( cyg_int32 /* size */ );
153
 
154
    // resize existing allocation, if oldsize is non-NULL, previous
155
    // allocation size is placed into it. If previous size not available,
156
    // it is set to 0. NB previous allocation size may have been rounded up.
157
    // Occasionally the allocation can be adjusted *backwards* as well as,
158
    // or instead of forwards, therefore the address of the resized
159
    // allocation is returned, or NULL if no resizing was possible.
160
    // Note that this differs from ::realloc() in that no attempt is
161
    // made to call malloc() if resizing is not possible - that is left
162
    // to higher layers. The data is copied from old to new though.
163
    // The effects of alloc_ptr==NULL or newsize==0 are undefined
164
    cyg_uint8 *
165
    resize_alloc( cyg_uint8 * /* alloc_ptr */, cyg_int32 /* newsize */,
166
                  cyg_int32 * /* oldsize */ );
167
 
168
    // free the memory back to the pool
169
    // returns true on success
170
    cyg_bool
171
    free( cyg_uint8 * /* ptr */, cyg_int32 /* size */ =0 );
172
 
173
    // Get memory pool status
174
    // flags is a bitmask of requested fields to fill in. The flags are
175
    // defined in common.hxx
176
    void
177
    get_status( cyg_mempool_status_flag_t /* flags */,
178
                Cyg_Mempool_Status & /* status */ );
179
 
180
};
181
 
182
#endif // ifndef CYGONCE_MEMALLOC_DLMALLOCIMPL_HXX
183
// EOF dlmallocimpl.hxx

powered by: WebSVN 2.1.0

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