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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [services/] [memalloc/] [common/] [current/] [src/] [memfixed.cxx] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      memfixed.cxx
4
//
5
//      Memory pool with fixed block class declarations
6
//
7
//==========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
9
// -------------------------------------------                              
10
// This file is part of eCos, the Embedded Configurable Operating System.   
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under    
14
// the terms of the GNU General Public License as published by the Free     
15
// Software Foundation; either version 2 or (at your option) any later      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
//==========================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):    hmt
43
// Contributors: jlarmour
44
// Date:         2000-06-16
45
// Purpose:      Define Memfixed class interface
46
// Description:  Inline class for constructing a fixed block allocator
47
// Usage:        #include <cyg/memalloc/memfixed.hxx>
48
//              
49
//
50
//####DESCRIPTIONEND####
51
//
52
//==========================================================================
53
 
54
// CONFIGURATION
55
 
56
#include <pkgconf/memalloc.h>
57
#include <pkgconf/system.h>
58
#ifdef CYGPKG_KERNEL
59
# include <pkgconf/kernel.h>
60
#endif
61
 
62
 
63
// INCLUDES
64
 
65
#include <cyg/infra/cyg_type.h>        // types
66
#include <cyg/infra/cyg_ass.h>         // assertion macros
67
#include <cyg/infra/cyg_trac.h>        // tracing macros
68
 
69
#ifdef CYGFUN_KERNEL_THREADS_TIMER
70
# include <cyg/kernel/ktypes.h>        // cyg_tick_count
71
#endif
72
 
73
#ifdef CYGSEM_MEMALLOC_ALLOCATOR_FIXED_THREADAWARE
74
// tell it to optimize for the fixed block one-to-one case
75
# define CYGIMP_MEM_T_ONEFREE_TO_ONEALLOC
76
# include <cyg/memalloc/mempolt2.hxx>  // kernel safe mempool template
77
#endif
78
 
79
#include <cyg/memalloc/memfixed.hxx>
80
#include <cyg/memalloc/mfiximpl.hxx>   // implementation of a fixed mem pool
81
#include <cyg/memalloc/common.hxx>     // Common memory allocator infra
82
 
83
// -------------------------------------------------------------------------
84
// debugging/assert function
85
 
86
#ifdef CYGDBG_USE_ASSERTS
87
cyg_bool
88
Cyg_Mempool_Fixed::check_this(cyg_assert_class_zeal zeal) const
89
{
90
    CYG_REPORT_FUNCTION();
91
    // check that we have a non-NULL pointer first
92
    if( this == NULL ) return false;
93
#ifdef CYGSEM_MEMALLOC_ALLOCATOR_FIXED_THREADAWARE
94
    return mypool.check_this( zeal );
95
#else
96
    return true;
97
#endif
98
}
99
#endif
100
 
101
// -------------------------------------------------------------------------
102
// Constructor: gives the base and size of the arena in which memory is
103
// to be carved out, note that management structures are taken from the
104
// same arena.  Alloc_unit is the blocksize allocated.
105
Cyg_Mempool_Fixed::Cyg_Mempool_Fixed(
106
    cyg_uint8 *base,
107
    cyg_int32 size,
108
    CYG_ADDRWORD alloc_unit )
109
    : mypool( base, size, alloc_unit )
110
{
111
}
112
 
113
// Destructor
114
Cyg_Mempool_Fixed::~Cyg_Mempool_Fixed()
115
{
116
}
117
 
118
// -------------------------------------------------------------------------
119
// get some memory; wait if none available
120
#ifdef CYGSEM_MEMALLOC_ALLOCATOR_FIXED_THREADAWARE
121
cyg_uint8 *
122
Cyg_Mempool_Fixed::alloc()
123
{
124
    return mypool.alloc( 0 );
125
}
126
 
127
# ifdef CYGFUN_KERNEL_THREADS_TIMER
128
// get some memory with a timeout
129
cyg_uint8 *
130
Cyg_Mempool_Fixed::alloc(cyg_tick_count delay_timeout )
131
{
132
    return mypool.alloc( 0, delay_timeout );
133
}
134
# endif
135
#endif
136
 
137
// get some memory, return NULL if none available
138
cyg_uint8 *
139
Cyg_Mempool_Fixed::try_alloc()
140
{
141
    return mypool.try_alloc( 0 );
142
}
143
 
144
// free the memory back to the pool
145
cyg_bool
146
Cyg_Mempool_Fixed::free( cyg_uint8 *p )
147
{
148
    return mypool.free( p, 0 );
149
}
150
 
151
// supposedly resize existing allocation. This is defined in the
152
// fixed block allocator purely for API consistency. It will return
153
// an error (false) for all values, except for the blocksize
154
// returns true on success
155
cyg_uint8 *
156
Cyg_Mempool_Fixed::resize_alloc( cyg_uint8 *alloc_ptr, cyg_int32 newsize,
157
                                 cyg_int32 *oldsize )
158
{
159
    return mypool.resize_alloc( alloc_ptr, newsize, oldsize );
160
}
161
 
162
// Get memory pool status
163
void
164
Cyg_Mempool_Fixed::get_status( cyg_mempool_status_flag_t flags,
165
                               Cyg_Mempool_Status &status )
166
{
167
    // set to 0 - if there's anything really waiting, it will be set to
168
    // 1 later
169
    status.waiting = 0;
170
 
171
    return mypool.get_status( flags, status );
172
}
173
 
174
// -------------------------------------------------------------------------
175
 
176
// End of memfixed.cxx

powered by: WebSVN 2.1.0

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