Linux Audio

Check our new training course

Loading...
v5.4
 1/* SPDX-License-Identifier: GPL-2.0-or-later */
 2/*
 3 *  ALSA sequencer Memory Manager
 4 *  Copyright (c) 1998 by Frank van de Pol <fvdpol@coil.demon.nl>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 5 */
 6#ifndef __SND_SEQ_MEMORYMGR_H
 7#define __SND_SEQ_MEMORYMGR_H
 8
 9#include <sound/seq_kernel.h>
10#include <linux/poll.h>
11
12struct snd_info_buffer;
13
14/* container for sequencer event (internal use) */
15struct snd_seq_event_cell {
16	struct snd_seq_event event;
17	struct snd_seq_pool *pool;				/* used pool */
18	struct snd_seq_event_cell *next;	/* next cell */
19};
20
21/* design note: the pool is a contiguous block of memory, if we dynamicly
22   want to add additional cells to the pool be better store this in another
23   pool as we need to know the base address of the pool when releasing
24   memory. */
25
26struct snd_seq_pool {
27	struct snd_seq_event_cell *ptr;	/* pointer to first event chunk */
28	struct snd_seq_event_cell *free;	/* pointer to the head of the free list */
29
30	int total_elements;	/* pool size actually allocated */
31	atomic_t counter;	/* cells free */
32
33	int size;		/* pool size to be allocated */
34	int room;		/* watermark for sleep/wakeup */
35
36	int closing;
37
38	/* statistics */
39	int max_used;
40	int event_alloc_nopool;
41	int event_alloc_failures;
42	int event_alloc_success;
43
44	/* Write locking */
45	wait_queue_head_t output_sleep;
46
47	/* Pool lock */
48	spinlock_t lock;
49};
50
51void snd_seq_cell_free(struct snd_seq_event_cell *cell);
52
53int snd_seq_event_dup(struct snd_seq_pool *pool, struct snd_seq_event *event,
54		      struct snd_seq_event_cell **cellp, int nonblock,
55		      struct file *file, struct mutex *mutexp);
56
57/* return number of unused (free) cells */
58static inline int snd_seq_unused_cells(struct snd_seq_pool *pool)
59{
60	return pool ? pool->total_elements - atomic_read(&pool->counter) : 0;
61}
62
63/* return total number of allocated cells */
64static inline int snd_seq_total_cells(struct snd_seq_pool *pool)
65{
66	return pool ? pool->total_elements : 0;
67}
68
69/* init pool - allocate events */
70int snd_seq_pool_init(struct snd_seq_pool *pool);
71
72/* done pool - free events */
73void snd_seq_pool_mark_closing(struct snd_seq_pool *pool);
74int snd_seq_pool_done(struct snd_seq_pool *pool);
75
76/* create pool */
77struct snd_seq_pool *snd_seq_pool_new(int poolsize);
78
79/* remove pool */
80int snd_seq_pool_delete(struct snd_seq_pool **pool);
 
 
 
 
 
 
81
82/* polling */
83int snd_seq_pool_poll_wait(struct snd_seq_pool *pool, struct file *file, poll_table *wait);
84
85void snd_seq_info_pool(struct snd_info_buffer *buffer,
86		       struct snd_seq_pool *pool, char *space);
87
88#endif
v4.10.11
 
  1/*
  2 *  ALSA sequencer Memory Manager
  3 *  Copyright (c) 1998 by Frank van de Pol <fvdpol@coil.demon.nl>
  4 *
  5 *
  6 *   This program is free software; you can redistribute it and/or modify
  7 *   it under the terms of the GNU General Public License as published by
  8 *   the Free Software Foundation; either version 2 of the License, or
  9 *   (at your option) any later version.
 10 *
 11 *   This program is distributed in the hope that it will be useful,
 12 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 13 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14 *   GNU General Public License for more details.
 15 *
 16 *   You should have received a copy of the GNU General Public License
 17 *   along with this program; if not, write to the Free Software
 18 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 19 *
 20 */
 21#ifndef __SND_SEQ_MEMORYMGR_H
 22#define __SND_SEQ_MEMORYMGR_H
 23
 24#include <sound/seq_kernel.h>
 25#include <linux/poll.h>
 26
 27struct snd_info_buffer;
 28
 29/* container for sequencer event (internal use) */
 30struct snd_seq_event_cell {
 31	struct snd_seq_event event;
 32	struct snd_seq_pool *pool;				/* used pool */
 33	struct snd_seq_event_cell *next;	/* next cell */
 34};
 35
 36/* design note: the pool is a contiguous block of memory, if we dynamicly
 37   want to add additional cells to the pool be better store this in another
 38   pool as we need to know the base address of the pool when releasing
 39   memory. */
 40
 41struct snd_seq_pool {
 42	struct snd_seq_event_cell *ptr;	/* pointer to first event chunk */
 43	struct snd_seq_event_cell *free;	/* pointer to the head of the free list */
 44
 45	int total_elements;	/* pool size actually allocated */
 46	atomic_t counter;	/* cells free */
 47
 48	int size;		/* pool size to be allocated */
 49	int room;		/* watermark for sleep/wakeup */
 50
 51	int closing;
 52
 53	/* statistics */
 54	int max_used;
 55	int event_alloc_nopool;
 56	int event_alloc_failures;
 57	int event_alloc_success;
 58
 59	/* Write locking */
 60	wait_queue_head_t output_sleep;
 61
 62	/* Pool lock */
 63	spinlock_t lock;
 64};
 65
 66void snd_seq_cell_free(struct snd_seq_event_cell *cell);
 67
 68int snd_seq_event_dup(struct snd_seq_pool *pool, struct snd_seq_event *event,
 69		      struct snd_seq_event_cell **cellp, int nonblock, struct file *file);
 
 70
 71/* return number of unused (free) cells */
 72static inline int snd_seq_unused_cells(struct snd_seq_pool *pool)
 73{
 74	return pool ? pool->total_elements - atomic_read(&pool->counter) : 0;
 75}
 76
 77/* return total number of allocated cells */
 78static inline int snd_seq_total_cells(struct snd_seq_pool *pool)
 79{
 80	return pool ? pool->total_elements : 0;
 81}
 82
 83/* init pool - allocate events */
 84int snd_seq_pool_init(struct snd_seq_pool *pool);
 85
 86/* done pool - free events */
 87void snd_seq_pool_mark_closing(struct snd_seq_pool *pool);
 88int snd_seq_pool_done(struct snd_seq_pool *pool);
 89
 90/* create pool */
 91struct snd_seq_pool *snd_seq_pool_new(int poolsize);
 92
 93/* remove pool */
 94int snd_seq_pool_delete(struct snd_seq_pool **pool);
 95
 96/* init memory */
 97int snd_sequencer_memory_init(void);
 98            
 99/* release event memory */
100void snd_sequencer_memory_done(void);
101
102/* polling */
103int snd_seq_pool_poll_wait(struct snd_seq_pool *pool, struct file *file, poll_table *wait);
104
105void snd_seq_info_pool(struct snd_info_buffer *buffer,
106		       struct snd_seq_pool *pool, char *space);
107
108#endif