Lines Matching full:pool

22 static inline int snd_seq_pool_available(struct snd_seq_pool *pool)  in snd_seq_pool_available()  argument
24 return pool->total_elements - atomic_read(&pool->counter); in snd_seq_pool_available()
27 static inline int snd_seq_output_ok(struct snd_seq_pool *pool) in snd_seq_output_ok() argument
29 return snd_seq_pool_available(pool) >= pool->room; in snd_seq_output_ok()
225 static inline void free_cell(struct snd_seq_pool *pool, in free_cell() argument
228 cell->next = pool->free; in free_cell()
229 pool->free = cell; in free_cell()
230 atomic_dec(&pool->counter); in free_cell()
235 struct snd_seq_pool *pool; in snd_seq_cell_free() local
239 pool = cell->pool; in snd_seq_cell_free()
240 if (snd_BUG_ON(!pool)) in snd_seq_cell_free()
243 guard(spinlock_irqsave)(&pool->lock); in snd_seq_cell_free()
244 free_cell(pool, cell); in snd_seq_cell_free()
251 curp->next = pool->free; in snd_seq_cell_free()
252 free_cell(pool, curp); in snd_seq_cell_free()
256 if (waitqueue_active(&pool->output_sleep)) { in snd_seq_cell_free()
258 if (snd_seq_output_ok(pool)) in snd_seq_cell_free()
259 wake_up(&pool->output_sleep); in snd_seq_cell_free()
267 static int snd_seq_cell_alloc(struct snd_seq_pool *pool, in snd_seq_cell_alloc() argument
277 if (pool == NULL) in snd_seq_cell_alloc()
283 spin_lock_irqsave(&pool->lock, flags); in snd_seq_cell_alloc()
284 if (pool->ptr == NULL) { /* not initialized */ in snd_seq_cell_alloc()
285 pr_debug("ALSA: seq: pool is not initialized\n"); in snd_seq_cell_alloc()
289 while (pool->free == NULL && ! nonblock && ! pool->closing) { in snd_seq_cell_alloc()
292 add_wait_queue(&pool->output_sleep, &wait); in snd_seq_cell_alloc()
293 spin_unlock_irqrestore(&pool->lock, flags); in snd_seq_cell_alloc()
299 spin_lock_irqsave(&pool->lock, flags); in snd_seq_cell_alloc()
300 remove_wait_queue(&pool->output_sleep, &wait); in snd_seq_cell_alloc()
307 if (pool->closing) { /* closing.. */ in snd_seq_cell_alloc()
312 cell = pool->free; in snd_seq_cell_alloc()
315 pool->free = cell->next; in snd_seq_cell_alloc()
316 atomic_inc(&pool->counter); in snd_seq_cell_alloc()
317 used = atomic_read(&pool->counter); in snd_seq_cell_alloc()
318 if (pool->max_used < used) in snd_seq_cell_alloc()
319 pool->max_used = used; in snd_seq_cell_alloc()
320 pool->event_alloc_success++; in snd_seq_cell_alloc()
325 pool->event_alloc_failures++; in snd_seq_cell_alloc()
329 spin_unlock_irqrestore(&pool->lock, flags); in snd_seq_cell_alloc()
339 int snd_seq_event_dup(struct snd_seq_pool *pool, struct snd_seq_event *event, in snd_seq_event_dup() argument
356 if (ncells >= pool->total_elements) in snd_seq_event_dup()
359 err = snd_seq_cell_alloc(pool, &cell, nonblock, file, mutexp); in snd_seq_event_dup()
390 err = snd_seq_cell_alloc(pool, &tmp, nonblock, file, in snd_seq_event_dup()
426 int snd_seq_pool_poll_wait(struct snd_seq_pool *pool, struct file *file, in snd_seq_pool_poll_wait() argument
429 poll_wait(file, &pool->output_sleep, wait); in snd_seq_pool_poll_wait()
430 guard(spinlock_irq)(&pool->lock); in snd_seq_pool_poll_wait()
431 return snd_seq_output_ok(pool); in snd_seq_pool_poll_wait()
436 int snd_seq_pool_init(struct snd_seq_pool *pool) in snd_seq_pool_init() argument
441 if (snd_BUG_ON(!pool)) in snd_seq_pool_init()
444 cellptr = kvmalloc_array(pool->size, in snd_seq_pool_init()
451 guard(spinlock_irq)(&pool->lock); in snd_seq_pool_init()
452 if (pool->ptr) { in snd_seq_pool_init()
457 pool->ptr = cellptr; in snd_seq_pool_init()
458 pool->free = NULL; in snd_seq_pool_init()
460 for (cell = 0; cell < pool->size; cell++) { in snd_seq_pool_init()
461 cellptr = pool->ptr + cell; in snd_seq_pool_init()
462 cellptr->pool = pool; in snd_seq_pool_init()
463 cellptr->next = pool->free; in snd_seq_pool_init()
464 pool->free = cellptr; in snd_seq_pool_init()
466 pool->room = (pool->size + 1) / 2; in snd_seq_pool_init()
469 pool->max_used = 0; in snd_seq_pool_init()
470 pool->total_elements = pool->size; in snd_seq_pool_init()
474 /* refuse the further insertion to the pool */
475 void snd_seq_pool_mark_closing(struct snd_seq_pool *pool) in snd_seq_pool_mark_closing() argument
477 if (snd_BUG_ON(!pool)) in snd_seq_pool_mark_closing()
479 guard(spinlock_irqsave)(&pool->lock); in snd_seq_pool_mark_closing()
480 pool->closing = 1; in snd_seq_pool_mark_closing()
484 int snd_seq_pool_done(struct snd_seq_pool *pool) in snd_seq_pool_done() argument
488 if (snd_BUG_ON(!pool)) in snd_seq_pool_done()
492 if (waitqueue_active(&pool->output_sleep)) in snd_seq_pool_done()
493 wake_up(&pool->output_sleep); in snd_seq_pool_done()
495 while (atomic_read(&pool->counter) > 0) in snd_seq_pool_done()
499 scoped_guard(spinlock_irq, &pool->lock) { in snd_seq_pool_done()
500 ptr = pool->ptr; in snd_seq_pool_done()
501 pool->ptr = NULL; in snd_seq_pool_done()
502 pool->free = NULL; in snd_seq_pool_done()
503 pool->total_elements = 0; in snd_seq_pool_done()
508 guard(spinlock_irq)(&pool->lock); in snd_seq_pool_done()
509 pool->closing = 0; in snd_seq_pool_done()
515 /* init new memory pool */
518 struct snd_seq_pool *pool; in snd_seq_pool_new() local
520 /* create pool block */ in snd_seq_pool_new()
521 pool = kzalloc(sizeof(*pool), GFP_KERNEL); in snd_seq_pool_new()
522 if (!pool) in snd_seq_pool_new()
524 spin_lock_init(&pool->lock); in snd_seq_pool_new()
525 pool->ptr = NULL; in snd_seq_pool_new()
526 pool->free = NULL; in snd_seq_pool_new()
527 pool->total_elements = 0; in snd_seq_pool_new()
528 atomic_set(&pool->counter, 0); in snd_seq_pool_new()
529 pool->closing = 0; in snd_seq_pool_new()
530 init_waitqueue_head(&pool->output_sleep); in snd_seq_pool_new()
532 pool->size = poolsize; in snd_seq_pool_new()
535 pool->max_used = 0; in snd_seq_pool_new()
536 return pool; in snd_seq_pool_new()
539 /* remove memory pool */
542 struct snd_seq_pool *pool = *ppool; in snd_seq_pool_delete() local
545 if (pool == NULL) in snd_seq_pool_delete()
547 snd_seq_pool_mark_closing(pool); in snd_seq_pool_delete()
548 snd_seq_pool_done(pool); in snd_seq_pool_delete()
549 kfree(pool); in snd_seq_pool_delete()
555 struct snd_seq_pool *pool, char *space) in snd_seq_info_pool() argument
557 if (pool == NULL) in snd_seq_info_pool()
559 snd_iprintf(buffer, "%sPool size : %d\n", space, pool->total_elements); in snd_seq_info_pool()
560 snd_iprintf(buffer, "%sCells in use : %d\n", space, atomic_read(&pool->counter)); in snd_seq_info_pool()
561 snd_iprintf(buffer, "%sPeak cells in use : %d\n", space, pool->max_used); in snd_seq_info_pool()
562 snd_iprintf(buffer, "%sAlloc success : %d\n", space, pool->event_alloc_success); in snd_seq_info_pool()
563 snd_iprintf(buffer, "%sAlloc failures : %d\n", space, pool->event_alloc_failures); in snd_seq_info_pool()