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()
236 struct snd_seq_pool *pool; in snd_seq_cell_free() local
240 pool = cell->pool; in snd_seq_cell_free()
241 if (snd_BUG_ON(!pool)) in snd_seq_cell_free()
244 spin_lock_irqsave(&pool->lock, flags); in snd_seq_cell_free()
245 free_cell(pool, cell); in snd_seq_cell_free()
252 curp->next = pool->free; in snd_seq_cell_free()
253 free_cell(pool, curp); in snd_seq_cell_free()
257 if (waitqueue_active(&pool->output_sleep)) { in snd_seq_cell_free()
259 if (snd_seq_output_ok(pool)) in snd_seq_cell_free()
260 wake_up(&pool->output_sleep); in snd_seq_cell_free()
262 spin_unlock_irqrestore(&pool->lock, flags); in snd_seq_cell_free()
269 static int snd_seq_cell_alloc(struct snd_seq_pool *pool, in snd_seq_cell_alloc() argument
279 if (pool == NULL) in snd_seq_cell_alloc()
285 spin_lock_irqsave(&pool->lock, flags); in snd_seq_cell_alloc()
286 if (pool->ptr == NULL) { /* not initialized */ in snd_seq_cell_alloc()
287 pr_debug("ALSA: seq: pool is not initialized\n"); in snd_seq_cell_alloc()
291 while (pool->free == NULL && ! nonblock && ! pool->closing) { in snd_seq_cell_alloc()
294 add_wait_queue(&pool->output_sleep, &wait); in snd_seq_cell_alloc()
295 spin_unlock_irqrestore(&pool->lock, flags); in snd_seq_cell_alloc()
301 spin_lock_irqsave(&pool->lock, flags); in snd_seq_cell_alloc()
302 remove_wait_queue(&pool->output_sleep, &wait); in snd_seq_cell_alloc()
309 if (pool->closing) { /* closing.. */ in snd_seq_cell_alloc()
314 cell = pool->free; in snd_seq_cell_alloc()
317 pool->free = cell->next; in snd_seq_cell_alloc()
318 atomic_inc(&pool->counter); in snd_seq_cell_alloc()
319 used = atomic_read(&pool->counter); in snd_seq_cell_alloc()
320 if (pool->max_used < used) in snd_seq_cell_alloc()
321 pool->max_used = used; in snd_seq_cell_alloc()
322 pool->event_alloc_success++; in snd_seq_cell_alloc()
327 pool->event_alloc_failures++; in snd_seq_cell_alloc()
331 spin_unlock_irqrestore(&pool->lock, flags); in snd_seq_cell_alloc()
341 int snd_seq_event_dup(struct snd_seq_pool *pool, struct snd_seq_event *event, in snd_seq_event_dup() argument
358 if (ncells >= pool->total_elements) in snd_seq_event_dup()
361 err = snd_seq_cell_alloc(pool, &cell, nonblock, file, mutexp); in snd_seq_event_dup()
392 err = snd_seq_cell_alloc(pool, &tmp, nonblock, file, in snd_seq_event_dup()
428 int snd_seq_pool_poll_wait(struct snd_seq_pool *pool, struct file *file, in snd_seq_pool_poll_wait() argument
431 poll_wait(file, &pool->output_sleep, wait); in snd_seq_pool_poll_wait()
432 return snd_seq_output_ok(pool); in snd_seq_pool_poll_wait()
437 int snd_seq_pool_init(struct snd_seq_pool *pool) in snd_seq_pool_init() argument
442 if (snd_BUG_ON(!pool)) in snd_seq_pool_init()
445 cellptr = kvmalloc_array(pool->size, in snd_seq_pool_init()
452 spin_lock_irq(&pool->lock); in snd_seq_pool_init()
453 if (pool->ptr) { in snd_seq_pool_init()
454 spin_unlock_irq(&pool->lock); in snd_seq_pool_init()
459 pool->ptr = cellptr; in snd_seq_pool_init()
460 pool->free = NULL; in snd_seq_pool_init()
462 for (cell = 0; cell < pool->size; cell++) { in snd_seq_pool_init()
463 cellptr = pool->ptr + cell; in snd_seq_pool_init()
464 cellptr->pool = pool; in snd_seq_pool_init()
465 cellptr->next = pool->free; in snd_seq_pool_init()
466 pool->free = cellptr; in snd_seq_pool_init()
468 pool->room = (pool->size + 1) / 2; in snd_seq_pool_init()
471 pool->max_used = 0; in snd_seq_pool_init()
472 pool->total_elements = pool->size; in snd_seq_pool_init()
473 spin_unlock_irq(&pool->lock); in snd_seq_pool_init()
477 /* refuse the further insertion to the pool */
478 void snd_seq_pool_mark_closing(struct snd_seq_pool *pool) in snd_seq_pool_mark_closing() argument
482 if (snd_BUG_ON(!pool)) in snd_seq_pool_mark_closing()
484 spin_lock_irqsave(&pool->lock, flags); in snd_seq_pool_mark_closing()
485 pool->closing = 1; in snd_seq_pool_mark_closing()
486 spin_unlock_irqrestore(&pool->lock, flags); in snd_seq_pool_mark_closing()
490 int snd_seq_pool_done(struct snd_seq_pool *pool) in snd_seq_pool_done() argument
494 if (snd_BUG_ON(!pool)) in snd_seq_pool_done()
498 if (waitqueue_active(&pool->output_sleep)) in snd_seq_pool_done()
499 wake_up(&pool->output_sleep); in snd_seq_pool_done()
501 while (atomic_read(&pool->counter) > 0) in snd_seq_pool_done()
505 spin_lock_irq(&pool->lock); in snd_seq_pool_done()
506 ptr = pool->ptr; in snd_seq_pool_done()
507 pool->ptr = NULL; in snd_seq_pool_done()
508 pool->free = NULL; in snd_seq_pool_done()
509 pool->total_elements = 0; in snd_seq_pool_done()
510 spin_unlock_irq(&pool->lock); in snd_seq_pool_done()
514 spin_lock_irq(&pool->lock); in snd_seq_pool_done()
515 pool->closing = 0; in snd_seq_pool_done()
516 spin_unlock_irq(&pool->lock); in snd_seq_pool_done()
522 /* init new memory pool */
525 struct snd_seq_pool *pool; in snd_seq_pool_new() local
527 /* create pool block */ in snd_seq_pool_new()
528 pool = kzalloc(sizeof(*pool), GFP_KERNEL); in snd_seq_pool_new()
529 if (!pool) in snd_seq_pool_new()
531 spin_lock_init(&pool->lock); in snd_seq_pool_new()
532 pool->ptr = NULL; in snd_seq_pool_new()
533 pool->free = NULL; in snd_seq_pool_new()
534 pool->total_elements = 0; in snd_seq_pool_new()
535 atomic_set(&pool->counter, 0); in snd_seq_pool_new()
536 pool->closing = 0; in snd_seq_pool_new()
537 init_waitqueue_head(&pool->output_sleep); in snd_seq_pool_new()
539 pool->size = poolsize; in snd_seq_pool_new()
542 pool->max_used = 0; in snd_seq_pool_new()
543 return pool; in snd_seq_pool_new()
546 /* remove memory pool */
549 struct snd_seq_pool *pool = *ppool; in snd_seq_pool_delete() local
552 if (pool == NULL) in snd_seq_pool_delete()
554 snd_seq_pool_mark_closing(pool); in snd_seq_pool_delete()
555 snd_seq_pool_done(pool); in snd_seq_pool_delete()
556 kfree(pool); in snd_seq_pool_delete()
562 struct snd_seq_pool *pool, char *space) in snd_seq_info_pool() argument
564 if (pool == NULL) in snd_seq_info_pool()
566 snd_iprintf(buffer, "%sPool size : %d\n", space, pool->total_elements); in snd_seq_info_pool()
567 snd_iprintf(buffer, "%sCells in use : %d\n", space, atomic_read(&pool->counter)); in snd_seq_info_pool()
568 snd_iprintf(buffer, "%sPeak cells in use : %d\n", space, pool->max_used); in snd_seq_info_pool()
569 snd_iprintf(buffer, "%sAlloc success : %d\n", space, pool->event_alloc_success); in snd_seq_info_pool()
570 snd_iprintf(buffer, "%sAlloc failures : %d\n", space, pool->event_alloc_failures); in snd_seq_info_pool()