Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  *  ALSA sequencer Memory Manager
0004  *  Copyright (c) 1998 by Frank van de Pol <fvdpol@coil.demon.nl>
0005  */
0006 #ifndef __SND_SEQ_MEMORYMGR_H
0007 #define __SND_SEQ_MEMORYMGR_H
0008 
0009 #include <sound/seq_kernel.h>
0010 #include <linux/poll.h>
0011 
0012 struct snd_info_buffer;
0013 
0014 /* container for sequencer event (internal use) */
0015 struct snd_seq_event_cell {
0016     struct snd_seq_event event;
0017     struct snd_seq_pool *pool;              /* used pool */
0018     struct snd_seq_event_cell *next;    /* next cell */
0019 };
0020 
0021 /* design note: the pool is a contiguous block of memory, if we dynamicly
0022    want to add additional cells to the pool be better store this in another
0023    pool as we need to know the base address of the pool when releasing
0024    memory. */
0025 
0026 struct snd_seq_pool {
0027     struct snd_seq_event_cell *ptr; /* pointer to first event chunk */
0028     struct snd_seq_event_cell *free;    /* pointer to the head of the free list */
0029 
0030     int total_elements; /* pool size actually allocated */
0031     atomic_t counter;   /* cells free */
0032 
0033     int size;       /* pool size to be allocated */
0034     int room;       /* watermark for sleep/wakeup */
0035 
0036     int closing;
0037 
0038     /* statistics */
0039     int max_used;
0040     int event_alloc_nopool;
0041     int event_alloc_failures;
0042     int event_alloc_success;
0043 
0044     /* Write locking */
0045     wait_queue_head_t output_sleep;
0046 
0047     /* Pool lock */
0048     spinlock_t lock;
0049 };
0050 
0051 void snd_seq_cell_free(struct snd_seq_event_cell *cell);
0052 
0053 int snd_seq_event_dup(struct snd_seq_pool *pool, struct snd_seq_event *event,
0054               struct snd_seq_event_cell **cellp, int nonblock,
0055               struct file *file, struct mutex *mutexp);
0056 
0057 /* return number of unused (free) cells */
0058 static inline int snd_seq_unused_cells(struct snd_seq_pool *pool)
0059 {
0060     return pool ? pool->total_elements - atomic_read(&pool->counter) : 0;
0061 }
0062 
0063 /* return total number of allocated cells */
0064 static inline int snd_seq_total_cells(struct snd_seq_pool *pool)
0065 {
0066     return pool ? pool->total_elements : 0;
0067 }
0068 
0069 /* init pool - allocate events */
0070 int snd_seq_pool_init(struct snd_seq_pool *pool);
0071 
0072 /* done pool - free events */
0073 void snd_seq_pool_mark_closing(struct snd_seq_pool *pool);
0074 int snd_seq_pool_done(struct snd_seq_pool *pool);
0075 
0076 /* create pool */
0077 struct snd_seq_pool *snd_seq_pool_new(int poolsize);
0078 
0079 /* remove pool */
0080 int snd_seq_pool_delete(struct snd_seq_pool **pool);
0081 
0082 /* polling */
0083 int snd_seq_pool_poll_wait(struct snd_seq_pool *pool, struct file *file, poll_table *wait);
0084 
0085 void snd_seq_info_pool(struct snd_info_buffer *buffer,
0086                struct snd_seq_pool *pool, char *space);
0087 
0088 #endif