Skip to content

Commit b3c705a

Browse files
committed
ALSA: rawmidi - Use workq for event handling
Kill tasklet usage in rawmidi core code. Use workq for the event callback instead of tasklet (which is used only in core/seq/seq_midi.c). Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 30bdee0 commit b3c705a

2 files changed

Lines changed: 14 additions & 27 deletions

File tree

‎include/sound/rawmidi.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/spinlock.h>
2828
#include <linux/wait.h>
2929
#include <linux/mutex.h>
30+
#include <linux/workqueue.h>
3031

3132
#if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE)
3233
#include "seq_device.h"
@@ -63,6 +64,7 @@ struct snd_rawmidi_global_ops {
6364
};
6465

6566
struct snd_rawmidi_runtime {
67+
struct snd_rawmidi_substream *substream;
6668
unsigned int drain: 1, /* drain stage */
6769
oss: 1; /* OSS compatible mode */
6870
/* midi stream buffer */
@@ -79,7 +81,7 @@ struct snd_rawmidi_runtime {
7981
/* event handler (new bytes, input only) */
8082
void (*event)(struct snd_rawmidi_substream *substream);
8183
/* defers calls to event [input] or ops->trigger [output] */
82-
struct tasklet_struct tasklet;
84+
struct work_struct event_work;
8385
/* private data */
8486
void *private_data;
8587
void (*private_free)(struct snd_rawmidi_substream *substream);

‎sound/core/rawmidi.c‎

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,12 @@ static inline int snd_rawmidi_ready_append(struct snd_rawmidi_substream *substre
9292
(!substream->append || runtime->avail >= count);
9393
}
9494

95-
static void snd_rawmidi_input_event_tasklet(unsigned long data)
95+
static void snd_rawmidi_input_event_work(struct work_struct *work)
9696
{
97-
struct snd_rawmidi_substream *substream = (struct snd_rawmidi_substream *)data;
98-
substream->runtime->event(substream);
99-
}
100-
101-
static void snd_rawmidi_output_trigger_tasklet(unsigned long data)
102-
{
103-
struct snd_rawmidi_substream *substream = (struct snd_rawmidi_substream *)data;
104-
substream->ops->trigger(substream, 1);
97+
struct snd_rawmidi_runtime *runtime =
98+
container_of(work, struct snd_rawmidi_runtime, event_work);
99+
if (runtime->event)
100+
runtime->event(runtime->substream);
105101
}
106102

107103
static int snd_rawmidi_runtime_create(struct snd_rawmidi_substream *substream)
@@ -110,16 +106,10 @@ static int snd_rawmidi_runtime_create(struct snd_rawmidi_substream *substream)
110106

111107
if ((runtime = kzalloc(sizeof(*runtime), GFP_KERNEL)) == NULL)
112108
return -ENOMEM;
109+
runtime->substream = substream;
113110
spin_lock_init(&runtime->lock);
114111
init_waitqueue_head(&runtime->sleep);
115-
if (substream->stream == SNDRV_RAWMIDI_STREAM_INPUT)
116-
tasklet_init(&runtime->tasklet,
117-
snd_rawmidi_input_event_tasklet,
118-
(unsigned long)substream);
119-
else
120-
tasklet_init(&runtime->tasklet,
121-
snd_rawmidi_output_trigger_tasklet,
122-
(unsigned long)substream);
112+
INIT_WORK(&runtime->event_work, snd_rawmidi_input_event_work);
123113
runtime->event = NULL;
124114
runtime->buffer_size = PAGE_SIZE;
125115
runtime->avail_min = 1;
@@ -150,21 +140,16 @@ static inline void snd_rawmidi_output_trigger(struct snd_rawmidi_substream *subs
150140
{
151141
if (!substream->opened)
152142
return;
153-
if (up) {
154-
tasklet_schedule(&substream->runtime->tasklet);
155-
} else {
156-
tasklet_kill(&substream->runtime->tasklet);
157-
substream->ops->trigger(substream, 0);
158-
}
143+
substream->ops->trigger(substream, up);
159144
}
160145

161146
static void snd_rawmidi_input_trigger(struct snd_rawmidi_substream *substream, int up)
162147
{
163148
if (!substream->opened)
164149
return;
165150
substream->ops->trigger(substream, up);
166-
if (!up && substream->runtime->event)
167-
tasklet_kill(&substream->runtime->tasklet);
151+
if (!up)
152+
cancel_work_sync(&substream->runtime->event_work);
168153
}
169154

170155
int snd_rawmidi_drop_output(struct snd_rawmidi_substream *substream)
@@ -926,7 +911,7 @@ int snd_rawmidi_receive(struct snd_rawmidi_substream *substream,
926911
}
927912
if (result > 0) {
928913
if (runtime->event)
929-
tasklet_schedule(&runtime->tasklet);
914+
schedule_work(&runtime->event_work);
930915
else if (snd_rawmidi_ready(substream))
931916
wake_up(&runtime->sleep);
932917
}

0 commit comments

Comments
 (0)