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