Commit ec114740 authored by Peter Wächtler's avatar Peter Wächtler Committed by Linus Torvalds

[PATCH] oss/sequencer.c - convert cli to spinlocks

parent 26b6d438
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* Alan Cox : reformatted and fixed a pair of null pointer bugs * Alan Cox : reformatted and fixed a pair of null pointer bugs
*/ */
#include <linux/kmod.h> #include <linux/kmod.h>
#include <linux/spinlock.h>
#define SEQUENCER_C #define SEQUENCER_C
#include "sound_config.h" #include "sound_config.h"
...@@ -28,6 +28,7 @@ static int pending_timer = -1; /* For timer change operation */ ...@@ -28,6 +28,7 @@ static int pending_timer = -1; /* For timer change operation */
extern unsigned long seq_time; extern unsigned long seq_time;
static int obsolete_api_used = 0; static int obsolete_api_used = 0;
static spinlock_t lock=SPIN_LOCK_UNLOCKED;
/* /*
* Local counts for number of synth and MIDI devices. These are initialized * Local counts for number of synth and MIDI devices. These are initialized
...@@ -95,37 +96,38 @@ int sequencer_read(int dev, struct file *file, char *buf, int count) ...@@ -95,37 +96,38 @@ int sequencer_read(int dev, struct file *file, char *buf, int count)
ev_len = seq_mode == SEQ_1 ? 4 : 8; ev_len = seq_mode == SEQ_1 ? 4 : 8;
save_flags(flags); spin_lock_irqsave(&lock,flags);
cli();
if (!iqlen) if (!iqlen)
{ {
spin_unlock_irqrestore(&lock,flags);
if (file->f_flags & O_NONBLOCK) { if (file->f_flags & O_NONBLOCK) {
restore_flags(flags);
return -EAGAIN; return -EAGAIN;
} }
interruptible_sleep_on_timeout(&midi_sleeper, interruptible_sleep_on_timeout(&midi_sleeper,
pre_event_timeout); pre_event_timeout);
spin_lock_irqsave(&lock,flags);
if (!iqlen) if (!iqlen)
{ {
restore_flags(flags); spin_unlock_irqrestore(&lock,flags);
return 0; return 0;
} }
} }
while (iqlen && c >= ev_len) while (iqlen && c >= ev_len)
{ {
char *fixit = (char *) &iqueue[iqhead * IEV_SZ]; char *fixit = (char *) &iqueue[iqhead * IEV_SZ];
spin_unlock_irqrestore(&lock,flags);
if (copy_to_user(&(buf)[p], fixit, ev_len)) if (copy_to_user(&(buf)[p], fixit, ev_len))
goto out; return count - c;
p += ev_len; p += ev_len;
c -= ev_len; c -= ev_len;
spin_lock_irqsave(&lock,flags);
iqhead = (iqhead + 1) % SEQ_MAX_QUEUE; iqhead = (iqhead + 1) % SEQ_MAX_QUEUE;
iqlen--; iqlen--;
} }
out: spin_unlock_irqrestore(&lock,flags);
restore_flags(flags);
return count - c; return count - c;
} }
...@@ -152,13 +154,12 @@ void seq_copy_to_input(unsigned char *event_rec, int len) ...@@ -152,13 +154,12 @@ void seq_copy_to_input(unsigned char *event_rec, int len)
if (iqlen >= (SEQ_MAX_QUEUE - 1)) if (iqlen >= (SEQ_MAX_QUEUE - 1))
return; /* Overflow */ return; /* Overflow */
save_flags(flags); spin_lock_irqsave(&lock,flags);
cli();
memcpy(&iqueue[iqtail * IEV_SZ], event_rec, len); memcpy(&iqueue[iqtail * IEV_SZ], event_rec, len);
iqlen++; iqlen++;
iqtail = (iqtail + 1) % SEQ_MAX_QUEUE; iqtail = (iqtail + 1) % SEQ_MAX_QUEUE;
wake_up(&midi_sleeper); wake_up(&midi_sleeper);
restore_flags(flags); spin_unlock_irqrestore(&lock,flags);
} }
static void sequencer_midi_input(int dev, unsigned char data) static void sequencer_midi_input(int dev, unsigned char data)
...@@ -869,19 +870,19 @@ static int play_event(unsigned char *q) ...@@ -869,19 +870,19 @@ static int play_event(unsigned char *q)
return 0; return 0;
} }
/* called also as timer in irq context */
static void seq_startplay(void) static void seq_startplay(void)
{ {
unsigned long flags;
int this_one, action; int this_one, action;
unsigned long flags;
while (qlen > 0) while (qlen > 0)
{ {
save_flags(flags); spin_lock_irqsave(&lock,flags);
cli();
qhead = ((this_one = qhead) + 1) % SEQ_MAX_QUEUE; qhead = ((this_one = qhead) + 1) % SEQ_MAX_QUEUE;
qlen--; qlen--;
restore_flags(flags); spin_unlock_irqrestore(&lock,flags);
seq_playing = 1; seq_playing = 1;
...@@ -947,7 +948,6 @@ int sequencer_open(int dev, struct file *file) ...@@ -947,7 +948,6 @@ int sequencer_open(int dev, struct file *file)
{ {
int retval, mode, i; int retval, mode, i;
int level, tmp; int level, tmp;
unsigned long flags;
if (!sequencer_ok) if (!sequencer_ok)
sequencer_init(); sequencer_init();
...@@ -979,16 +979,12 @@ int sequencer_open(int dev, struct file *file) ...@@ -979,16 +979,12 @@ int sequencer_open(int dev, struct file *file)
return -ENXIO; return -ENXIO;
} }
} }
save_flags(flags);
cli();
if (sequencer_busy) if (sequencer_busy)
{ {
restore_flags(flags);
return -EBUSY; return -EBUSY;
} }
sequencer_busy = 1; sequencer_busy = 1;
obsolete_api_used = 0; obsolete_api_used = 0;
restore_flags(flags);
max_mididev = num_midis; max_mididev = num_midis;
max_synthdev = num_synths; max_synthdev = num_synths;
...@@ -1203,16 +1199,11 @@ void sequencer_release(int dev, struct file *file) ...@@ -1203,16 +1199,11 @@ void sequencer_release(int dev, struct file *file)
static int seq_sync(void) static int seq_sync(void)
{ {
unsigned long flags;
if (qlen && !seq_playing && !signal_pending(current)) if (qlen && !seq_playing && !signal_pending(current))
seq_startplay(); seq_startplay();
save_flags(flags);
cli();
if (qlen > 0) if (qlen > 0)
interruptible_sleep_on_timeout(&seq_sleeper, HZ); interruptible_sleep_on_timeout(&seq_sleeper, HZ);
restore_flags(flags);
return qlen; return qlen;
} }
...@@ -1233,13 +1224,12 @@ static void midi_outc(int dev, unsigned char data) ...@@ -1233,13 +1224,12 @@ static void midi_outc(int dev, unsigned char data)
n = 3 * HZ; /* Timeout */ n = 3 * HZ; /* Timeout */
save_flags(flags); spin_lock_irqsave(&lock,flags);
cli();
while (n && !midi_devs[dev]->outputc(dev, data)) { while (n && !midi_devs[dev]->outputc(dev, data)) {
interruptible_sleep_on_timeout(&seq_sleeper, HZ/25); interruptible_sleep_on_timeout(&seq_sleeper, HZ/25);
n--; n--;
} }
restore_flags(flags); spin_unlock_irqrestore(&lock,flags);
} }
static void seq_reset(void) static void seq_reset(void)
...@@ -1308,14 +1298,13 @@ static void seq_reset(void) ...@@ -1308,14 +1298,13 @@ static void seq_reset(void)
seq_playing = 0; seq_playing = 0;
save_flags(flags); spin_lock_irqsave(&lock,flags);
cli();
if (waitqueue_active(&seq_sleeper)) { if (waitqueue_active(&seq_sleeper)) {
/* printk( "Sequencer Warning: Unexpected sleeping process - Waking up\n"); */ /* printk( "Sequencer Warning: Unexpected sleeping process - Waking up\n"); */
wake_up(&seq_sleeper); wake_up(&seq_sleeper);
} }
restore_flags(flags); spin_unlock_irqrestore(&lock,flags);
} }
static void seq_panic(void) static void seq_panic(void)
...@@ -1499,10 +1488,9 @@ int sequencer_ioctl(int dev, struct file *file, unsigned int cmd, caddr_t arg) ...@@ -1499,10 +1488,9 @@ int sequencer_ioctl(int dev, struct file *file, unsigned int cmd, caddr_t arg)
case SNDCTL_SEQ_OUTOFBAND: case SNDCTL_SEQ_OUTOFBAND:
if (copy_from_user(&event_rec, arg, sizeof(event_rec))) if (copy_from_user(&event_rec, arg, sizeof(event_rec)))
return -EFAULT; return -EFAULT;
save_flags(flags); spin_lock_irqsave(&lock,flags);
cli();
play_event(event_rec.arr); play_event(event_rec.arr);
restore_flags(flags); spin_unlock_irqrestore(&lock,flags);
return 0; return 0;
case SNDCTL_MIDI_INFO: case SNDCTL_MIDI_INFO:
...@@ -1554,8 +1542,7 @@ unsigned int sequencer_poll(int dev, struct file *file, poll_table * wait) ...@@ -1554,8 +1542,7 @@ unsigned int sequencer_poll(int dev, struct file *file, poll_table * wait)
dev = dev >> 4; dev = dev >> 4;
save_flags(flags); spin_lock_irqsave(&lock,flags);
cli();
/* input */ /* input */
poll_wait(file, &midi_sleeper, wait); poll_wait(file, &midi_sleeper, wait);
if (iqlen) if (iqlen)
...@@ -1565,7 +1552,7 @@ unsigned int sequencer_poll(int dev, struct file *file, poll_table * wait) ...@@ -1565,7 +1552,7 @@ unsigned int sequencer_poll(int dev, struct file *file, poll_table * wait)
poll_wait(file, &seq_sleeper, wait); poll_wait(file, &seq_sleeper, wait);
if ((SEQ_MAX_QUEUE - qlen) >= output_threshold) if ((SEQ_MAX_QUEUE - qlen) >= output_threshold)
mask |= POLLOUT | POLLWRNORM; mask |= POLLOUT | POLLWRNORM;
restore_flags(flags); spin_unlock_irqrestore(&lock,flags);
return mask; return mask;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment