2 * ALSA sequencer Queue handling
3 * Copyright (c) 1998-1999 by Frank van de Pol <fvdpol@coil.demon.nl>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #ifndef __SND_SEQ_QUEUE_H
21 #define __SND_SEQ_QUEUE_H
23 #include "seq_memory.h"
24 #include "seq_prioq.h"
25 #include "seq_timer.h"
27 #include <linux/interrupt.h>
28 #include <linux/list.h>
29 #include <linux/bitops.h>
31 #define SEQ_QUEUE_NO_OWNER (-1)
33 struct _snd_seq_queue
{
34 int queue
; /* queue number */
36 char name
[64]; /* name of this queue */
38 prioq_t
*tickq
; /* midi tick event queue */
39 prioq_t
*timeq
; /* real-time event queue */
41 seq_timer_t
*timer
; /* time keeper for this queue */
42 int owner
; /* client that 'owns' the timer */
43 unsigned int locked
:1, /* timer is only accesibble by owner if set */
44 klocked
:1, /* kernel lock (after START) */
48 unsigned int flags
; /* status flags */
49 unsigned int info_flags
; /* info for sync */
51 spinlock_t owner_lock
;
52 spinlock_t check_lock
;
54 /* clients which uses this queue (bitmap) */
55 DECLARE_BITMAP(clients_bitmap
, SNDRV_SEQ_MAX_CLIENTS
);
56 unsigned int clients
; /* users of this queue */
57 struct semaphore timer_mutex
;
59 snd_use_lock_t use_lock
;
63 /* get the number of current queues */
64 int snd_seq_queue_get_cur_queues(void);
66 /* init queues structure */
67 int snd_seq_queues_init(void);
70 void snd_seq_queues_delete(void);
73 /* create new queue (constructor) */
74 int snd_seq_queue_alloc(int client
, int locked
, unsigned int flags
);
76 /* delete queue (destructor) */
77 int snd_seq_queue_delete(int client
, int queueid
);
79 /* notification that client has left the system */
80 void snd_seq_queue_client_termination(int client
);
83 void snd_seq_queue_client_leave(int client
);
85 /* enqueue a event received from one the clients */
86 int snd_seq_enqueue_event(snd_seq_event_cell_t
*cell
, int atomic
, int hop
);
89 void snd_seq_queue_client_leave_cells(int client
);
90 void snd_seq_queue_remove_cells(int client
, snd_seq_remove_events_t
*info
);
92 /* return pointer to queue structure for specified id */
93 queue_t
*queueptr(int queueid
);
95 #define queuefree(q) snd_use_lock_free(&(q)->use_lock)
97 /* return the (first) queue matching with the specified name */
98 queue_t
*snd_seq_queue_find_name(char *name
);
100 /* check single queue and dispatch events */
101 void snd_seq_check_queue(queue_t
*q
, int atomic
, int hop
);
103 /* access to queue's parameters */
104 int snd_seq_queue_check_access(int queueid
, int client
);
105 int snd_seq_queue_timer_set_tempo(int queueid
, int client
, snd_seq_queue_tempo_t
*info
);
106 int snd_seq_queue_set_owner(int queueid
, int client
, int locked
);
107 int snd_seq_queue_set_locked(int queueid
, int client
, int locked
);
108 int snd_seq_queue_timer_open(int queueid
);
109 int snd_seq_queue_timer_close(int queueid
);
110 int snd_seq_queue_use(int queueid
, int client
, int use
);
111 int snd_seq_queue_is_used(int queueid
, int client
);
113 int snd_seq_control_queue(snd_seq_event_t
*ev
, int atomic
, int hop
);
116 * 64bit division - for sync stuff..
118 #if defined(i386) || defined(i486)
120 #define udiv_qrnnd(q, r, n1, n0, d) \
128 #define u64_div(x,y,q) do {u32 __tmp; udiv_qrnnd(q, __tmp, (x)>>32, x, y);} while (0)
129 #define u64_mod(x,y,r) do {u32 __tmp; udiv_qrnnd(__tmp, q, (x)>>32, x, y);} while (0)
130 #define u64_divmod(x,y,q,r) udiv_qrnnd(q, r, (x)>>32, x, y)
133 #define u64_div(x,y,q) ((q) = (u32)((u64)(x) / (u64)(y)))
134 #define u64_mod(x,y,r) ((r) = (u32)((u64)(x) % (u64)(y)))
135 #define u64_divmod(x,y,q,r) (u64_div(x,y,q), u64_mod(x,y,r))