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

Subversion Repositories openrisc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      sepmeta.cxx
4
//
5
//      Variable block memory pool with separated metadata 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):    jlarmour
43
// Contributors: 
44
// Date:         2001-06-28
45
// Description: 
46
// Usage:        #include <cyg/memalloc/sepmeta.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_SEPMETA_THREADAWARE
73
# include <cyg/memalloc/mempolt2.hxx>   // kernel safe mempool template
74
#endif
75
 
76
#include <cyg/memalloc/sepmeta.hxx>
77
#include <cyg/memalloc/sepmetaimpl.hxx>// implementation of this 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_Sepmeta::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_SEPMETA_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_Sepmeta::Cyg_Mempool_Sepmeta(
104
    cyg_uint8 *base,
105
    cyg_int32 size,
106
    cyg_int32 alignment,
107
    cyg_uint8 *metabase,
108
    cyg_uint32 metasize)
109
    : args(alignment, metabase, metasize),
110
    mypool( base, size, (CYG_ADDRWORD)&args )
111
{
112
}
113
 
114
// Destructor
115
Cyg_Mempool_Sepmeta::~Cyg_Mempool_Sepmeta()
116
{
117
}
118
 
119
// -------------------------------------------------------------------------
120
// get some memory; wait if none available
121
#ifdef CYGSEM_MEMALLOC_ALLOCATOR_SEPMETA_THREADAWARE
122
cyg_uint8 *
123
Cyg_Mempool_Sepmeta::alloc(cyg_int32 size)
124
{
125
    return mypool.alloc( size );
126
}
127
 
128
# ifdef CYGFUN_KERNEL_THREADS_TIMER
129
// get some memory with a timeout
130
cyg_uint8 *
131
Cyg_Mempool_Sepmeta::alloc(cyg_int32 size, cyg_tick_count delay_timeout)
132
{
133
    return mypool.alloc( size , delay_timeout );
134
}
135
# endif
136
#endif
137
 
138
// get some memory, return NULL if none available
139
cyg_uint8 *
140
Cyg_Mempool_Sepmeta::try_alloc(cyg_int32 size)
141
{
142
    return mypool.try_alloc( size );
143
}
144
 
145
// resize existing allocation, if oldsize is non-NULL, previous
146
// allocation size is placed into it. If previous size not available,
147
// it is set to 0. NB previous allocation size may have been rounded up.
148
// Occasionally the allocation can be adjusted *backwards* as well as,
149
// or instead of forwards, therefore the address of the resized
150
// allocation is returned, or NULL if no resizing was possible.
151
// Note that this differs from ::realloc() in that no attempt is
152
// made to call malloc() if resizing is not possible - that is left
153
// to higher layers. The data is copied from old to new though.
154
// The effects of alloc_ptr==NULL or newsize==0 are undefined
155
cyg_uint8 *
156
Cyg_Mempool_Sepmeta::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
// free the memory back to the pool
163
cyg_bool
164
Cyg_Mempool_Sepmeta::free( cyg_uint8 *p, cyg_int32 size )
165
{
166
    return mypool.free( p, size );
167
}
168
 
169
// Get memory pool status
170
void
171
Cyg_Mempool_Sepmeta::get_status( cyg_mempool_status_flag_t flags,
172
                                  Cyg_Mempool_Status &status )
173
{
174
    // set to 0 - if there's anything really waiting, it will be set to
175
    // 1 later
176
    status.waiting = 0;
177
 
178
    return mypool.get_status( flags, status );
179
}
180
 
181
// -------------------------------------------------------------------------
182
 
183
// End of sepmeta.cxx

powered by: WebSVN 2.1.0

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