Go to the source code of this file.
Data Structures | |
struct | mm_pb_manager |
struct | mm_buffer |
Defines | |
#define | SUPER(__derived) (&(__derived)->base) |
Convenience macro (type safe). | |
Functions | |
static struct mm_pb_manager * | mm_pb_manager (struct pb_manager *mgr) |
static struct mm_buffer * | mm_buffer (struct pb_buffer *buf) |
static void | mm_buffer_destroy (struct pb_buffer *buf) |
static void * | mm_buffer_map (struct pb_buffer *buf, unsigned flags) |
static void | mm_buffer_unmap (struct pb_buffer *buf) |
static void | mm_buffer_get_base_buffer (struct pb_buffer *buf, struct pb_buffer **base_buf, unsigned *offset) |
static struct pb_buffer * | mm_bufmgr_create_buffer (struct pb_manager *mgr, size_t size, const struct pb_desc *desc) |
static void | mm_bufmgr_flush (struct pb_manager *mgr) |
static void | mm_bufmgr_destroy (struct pb_manager *mgr) |
struct pb_manager * | mm_bufmgr_create_from_buffer (struct pb_buffer *buffer, size_t size, size_t align2) |
Same as mm_bufmgr_create. | |
struct pb_manager * | mm_bufmgr_create (struct pb_manager *provider, size_t size, size_t align2) |
Static sub-allocator based the old memory manager. | |
Variables | |
static struct pb_vtbl | mm_buffer_vtbl |
Definition in file pb_bufmgr_mm.c.
#define SUPER | ( | __derived | ) | (&(__derived)->base) |
static void mm_buffer_destroy | ( | struct pb_buffer * | buf | ) | [static] |
Definition at line 95 of file pb_bufmgr_mm.c.
References assert, pb_buffer::base, mm_buffer::block, FREE, mm_buffer::mgr, mm_buffer(), mmFreeMem(), mm_pb_manager::mutex, pipe_mutex_lock, pipe_mutex_unlock, and pipe_buffer::refcount.
00096 { 00097 struct mm_buffer *mm_buf = mm_buffer(buf); 00098 struct mm_pb_manager *mm = mm_buf->mgr; 00099 00100 assert(buf->base.refcount == 0); 00101 00102 pipe_mutex_lock(mm->mutex); 00103 mmFreeMem(mm_buf->block); 00104 FREE(buf); 00105 pipe_mutex_unlock(mm->mutex); 00106 }
static void mm_buffer_get_base_buffer | ( | struct pb_buffer * | buf, | |
struct pb_buffer ** | base_buf, | |||
unsigned * | offset | |||
) | [static] |
Definition at line 128 of file pb_bufmgr_mm.c.
References mm_buffer::block, mm_pb_manager::buffer, mm_buffer::mgr, mm_buffer(), mem_block::ofs, and pb_get_base_buffer().
00131 { 00132 struct mm_buffer *mm_buf = mm_buffer(buf); 00133 struct mm_pb_manager *mm = mm_buf->mgr; 00134 pb_get_base_buffer(mm->buffer, base_buf, offset); 00135 *offset += mm_buf->block->ofs; 00136 }
static void* mm_buffer_map | ( | struct pb_buffer * | buf, | |
unsigned | flags | |||
) | [static] |
Definition at line 110 of file pb_bufmgr_mm.c.
References mm_buffer::block, mm_pb_manager::map, mm_buffer::mgr, mm_buffer(), and mem_block::ofs.
00112 { 00113 struct mm_buffer *mm_buf = mm_buffer(buf); 00114 struct mm_pb_manager *mm = mm_buf->mgr; 00115 00116 return (unsigned char *) mm->map + mm_buf->block->ofs; 00117 }
static void mm_buffer_unmap | ( | struct pb_buffer * | buf | ) | [static] |
struct pb_manager* mm_bufmgr_create | ( | struct pb_manager * | provider, | |
size_t | size, | |||
size_t | align2 | |||
) | [read] |
Static sub-allocator based the old memory manager.
It managers buffers of different sizes. It does so by allocating a buffer with the size of the heap, and then using the old mm memory manager to manage that heap.
Definition at line 271 of file pb_bufmgr_mm.c.
References pb_desc::alignment, pb_manager::create_buffer, mm_bufmgr_create_from_buffer(), and pb_reference().
00273 { 00274 struct pb_buffer *buffer; 00275 struct pb_manager *mgr; 00276 struct pb_desc desc; 00277 00278 if(!provider) 00279 return NULL; 00280 00281 memset(&desc, 0, sizeof(desc)); 00282 desc.alignment = 1 << align2; 00283 00284 buffer = provider->create_buffer(provider, size, &desc); 00285 if (!buffer) 00286 return NULL; 00287 00288 mgr = mm_bufmgr_create_from_buffer(buffer, size, align2); 00289 if (!mgr) { 00290 pb_reference(&buffer, NULL); 00291 return NULL; 00292 } 00293 00294 return mgr; 00295 }
static struct pb_buffer* mm_bufmgr_create_buffer | ( | struct pb_manager * | mgr, | |
size_t | size, | |||
const struct pb_desc * | desc | |||
) | [static, read] |
Definition at line 149 of file pb_bufmgr_mm.c.
References mm_pb_manager::align2, pipe_buffer::alignment, pb_desc::alignment, assert, pb_buffer::base, mm_buffer::base, mm_buffer::block, CALLOC_STRUCT, debug_printf(), FREE, mm_pb_manager::heap, mm_buffer::mgr, mm_pb_manager(), mmAllocMem(), mmDumpMemInfo(), mm_pb_manager::mutex, mem_block::ofs, pb_check_alignment(), pipe_mutex_lock, pipe_mutex_unlock, pipe_buffer::refcount, mem_block::size, mm_pb_manager::size, pipe_buffer::size, SUPER, pb_desc::usage, pipe_buffer::usage, and pb_buffer::vtbl.
00152 { 00153 struct mm_pb_manager *mm = mm_pb_manager(mgr); 00154 struct mm_buffer *mm_buf; 00155 00156 /* We don't handle alignments larger then the one initially setup */ 00157 assert(pb_check_alignment(desc->alignment, 1 << mm->align2)); 00158 if(!pb_check_alignment(desc->alignment, 1 << mm->align2)) 00159 return NULL; 00160 00161 pipe_mutex_lock(mm->mutex); 00162 00163 mm_buf = CALLOC_STRUCT(mm_buffer); 00164 if (!mm_buf) { 00165 pipe_mutex_unlock(mm->mutex); 00166 return NULL; 00167 } 00168 00169 mm_buf->base.base.refcount = 1; 00170 mm_buf->base.base.alignment = desc->alignment; 00171 mm_buf->base.base.usage = desc->usage; 00172 mm_buf->base.base.size = size; 00173 00174 mm_buf->base.vtbl = &mm_buffer_vtbl; 00175 00176 mm_buf->mgr = mm; 00177 00178 mm_buf->block = mmAllocMem(mm->heap, size, mm->align2, 0); 00179 if(!mm_buf->block) { 00180 debug_printf("warning: heap full\n"); 00181 #if 0 00182 mmDumpMemInfo(mm->heap); 00183 #endif 00184 FREE(mm_buf); 00185 pipe_mutex_unlock(mm->mutex); 00186 return NULL; 00187 } 00188 00189 /* Some sanity checks */ 00190 assert(0 <= (unsigned)mm_buf->block->ofs && (unsigned)mm_buf->block->ofs < mm->size); 00191 assert(size <= (unsigned)mm_buf->block->size && (unsigned)mm_buf->block->ofs + (unsigned)mm_buf->block->size <= mm->size); 00192 00193 pipe_mutex_unlock(mm->mutex); 00194 return SUPER(mm_buf); 00195 }
struct pb_manager* mm_bufmgr_create_from_buffer | ( | struct pb_buffer * | buffer, | |
size_t | size, | |||
size_t | align2 | |||
) | [read] |
Same as mm_bufmgr_create.
Buffer will be release when the manager is destroyed.
Definition at line 224 of file pb_bufmgr_mm.c.
References mm_pb_manager::align2, mm_pb_manager::base, mm_pb_manager::buffer, CALLOC_STRUCT, pb_manager::create_buffer, pb_manager::destroy, pb_manager::flush, FREE, mm_pb_manager::heap, mm_pb_manager::map, mm_bufmgr_create_buffer(), mm_bufmgr_destroy(), mm_bufmgr_flush(), mmDestroy(), mmInit(), mm_pb_manager::mutex, pb_map(), pb_unmap(), PIPE_BUFFER_USAGE_CPU_READ, PIPE_BUFFER_USAGE_CPU_WRITE, pipe_mutex_init, mm_pb_manager::size, and SUPER.
00226 { 00227 struct mm_pb_manager *mm; 00228 00229 if(!buffer) 00230 return NULL; 00231 00232 mm = CALLOC_STRUCT(mm_pb_manager); 00233 if (!mm) 00234 return NULL; 00235 00236 mm->base.destroy = mm_bufmgr_destroy; 00237 mm->base.create_buffer = mm_bufmgr_create_buffer; 00238 mm->base.flush = mm_bufmgr_flush; 00239 00240 mm->size = size; 00241 mm->align2 = align2; /* 64-byte alignment */ 00242 00243 pipe_mutex_init(mm->mutex); 00244 00245 mm->buffer = buffer; 00246 00247 mm->map = pb_map(mm->buffer, 00248 PIPE_BUFFER_USAGE_CPU_READ | 00249 PIPE_BUFFER_USAGE_CPU_WRITE); 00250 if(!mm->map) 00251 goto failure; 00252 00253 mm->heap = mmInit(0, size); 00254 if (!mm->heap) 00255 goto failure; 00256 00257 return SUPER(mm); 00258 00259 failure: 00260 if(mm->heap) 00261 mmDestroy(mm->heap); 00262 if(mm->map) 00263 pb_unmap(mm->buffer); 00264 if(mm) 00265 FREE(mm); 00266 return NULL; 00267 }
static void mm_bufmgr_destroy | ( | struct pb_manager * | mgr | ) | [static] |
Definition at line 206 of file pb_bufmgr_mm.c.
References mm_pb_manager::buffer, FREE, mm_pb_manager::heap, mm_pb_manager(), mmDestroy(), mm_pb_manager::mutex, pb_reference(), pb_unmap(), pipe_mutex_lock, and pipe_mutex_unlock.
00207 { 00208 struct mm_pb_manager *mm = mm_pb_manager(mgr); 00209 00210 pipe_mutex_lock(mm->mutex); 00211 00212 mmDestroy(mm->heap); 00213 00214 pb_unmap(mm->buffer); 00215 pb_reference(&mm->buffer, NULL); 00216 00217 pipe_mutex_unlock(mm->mutex); 00218 00219 FREE(mgr); 00220 }
static void mm_bufmgr_flush | ( | struct pb_manager * | mgr | ) | [static] |
static struct mm_pb_manager* mm_pb_manager | ( | struct pb_manager * | mgr | ) | [static, read] |
Definition at line 69 of file pb_bufmgr_mm.c.
References assert.
00070 { 00071 assert(mgr); 00072 return (struct mm_pb_manager *)mgr; 00073 }
struct pb_vtbl mm_buffer_vtbl [static] |
Initial value:
Definition at line 140 of file pb_bufmgr_mm.c.