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

Subversion Repositories openrisc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
#ifndef CYGONCE_MEMALLOC_DLMALLOC_HXX
2
#define CYGONCE_MEMALLOC_DLMALLOC_HXX
3
 
4
//==========================================================================
5
//
6
//      dlmalloc.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
#ifdef CYGIMP_MEMALLOC_ALLOCATOR_DLMALLOC_THREADAWARE
64
# include 
65
# ifdef CYGPKG_KERNEL
66
#  include 
67
# endif
68
#endif
69
 
70
// when used as an implementation for malloc, we need the following
71
// to let the system know the name of the class
72
#define CYGCLS_MEMALLOC_MALLOC_IMPL Cyg_Mempool_dlmalloc
73
 
74
// if the implementation is all that's required, don't output anything else
75
#ifndef __MALLOC_IMPL_WANTED
76
 
77
// INCLUDES
78
 
79
#include                       // size_t, ptrdiff_t
80
#include           // types
81
#ifdef CYGIMP_MEMALLOC_ALLOCATOR_DLMALLOC_THREADAWARE
82
# include     // kernel safe mempool template
83
#endif
84
#include  // dlmalloc implementation
85
#include        // Common memory allocator infra
86
#ifdef CYGFUN_KERNEL_THREADS_TIMER
87
# include           // cyg_tick_count
88
#endif
89
 
90
 
91
// TYPE DEFINITIONS
92
 
93
 
94
class Cyg_Mempool_dlmalloc
95
{
96
protected:
97
#ifdef CYGIMP_MEMALLOC_ALLOCATOR_DLMALLOC_THREADAWARE
98
    Cyg_Mempolt2 mypool;
99
#else
100
    Cyg_Mempool_dlmalloc_Implementation mypool;
101
#endif
102
 
103
 
104
public:
105
    // Constructor: gives the base and size of the arena in which memory is
106
    // to be carved out, note that management structures are taken from the
107
    // same arena.
108
    Cyg_Mempool_dlmalloc( cyg_uint8 *base, cyg_int32 size,
109
                          CYG_ADDRWORD argthru=0 )
110
        : mypool( base, size, argthru ) {}
111
 
112
    // Destructor
113
    ~Cyg_Mempool_dlmalloc() {}
114
 
115
    // get some memory; wait if none available
116
    // if we aren't configured to be thread-aware this is irrelevant
117
#ifdef CYGIMP_MEMALLOC_ALLOCATOR_DLMALLOC_THREADAWARE
118
    cyg_uint8 *
119
    alloc( cyg_int32 size ) { return mypool.alloc( size ); }
120
 
121
# ifdef CYGFUN_KERNEL_THREADS_TIMER
122
    // get some memory with a timeout
123
    cyg_uint8 *
124
    alloc( cyg_int32 size, cyg_tick_count delay_timeout ) {
125
        return mypool.alloc( size, delay_timeout );
126
    }
127
# endif
128
#endif
129
 
130
    // get some memory, return NULL if none available
131
    cyg_uint8 *
132
    try_alloc( cyg_int32 size ) { return mypool.try_alloc( size ); }
133
 
134
 
135
    // resize existing allocation, if oldsize is non-NULL, previous
136
    // allocation size is placed into it. If previous size not available,
137
    // it is set to 0. NB previous allocation size may have been rounded up.
138
    // Occasionally the allocation can be adjusted *backwards* as well as,
139
    // or instead of forwards, therefore the address of the resized
140
    // allocation is returned, or NULL if no resizing was possible.
141
    // Note that this differs from ::realloc() in that no attempt is
142
    // made to call malloc() if resizing is not possible - that is left
143
    // to higher layers. The data is copied from old to new though.
144
    // The effects of alloc_ptr==NULL or newsize==0 are undefined
145
    cyg_uint8 *
146
    resize_alloc( cyg_uint8 *alloc_ptr, cyg_int32 newsize,
147
                  cyg_int32 *oldsize ) {
148
        return mypool.resize_alloc( alloc_ptr, newsize, oldsize);
149
    }
150
 
151
    // free the memory back to the pool
152
    // returns true on success
153
    cyg_bool
154
    free( cyg_uint8 *ptr, cyg_int32 size=0 ) { return mypool.free(ptr, size); }
155
 
156
    // Get memory pool status
157
    // flags is a bitmask of requested fields to fill in. The flags are
158
    // defined in common.hxx
159
    void
160
    get_status( cyg_mempool_status_flag_t flags, Cyg_Mempool_Status &status ) {
161
        // set to 0 - if there's anything really waiting, it will be set to
162
        // 1 later
163
        status.waiting = 0;
164
        mypool.get_status( flags, status );
165
    }
166
};
167
 
168
#endif // ifndef __MALLOC_IMPL_WANTED
169
 
170
#endif // ifndef CYGONCE_MEMALLOC_DLMALLOC_HXX
171
// EOF dlmalloc.hxx

powered by: WebSVN 2.1.0

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