#include "seq_oss_event.h"
#include <sound/seq_oss_legacy.h>
#include "../seq_lock.h"
+#include <linux/wait.h>
/*
* constants
/*
* create a read queue
*/
-seq_oss_readq_t *
-snd_seq_oss_readq_new(seq_oss_devinfo_t *dp, int maxlen)
+struct seq_oss_readq *
+snd_seq_oss_readq_new(struct seq_oss_devinfo *dp, int maxlen)
{
- seq_oss_readq_t *q;
+ struct seq_oss_readq *q;
- if ((q = snd_kcalloc(sizeof(*q), GFP_KERNEL)) == NULL) {
+ if ((q = kzalloc(sizeof(*q), GFP_KERNEL)) == NULL) {
snd_printk(KERN_ERR "can't malloc read queue\n");
return NULL;
}
- if ((q->q = snd_kcalloc(sizeof(evrec_t) * maxlen, GFP_KERNEL)) == NULL) {
+ if ((q->q = kcalloc(maxlen, sizeof(union evrec), GFP_KERNEL)) == NULL) {
snd_printk(KERN_ERR "can't malloc read queue buffer\n");
kfree(q);
return NULL;
* delete the read queue
*/
void
-snd_seq_oss_readq_delete(seq_oss_readq_t *q)
+snd_seq_oss_readq_delete(struct seq_oss_readq *q)
{
if (q) {
- snd_seq_oss_readq_clear(q); /* to be sure */
- if (q->q)
- kfree(q->q);
+ kfree(q->q);
kfree(q);
}
}
* reset the read queue
*/
void
-snd_seq_oss_readq_clear(seq_oss_readq_t *q)
+snd_seq_oss_readq_clear(struct seq_oss_readq *q)
{
if (q->qlen) {
q->qlen = 0;
* put a midi byte
*/
int
-snd_seq_oss_readq_puts(seq_oss_readq_t *q, int dev, unsigned char *data, int len)
+snd_seq_oss_readq_puts(struct seq_oss_readq *q, int dev, unsigned char *data, int len)
{
- evrec_t rec;
+ union evrec rec;
int result;
+ memset(&rec, 0, sizeof(rec));
rec.c[0] = SEQ_MIDIPUTC;
rec.c[2] = dev;
- rec.c[3] = 0;
while (len-- > 0) {
rec.c[1] = *data++;
* return zero if enqueued
*/
int
-snd_seq_oss_readq_put_event(seq_oss_readq_t *q, evrec_t *ev)
+snd_seq_oss_readq_put_event(struct seq_oss_readq *q, union evrec *ev)
{
unsigned long flags;
return -ENOMEM;
}
- memcpy(&q->q[q->tail], ev, ev_length(ev));
+ memcpy(&q->q[q->tail], ev, sizeof(*ev));
q->tail = (q->tail + 1) % q->maxlen;
q->qlen++;
/*
* pop queue
+ * caller must hold lock
*/
-evrec_t *
-snd_seq_oss_readq_pick(seq_oss_readq_t *q, int blocking, unsigned long *rflags)
+int
+snd_seq_oss_readq_pick(struct seq_oss_readq *q, union evrec *rec)
{
- evrec_t *p;
-
- spin_lock_irqsave(&q->lock, *rflags);
- if (q->qlen == 0) {
- if (blocking) {
- spin_unlock(&q->lock);
- interruptible_sleep_on_timeout(&q->midi_sleep,
- q->pre_event_timeout);
- spin_lock(&q->lock);
- }
- if (q->qlen == 0) {
- spin_unlock_irqrestore(&q->lock, *rflags);
- return NULL;
- }
- }
- p = q->q + q->head;
-
- return p;
+ if (q->qlen == 0)
+ return -EAGAIN;
+ memcpy(rec, &q->q[q->head], sizeof(*rec));
+ return 0;
}
/*
- * unlock queue
+ * sleep until ready
*/
void
-snd_seq_oss_readq_unlock(seq_oss_readq_t *q, unsigned long flags)
+snd_seq_oss_readq_wait(struct seq_oss_readq *q)
{
- spin_unlock_irqrestore(&q->lock, flags);
+ wait_event_interruptible_timeout(q->midi_sleep,
+ (q->qlen > 0 || q->head == q->tail),
+ q->pre_event_timeout);
}
/*
- * drain one record and unlock queue
+ * drain one record
+ * caller must hold lock
*/
void
-snd_seq_oss_readq_free(seq_oss_readq_t *q, unsigned long flags)
+snd_seq_oss_readq_free(struct seq_oss_readq *q)
{
if (q->qlen > 0) {
q->head = (q->head + 1) % q->maxlen;
q->qlen--;
}
- spin_unlock_irqrestore(&q->lock, flags);
}
/*
* return non-zero if readq is not empty.
*/
unsigned int
-snd_seq_oss_readq_poll(seq_oss_readq_t *q, struct file *file, poll_table *wait)
+snd_seq_oss_readq_poll(struct seq_oss_readq *q, struct file *file, poll_table *wait)
{
poll_wait(file, &q->midi_sleep, wait);
return q->qlen;
* put a timestamp
*/
int
-snd_seq_oss_readq_put_timestamp(seq_oss_readq_t *q, unsigned long curt, int seq_mode)
+snd_seq_oss_readq_put_timestamp(struct seq_oss_readq *q, unsigned long curt, int seq_mode)
{
if (curt != q->input_time) {
- evrec_t rec;
+ union evrec rec;
+ memset(&rec, 0, sizeof(rec));
switch (seq_mode) {
case SNDRV_SEQ_OSS_MODE_SYNTH:
rec.echo = (curt << 8) | SEQ_WAIT;
}
+#ifdef CONFIG_PROC_FS
/*
* proc interface
*/
void
-snd_seq_oss_readq_info_read(seq_oss_readq_t *q, snd_info_buffer_t *buf)
+snd_seq_oss_readq_info_read(struct seq_oss_readq *q, struct snd_info_buffer *buf)
{
snd_iprintf(buf, " read queue [%s] length = %d : tick = %ld\n",
(waitqueue_active(&q->midi_sleep) ? "sleeping":"running"),
q->qlen, q->input_time);
}
+#endif /* CONFIG_PROC_FS */