Lines Matching refs:buf

127 static size_t calc_buffer_size(struct smm_buffer * buf);
128 static void purge_history(struct smm_buffer * buf);
130 static void return_to_pool(struct smm_buffer * buf);
134 static void free_buffer(struct smm_buffer * buf);
197 struct smm_buffer * buf; in smm_resize() local
205 LL_DEQUEUE(buf, &rgrp->unused, use); in smm_resize()
206 return_to_pool(buf); in smm_resize()
210 LL_FOREACH(buf, &rgrp->inuse, use) { in smm_resize()
211 buf->group_resized = true; in smm_resize()
212 purge_history(buf); in smm_resize()
219 struct smm_buffer * buf; in smm_destroy() local
224 LL_DEQUEUE(buf, &dgrp->unused, use); in smm_destroy()
225 return_to_pool(buf); in smm_destroy()
232 LL_DEQUEUE(buf, &dgrp->inuse, use); in smm_destroy()
233 return_to_pool(buf); in smm_destroy()
244 struct smm_buffer * buf; in smm_acquire() local
249 buf = get_from_pool(agrp); in smm_acquire()
253 LL_DEQUEUE(buf, &agrp->unused, use); in smm_acquire()
256 if(buf != NULL) { in smm_acquire()
258 LL_ENQUEUE(&agrp->inuse, buf, use); in smm_acquire()
262 if(smm_instance.cbs.init_buffer(smm_instance.cbs.ctx, &buf->props)) { in smm_acquire()
263 smm_release(buf); in smm_acquire()
264 buf = NULL; in smm_acquire()
268 if(buf != NULL) { in smm_acquire()
270 purge_history(buf); in smm_acquire()
273 LL_ENQUEUE(&agrp->history, buf, age); in smm_acquire()
277 return buf; in smm_acquire()
281 void * smm_map(smm_buffer_t * buf) in smm_map() argument
283 struct smm_buffer * mbuf = buf; in smm_map()
320 void smm_release(smm_buffer_t * buf) in smm_release() argument
322 struct smm_buffer * rbuf = buf; in smm_release()
357 smm_buffer_t * smm_next(smm_buffer_t * buf) in smm_next() argument
360 struct smm_buffer * nbuf = buf; in smm_next()
373 void purge_history(struct smm_buffer * buf) in purge_history() argument
376 struct smm_group * grp = buf->props.group; in purge_history()
380 if(ibuf == buf) { in purge_history()
383 } while(ibuf != buf); in purge_history()
390 size_t calc_buffer_size(struct smm_buffer * buf) in calc_buffer_size() argument
393 struct smm_pool * buf_pool = buf->props.pool; in calc_buffer_size()
395 if(buf == LL_LAST(&buf_pool->allocd)) { in calc_buffer_size()
396 buf_sz = (buf_pool->props.size - buf->props.offset); in calc_buffer_size()
399 buf_sz = (LL_NEXT(buf, pool)->props.offset - buf->props.offset); in calc_buffer_size()
410 struct smm_buffer * buf; in get_from_pool() local
422 buf = NULL; in get_from_pool()
426 LL_FOREACH(buf, &smm_instance.active->allocd, pool) { in get_from_pool()
427 last = buf; in get_from_pool()
428 if(buf->props.group == NULL) { in get_from_pool()
429 buf_sz = calc_buffer_size(buf); in get_from_pool()
434 if((buf != LL_LAST(&smm_instance.active->allocd)) && in get_from_pool()
435 (LL_NEXT(buf, pool)->props.group == NULL)) { in get_from_pool()
437 LL_NEXT(buf, pool)->props.offset -= (buf_sz - grp->size); in get_from_pool()
441 alloc_buffer(buf, buf->props.offset + grp->size); in get_from_pool()
449 if(buf == NULL) { in get_from_pool()
460 buf = alloc_buffer(NULL, 0); in get_from_pool()
463 buf = alloc_buffer(last, smm_instance.active->props.size); in get_from_pool()
465 last = buf; in get_from_pool()
473 if(buf != NULL) { in get_from_pool()
474 free_buffer(buf); in get_from_pool()
475 buf = NULL; in get_from_pool()
481 buf = last; in get_from_pool()
488 free_buffer(buf); in get_from_pool()
491 buf = NULL; in get_from_pool()
506 if(buf != NULL) { in get_from_pool()
508 memcpy((void *)&buf->props.group, &grp, sizeof(struct smm_group *)); in get_from_pool()
512 if(smm_instance.cbs.new_buffer(smm_instance.cbs.ctx, &buf->props)) { in get_from_pool()
514 memcpy((void *)&buf->props.group, &grp, sizeof(struct smm_group *)); in get_from_pool()
515 buf = NULL; in get_from_pool()
519 if(buf != NULL) { in get_from_pool()
526 return buf; in get_from_pool()
530 void return_to_pool(struct smm_buffer * buf) in return_to_pool() argument
532 struct smm_group * grp = buf->props.group; in return_to_pool()
533 struct smm_pool * pool = buf->props.pool; in return_to_pool()
537 smm_instance.cbs.free_buffer(smm_instance.cbs.ctx, &buf->props); in return_to_pool()
541 purge_history(buf); in return_to_pool()
546 memcpy((void *)&buf->props.group, &grp, sizeof(struct smm_group *)); in return_to_pool()
550 smm_instance.statistics.active_used -= calc_buffer_size(buf); in return_to_pool()
554 if((buf != LL_LAST(&pool->allocd)) && in return_to_pool()
555 (LL_NEXT(buf, pool)->props.group == NULL)) { in return_to_pool()
556 free_buffer(LL_NEXT(buf, pool)); in return_to_pool()
558 if((buf != LL_FIRST(&pool->allocd)) && in return_to_pool()
559 (LL_PREV(buf, pool)->props.group == NULL)) { in return_to_pool()
560 buf = LL_PREV(buf, pool); in return_to_pool()
561 pool = buf->props.pool; in return_to_pool()
562 free_buffer(LL_NEXT(buf, pool)); in return_to_pool()
566 if((buf == LL_FIRST(&pool->allocd)) && in return_to_pool()
567 (buf == LL_LAST(&pool->allocd))) { in return_to_pool()
568 free_buffer(buf); in return_to_pool()
639 struct smm_buffer * buf; in alloc_buffer() local
648 buf = malloc(sizeof(struct smm_buffer)); in alloc_buffer()
649 if(buf != NULL) { in alloc_buffer()
650 memcpy(&buf->props, &initial_props, sizeof(struct smm_buffer_properties)); in alloc_buffer()
651 buf->group_resized = false; in alloc_buffer()
654 LL_ENQUEUE(&smm_instance.active->allocd, buf, pool); in alloc_buffer()
657 LL_INSERT_AFTER(&smm_instance.active->allocd, last, buf, pool); in alloc_buffer()
661 return buf; in alloc_buffer()
665 void free_buffer(struct smm_buffer * buf) in free_buffer() argument
667 struct smm_pool * buf_pool = buf->props.pool; in free_buffer()
670 LL_REMOVE(&buf_pool->allocd, buf, pool); in free_buffer()
671 free(buf); in free_buffer()