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()
163 static inline void free_cell(struct snd_seq_pool *pool, in free_cell() argument
166 cell->next = pool->free; in free_cell()
167 pool->free = cell; in free_cell()
168 atomic_dec(&pool->counter); in free_cell()
174 struct snd_seq_pool *pool; in snd_seq_cell_free() local
178 pool = cell->pool; in snd_seq_cell_free()
179 if (snd_BUG_ON(!pool)) in snd_seq_cell_free()
182 spin_lock_irqsave(&pool->lock, flags); in snd_seq_cell_free()
183 free_cell(pool, cell); in snd_seq_cell_free()
190 curp->next = pool->free; in snd_seq_cell_free()
191 free_cell(pool, curp); in snd_seq_cell_free()
195 if (waitqueue_active(&pool->output_sleep)) { in snd_seq_cell_free()
197 if (snd_seq_output_ok(pool)) in snd_seq_cell_free()
198 wake_up(&pool->output_sleep); in snd_seq_cell_free()
200 spin_unlock_irqrestore(&pool->lock, flags); in snd_seq_cell_free()
207 static int snd_seq_cell_alloc(struct snd_seq_pool *pool, in snd_seq_cell_alloc() argument
217 if (pool == NULL) in snd_seq_cell_alloc()
223 spin_lock_irqsave(&pool->lock, flags); in snd_seq_cell_alloc()
224 if (pool->ptr == NULL) { /* not initialized */ in snd_seq_cell_alloc()
225 pr_debug("ALSA: seq: pool is not initialized\n"); in snd_seq_cell_alloc()
229 while (pool->free == NULL && ! nonblock && ! pool->closing) { in snd_seq_cell_alloc()
232 add_wait_queue(&pool->output_sleep, &wait); in snd_seq_cell_alloc()
233 spin_unlock_irqrestore(&pool->lock, flags); in snd_seq_cell_alloc()
239 spin_lock_irqsave(&pool->lock, flags); in snd_seq_cell_alloc()
240 remove_wait_queue(&pool->output_sleep, &wait); in snd_seq_cell_alloc()
247 if (pool->closing) { /* closing.. */ in snd_seq_cell_alloc()
252 cell = pool->free; in snd_seq_cell_alloc()
255 pool->free = cell->next; in snd_seq_cell_alloc()
256 atomic_inc(&pool->counter); in snd_seq_cell_alloc()
257 used = atomic_read(&pool->counter); in snd_seq_cell_alloc()
258 if (pool->max_used < used) in snd_seq_cell_alloc()
259 pool->max_used = used; in snd_seq_cell_alloc()
260 pool->event_alloc_success++; in snd_seq_cell_alloc()
265 pool->event_alloc_failures++; in snd_seq_cell_alloc()
269 spin_unlock_irqrestore(&pool->lock, flags); in snd_seq_cell_alloc()
279 int snd_seq_event_dup(struct snd_seq_pool *pool, struct snd_seq_event *event, in snd_seq_event_dup() argument
295 if (ncells >= pool->total_elements) in snd_seq_event_dup()
298 err = snd_seq_cell_alloc(pool, &cell, nonblock, file, mutexp); in snd_seq_event_dup()
324 err = snd_seq_cell_alloc(pool, &tmp, nonblock, file, in snd_seq_event_dup()
360 int snd_seq_pool_poll_wait(struct snd_seq_pool *pool, struct file *file, in snd_seq_pool_poll_wait() argument
363 poll_wait(file, &pool->output_sleep, wait); in snd_seq_pool_poll_wait()
364 return snd_seq_output_ok(pool); in snd_seq_pool_poll_wait()
369 int snd_seq_pool_init(struct snd_seq_pool *pool) in snd_seq_pool_init() argument
374 if (snd_BUG_ON(!pool)) in snd_seq_pool_init()
377 cellptr = kvmalloc_array(sizeof(struct snd_seq_event_cell), pool->size, in snd_seq_pool_init()
383 spin_lock_irq(&pool->lock); in snd_seq_pool_init()
384 if (pool->ptr) { in snd_seq_pool_init()
385 spin_unlock_irq(&pool->lock); in snd_seq_pool_init()
390 pool->ptr = cellptr; in snd_seq_pool_init()
391 pool->free = NULL; in snd_seq_pool_init()
393 for (cell = 0; cell < pool->size; cell++) { in snd_seq_pool_init()
394 cellptr = pool->ptr + cell; in snd_seq_pool_init()
395 cellptr->pool = pool; in snd_seq_pool_init()
396 cellptr->next = pool->free; in snd_seq_pool_init()
397 pool->free = cellptr; in snd_seq_pool_init()
399 pool->room = (pool->size + 1) / 2; in snd_seq_pool_init()
402 pool->max_used = 0; in snd_seq_pool_init()
403 pool->total_elements = pool->size; in snd_seq_pool_init()
404 spin_unlock_irq(&pool->lock); in snd_seq_pool_init()
408 /* refuse the further insertion to the pool */
409 void snd_seq_pool_mark_closing(struct snd_seq_pool *pool) in snd_seq_pool_mark_closing() argument
413 if (snd_BUG_ON(!pool)) in snd_seq_pool_mark_closing()
415 spin_lock_irqsave(&pool->lock, flags); in snd_seq_pool_mark_closing()
416 pool->closing = 1; in snd_seq_pool_mark_closing()
417 spin_unlock_irqrestore(&pool->lock, flags); in snd_seq_pool_mark_closing()
421 int snd_seq_pool_done(struct snd_seq_pool *pool) in snd_seq_pool_done() argument
425 if (snd_BUG_ON(!pool)) in snd_seq_pool_done()
429 if (waitqueue_active(&pool->output_sleep)) in snd_seq_pool_done()
430 wake_up(&pool->output_sleep); in snd_seq_pool_done()
432 while (atomic_read(&pool->counter) > 0) in snd_seq_pool_done()
436 spin_lock_irq(&pool->lock); in snd_seq_pool_done()
437 ptr = pool->ptr; in snd_seq_pool_done()
438 pool->ptr = NULL; in snd_seq_pool_done()
439 pool->free = NULL; in snd_seq_pool_done()
440 pool->total_elements = 0; in snd_seq_pool_done()
441 spin_unlock_irq(&pool->lock); in snd_seq_pool_done()
445 spin_lock_irq(&pool->lock); in snd_seq_pool_done()
446 pool->closing = 0; in snd_seq_pool_done()
447 spin_unlock_irq(&pool->lock); in snd_seq_pool_done()
453 /* init new memory pool */
456 struct snd_seq_pool *pool; in snd_seq_pool_new() local
458 /* create pool block */ in snd_seq_pool_new()
459 pool = kzalloc(sizeof(*pool), GFP_KERNEL); in snd_seq_pool_new()
460 if (!pool) in snd_seq_pool_new()
462 spin_lock_init(&pool->lock); in snd_seq_pool_new()
463 pool->ptr = NULL; in snd_seq_pool_new()
464 pool->free = NULL; in snd_seq_pool_new()
465 pool->total_elements = 0; in snd_seq_pool_new()
466 atomic_set(&pool->counter, 0); in snd_seq_pool_new()
467 pool->closing = 0; in snd_seq_pool_new()
468 init_waitqueue_head(&pool->output_sleep); in snd_seq_pool_new()
470 pool->size = poolsize; in snd_seq_pool_new()
473 pool->max_used = 0; in snd_seq_pool_new()
474 return pool; in snd_seq_pool_new()
477 /* remove memory pool */
480 struct snd_seq_pool *pool = *ppool; in snd_seq_pool_delete() local
483 if (pool == NULL) in snd_seq_pool_delete()
485 snd_seq_pool_mark_closing(pool); in snd_seq_pool_delete()
486 snd_seq_pool_done(pool); in snd_seq_pool_delete()
487 kfree(pool); in snd_seq_pool_delete()
493 struct snd_seq_pool *pool, char *space) in snd_seq_info_pool() argument
495 if (pool == NULL) in snd_seq_info_pool()
497 snd_iprintf(buffer, "%sPool size : %d\n", space, pool->total_elements); in snd_seq_info_pool()
498 snd_iprintf(buffer, "%sCells in use : %d\n", space, atomic_read(&pool->counter)); in snd_seq_info_pool()
499 snd_iprintf(buffer, "%sPeak cells in use : %d\n", space, pool->max_used); in snd_seq_info_pool()
500 snd_iprintf(buffer, "%sAlloc success : %d\n", space, pool->event_alloc_success); in snd_seq_info_pool()
501 snd_iprintf(buffer, "%sAlloc failures : %d\n", space, pool->event_alloc_failures); in snd_seq_info_pool()