Lines Matching +full:1 +full:- +full:cell

1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright (c) 1998-1999 by Frank van de Pol <fvdpol@coil.demon.nl>
20 * +-------+
21 * Head --> | first |
22 * +-------+
24 * +-----v-+
26 * +-------+
28 * +-----v-+
30 * +-------+
32 * +-----v-+
33 * Tail --> | last |
34 * +-------+
50 spin_lock_init(&f->lock); in snd_seq_prioq_new()
51 f->head = NULL; in snd_seq_prioq_new()
52 f->tail = NULL; in snd_seq_prioq_new()
53 f->cells = 0; in snd_seq_prioq_new()
72 if (f->cells > 0) { in snd_seq_prioq_delete()
74 while (f->cells > 0) in snd_seq_prioq_delete()
85 /* return 1 if a >= b; 0 */
89 if ((a->flags & SNDRV_SEQ_TIME_STAMP_MASK) == SNDRV_SEQ_TIME_STAMP_TICK) { in compare_timestamp()
91 return (snd_seq_compare_tick_time(&a->time.tick, &b->time.tick)); in compare_timestamp()
94 return (snd_seq_compare_real_time(&a->time.time, &b->time.time)); in compare_timestamp()
106 if ((a->flags & SNDRV_SEQ_TIME_STAMP_MASK) == SNDRV_SEQ_TIME_STAMP_TICK) { in compare_timestamp_rel()
108 if (a->time.tick > b->time.tick) in compare_timestamp_rel()
109 return 1; in compare_timestamp_rel()
110 else if (a->time.tick == b->time.tick) in compare_timestamp_rel()
113 return -1; in compare_timestamp_rel()
116 if (a->time.time.tv_sec > b->time.time.tv_sec) in compare_timestamp_rel()
117 return 1; in compare_timestamp_rel()
118 else if (a->time.time.tv_sec == b->time.time.tv_sec) { in compare_timestamp_rel()
119 if (a->time.time.tv_nsec > b->time.time.tv_nsec) in compare_timestamp_rel()
120 return 1; in compare_timestamp_rel()
121 else if (a->time.time.tv_nsec == b->time.time.tv_nsec) in compare_timestamp_rel()
124 return -1; in compare_timestamp_rel()
126 return -1; in compare_timestamp_rel()
130 /* enqueue cell to prioq */
132 struct snd_seq_event_cell * cell) in snd_seq_prioq_cell_in() argument
138 if (snd_BUG_ON(!f || !cell)) in snd_seq_prioq_cell_in()
139 return -EINVAL; in snd_seq_prioq_cell_in()
142 prior = (cell->event.flags & SNDRV_SEQ_PRIORITY_MASK); in snd_seq_prioq_cell_in()
144 guard(spinlock_irqsave)(&f->lock); in snd_seq_prioq_cell_in()
149 if (f->tail && !prior) { in snd_seq_prioq_cell_in()
150 if (compare_timestamp(&cell->event, &f->tail->event)) { in snd_seq_prioq_cell_in()
151 /* add new cell to tail of the fifo */ in snd_seq_prioq_cell_in()
152 f->tail->next = cell; in snd_seq_prioq_cell_in()
153 f->tail = cell; in snd_seq_prioq_cell_in()
154 cell->next = NULL; in snd_seq_prioq_cell_in()
155 f->cells++; in snd_seq_prioq_cell_in()
159 /* traverse list of elements to find the place where the new cell is in snd_seq_prioq_cell_in()
162 prev = NULL; /* previous cell */ in snd_seq_prioq_cell_in()
163 cur = f->head; /* cursor */ in snd_seq_prioq_cell_in()
168 int rel = compare_timestamp_rel(&cell->event, &cur->event); in snd_seq_prioq_cell_in()
170 /* new cell has earlier schedule time, */ in snd_seq_prioq_cell_in()
175 /* new cell has equal or larger schedule time, */ in snd_seq_prioq_cell_in()
176 /* move cursor to next cell */ in snd_seq_prioq_cell_in()
178 cur = cur->next; in snd_seq_prioq_cell_in()
179 if (! --count) { in snd_seq_prioq_cell_in()
181 return -EINVAL; in snd_seq_prioq_cell_in()
187 prev->next = cell; in snd_seq_prioq_cell_in()
188 cell->next = cur; in snd_seq_prioq_cell_in()
190 if (f->head == cur) /* this is the first cell, set head to it */ in snd_seq_prioq_cell_in()
191 f->head = cell; in snd_seq_prioq_cell_in()
193 f->tail = cell; in snd_seq_prioq_cell_in()
194 f->cells++; in snd_seq_prioq_cell_in()
198 /* return 1 if the current time >= event timestamp */
201 if ((ev->flags & SNDRV_SEQ_TIME_STAMP_MASK) == SNDRV_SEQ_TIME_STAMP_TICK) in event_is_ready()
202 return snd_seq_compare_tick_time(current_time, &ev->time.tick); in event_is_ready()
204 return snd_seq_compare_real_time(current_time, &ev->time.time); in event_is_ready()
207 /* dequeue cell from prioq */
211 struct snd_seq_event_cell *cell; in snd_seq_prioq_cell_out() local
218 guard(spinlock_irqsave)(&f->lock); in snd_seq_prioq_cell_out()
219 cell = f->head; in snd_seq_prioq_cell_out()
220 if (cell && current_time && !event_is_ready(&cell->event, current_time)) in snd_seq_prioq_cell_out()
221 cell = NULL; in snd_seq_prioq_cell_out()
222 if (cell) { in snd_seq_prioq_cell_out()
223 f->head = cell->next; in snd_seq_prioq_cell_out()
226 if (f->tail == cell) in snd_seq_prioq_cell_out()
227 f->tail = NULL; in snd_seq_prioq_cell_out()
229 cell->next = NULL; in snd_seq_prioq_cell_out()
230 f->cells--; in snd_seq_prioq_cell_out()
233 return cell; in snd_seq_prioq_cell_out()
243 return f->cells; in snd_seq_prioq_avail()
248 bool (*match)(struct snd_seq_event_cell *cell, in prioq_remove_cells() argument
252 register struct snd_seq_event_cell *cell, *next; in prioq_remove_cells() local
257 scoped_guard(spinlock_irqsave, &f->lock) { in prioq_remove_cells()
258 for (cell = f->head; cell; cell = next) { in prioq_remove_cells()
259 next = cell->next; in prioq_remove_cells()
260 if (!match(cell, arg)) { in prioq_remove_cells()
261 prev = cell; in prioq_remove_cells()
265 /* remove cell from prioq */ in prioq_remove_cells()
266 if (cell == f->head) in prioq_remove_cells()
267 f->head = cell->next; in prioq_remove_cells()
269 prev->next = cell->next; in prioq_remove_cells()
270 if (cell == f->tail) in prioq_remove_cells()
271 f->tail = cell->next; in prioq_remove_cells()
272 f->cells--; in prioq_remove_cells()
274 /* add cell to free list */ in prioq_remove_cells()
275 cell->next = NULL; in prioq_remove_cells()
277 freefirst = cell; in prioq_remove_cells()
279 freeprev->next = cell; in prioq_remove_cells()
280 freeprev = cell; in prioq_remove_cells()
286 freenext = freefirst->next; in prioq_remove_cells()
297 static inline bool prioq_match(struct snd_seq_event_cell *cell, void *arg) in prioq_match() argument
301 if (cell->event.source.client == v->client || in prioq_match()
302 cell->event.dest.client == v->client) in prioq_match()
304 if (!v->timestamp) in prioq_match()
306 switch (cell->event.flags & SNDRV_SEQ_TIME_STAMP_MASK) { in prioq_match()
308 if (cell->event.time.tick) in prioq_match()
312 if (cell->event.time.time.tv_sec || in prioq_match()
313 cell->event.time.time.tv_nsec) in prioq_match()
333 static bool prioq_remove_match(struct snd_seq_event_cell *cell, void *arg) in prioq_remove_match() argument
336 struct snd_seq_event *ev = &cell->event; in prioq_remove_match()
337 struct snd_seq_remove_events *info = v->info; in prioq_remove_match()
340 if (ev->source.client != v->client) in prioq_remove_match()
343 if (info->remove_mode & SNDRV_SEQ_REMOVE_DEST) { in prioq_remove_match()
344 if (ev->dest.client != info->dest.client || in prioq_remove_match()
345 ev->dest.port != info->dest.port) in prioq_remove_match()
348 if (info->remove_mode & SNDRV_SEQ_REMOVE_DEST_CHANNEL) { in prioq_remove_match()
352 if (ev->data.note.channel != info->channel) in prioq_remove_match()
355 if (info->remove_mode & SNDRV_SEQ_REMOVE_TIME_AFTER) { in prioq_remove_match()
356 if (info->remove_mode & SNDRV_SEQ_REMOVE_TIME_TICK) in prioq_remove_match()
357 res = snd_seq_compare_tick_time(&ev->time.tick, &info->time.tick); in prioq_remove_match()
359 res = snd_seq_compare_real_time(&ev->time.time, &info->time.time); in prioq_remove_match()
363 if (info->remove_mode & SNDRV_SEQ_REMOVE_TIME_BEFORE) { in prioq_remove_match()
364 if (info->remove_mode & SNDRV_SEQ_REMOVE_TIME_TICK) in prioq_remove_match()
365 res = snd_seq_compare_tick_time(&ev->time.tick, &info->time.tick); in prioq_remove_match()
367 res = snd_seq_compare_real_time(&ev->time.time, &info->time.time); in prioq_remove_match()
371 if (info->remove_mode & SNDRV_SEQ_REMOVE_EVENT_TYPE) { in prioq_remove_match()
372 if (ev->type != info->type) in prioq_remove_match()
375 if (info->remove_mode & SNDRV_SEQ_REMOVE_IGNORE_OFF) { in prioq_remove_match()
377 switch (ev->type) { in prioq_remove_match()
385 if (info->remove_mode & SNDRV_SEQ_REMOVE_TAG_MATCH) { in prioq_remove_match()
386 if (info->tag != ev->tag) in prioq_remove_match()