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

Subversion Repositories openrisc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      memvar.cxx
4
//
5
//      Memory pool with variable 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):    dsm, jlarmour
43
// Contributors: 
44
// Date:         2000-06-12
45
// Description: 
46
// Usage:        #include <cyg/memalloc/memvar.hxx>
47
//              
48
//
49
//####DESCRIPTIONEND####
50
//
51
//==========================================================================
52
 
53
// CONFIGURATION
54
 
55
#include <pkgconf/memalloc.h>
56
#include <pkgconf/system.h>
57
#ifdef CYGPKG_KERNEL
58
# include <pkgconf/kernel.h>
59
#endif
60
 
61
 
62
// INCLUDES
63
 
64
#include <cyg/infra/cyg_type.h>        // types
65
#include <cyg/infra/cyg_ass.h>         // assertion macros
66
#include <cyg/infra/cyg_trac.h>        // tracing macros
67
 
68
#ifdef CYGFUN_KERNEL_THREADS_TIMER
69
# include <cyg/kernel/ktypes.h>        // cyg_tick_count
70
#endif
71
 
72
#ifdef CYGSEM_MEMALLOC_ALLOCATOR_VARIABLE_THREADAWARE
73
# include <cyg/memalloc/mempolt2.hxx>   // kernel safe mempool template
74
#endif
75
 
76
#include <cyg/memalloc/memvar.hxx>
77
#include <cyg/memalloc/mvarimpl.hxx>   // implementation of a variable mem pool
78
#include <cyg/memalloc/common.hxx>     // Common memory allocator infra
79
 
80
// FUNCTIONS
81
 
82
// -------------------------------------------------------------------------
83
// debugging/assert function
84
 
85
#ifdef CYGDBG_USE_ASSERTS
86
cyg_bool
87
Cyg_Mempool_Variable::check_this(cyg_assert_class_zeal zeal) const
88
{
89
    CYG_REPORT_FUNCTION();
90
    // check that we have a non-NULL pointer first
91
    if( this == NULL ) return false;
92
#ifdef CYGSEM_MEMALLOC_ALLOCATOR_VARIABLE_THREADAWARE
93
    return mypool.check_this( zeal );
94
#else
95
    return true;
96
#endif
97
}
98
#endif
99
 
100
// -------------------------------------------------------------------------
101
// Constructor: gives the base and size of the arena in which memory is
102
// to be carved out
103
Cyg_Mempool_Variable::Cyg_Mempool_Variable(
104
    cyg_uint8 *base,
105
    cyg_int32 size,
106
    cyg_int32 alignment)
107
    : mypool( base, size, (CYG_ADDRWORD)alignment )
108
{
109
}
110
 
111
// Destructor
112
Cyg_Mempool_Variable::~Cyg_Mempool_Variable()
113
{
114
}
115
 
116
// -------------------------------------------------------------------------
117
// get some memory; wait if none available
118
#ifdef CYGSEM_MEMALLOC_ALLOCATOR_VARIABLE_THREADAWARE
119
cyg_uint8 *
120
Cyg_Mempool_Variable::alloc(cyg_int32 size)
121
{
122
    return mypool.alloc( size );
123
}
124
 
125
# ifdef CYGFUN_KERNEL_THREADS_TIMER
126
// get some memory with a timeout
127
cyg_uint8 *
128
Cyg_Mempool_Variable::alloc(cyg_int32 size, cyg_tick_count delay_timeout)
129
{
130
    return mypool.alloc( size , delay_timeout );
131
}
132
# endif
133
#endif
134
 
135
// get some memory, return NULL if none available
136
cyg_uint8 *
137
Cyg_Mempool_Variable::try_alloc(cyg_int32 size)
138
{
139
    return mypool.try_alloc( size );
140
}
141
 
142
// resize existing allocation, if oldsize is non-NULL, previous
143
// allocation size is placed into it. If previous size not available,
144
// it is set to 0. NB previous allocation size may have been rounded up.
145
// Occasionally the allocation can be adjusted *backwards* as well as,
146
// or instead of forwards, therefore the address of the resized
147
// allocation is returned, or NULL if no resizing was possible.
148
// Note that this differs from ::realloc() in that no attempt is
149
// made to call malloc() if resizing is not possible - that is left
150
// to higher layers. The data is copied from old to new though.
151
// The effects of alloc_ptr==NULL or newsize==0 are undefined
152
cyg_uint8 *
153
Cyg_Mempool_Variable::resize_alloc( cyg_uint8 *alloc_ptr, cyg_int32 newsize,
154
                                    cyg_int32 *oldsize )
155
{
156
    return mypool.resize_alloc( alloc_ptr, newsize, oldsize );
157
}
158
 
159
// free the memory back to the pool
160
cyg_bool
161
Cyg_Mempool_Variable::free( cyg_uint8 *p, cyg_int32 size )
162
{
163
    return mypool.free( p, size );
164
}
165
 
166
// Get memory pool status
167
void
168
Cyg_Mempool_Variable::get_status( cyg_mempool_status_flag_t flags,
169
                                  Cyg_Mempool_Status &status )
170
{
171
    // set to 0 - if there's anything really waiting, it will be set to
172
    // 1 later
173
    status.waiting = 0;
174
 
175
    return mypool.get_status( flags, status );
176
}
177
 
178
// -------------------------------------------------------------------------
179
 
180
// End of memvar.cxx

powered by: WebSVN 2.1.0

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