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
139 if (snd_BUG_ON(!f || !cell)) in snd_seq_prioq_cell_in()
140 return -EINVAL; in snd_seq_prioq_cell_in()
143 prior = (cell->event.flags & SNDRV_SEQ_PRIORITY_MASK); in snd_seq_prioq_cell_in()
145 spin_lock_irqsave(&f->lock, flags); in snd_seq_prioq_cell_in()
150 if (f->tail && !prior) { in snd_seq_prioq_cell_in()
151 if (compare_timestamp(&cell->event, &f->tail->event)) { in snd_seq_prioq_cell_in()
152 /* add new cell to tail of the fifo */ in snd_seq_prioq_cell_in()
153 f->tail->next = cell; in snd_seq_prioq_cell_in()
154 f->tail = cell; in snd_seq_prioq_cell_in()
155 cell->next = NULL; in snd_seq_prioq_cell_in()
156 f->cells++; in snd_seq_prioq_cell_in()
157 spin_unlock_irqrestore(&f->lock, flags); in snd_seq_prioq_cell_in()
161 /* traverse list of elements to find the place where the new cell is in snd_seq_prioq_cell_in()
164 prev = NULL; /* previous cell */ in snd_seq_prioq_cell_in()
165 cur = f->head; /* cursor */ in snd_seq_prioq_cell_in()
170 int rel = compare_timestamp_rel(&cell->event, &cur->event); in snd_seq_prioq_cell_in()
172 /* new cell has earlier schedule time, */ in snd_seq_prioq_cell_in()
177 /* new cell has equal or larger schedule time, */ in snd_seq_prioq_cell_in()
178 /* move cursor to next cell */ in snd_seq_prioq_cell_in()
180 cur = cur->next; in snd_seq_prioq_cell_in()
181 if (! --count) { in snd_seq_prioq_cell_in()
182 spin_unlock_irqrestore(&f->lock, flags); in snd_seq_prioq_cell_in()
184 return -EINVAL; in snd_seq_prioq_cell_in()
190 prev->next = cell; in snd_seq_prioq_cell_in()
191 cell->next = cur; in snd_seq_prioq_cell_in()
193 if (f->head == cur) /* this is the first cell, set head to it */ in snd_seq_prioq_cell_in()
194 f->head = cell; in snd_seq_prioq_cell_in()
196 f->tail = cell; in snd_seq_prioq_cell_in()
197 f->cells++; in snd_seq_prioq_cell_in()
198 spin_unlock_irqrestore(&f->lock, flags); in snd_seq_prioq_cell_in()
202 /* return 1 if the current time >= event timestamp */
205 if ((ev->flags & SNDRV_SEQ_TIME_STAMP_MASK) == SNDRV_SEQ_TIME_STAMP_TICK) in event_is_ready()
206 return snd_seq_compare_tick_time(current_time, &ev->time.tick); in event_is_ready()
208 return snd_seq_compare_real_time(current_time, &ev->time.time); in event_is_ready()
211 /* dequeue cell from prioq */
215 struct snd_seq_event_cell *cell; in snd_seq_prioq_cell_out() local
222 spin_lock_irqsave(&f->lock, flags); in snd_seq_prioq_cell_out()
224 cell = f->head; in snd_seq_prioq_cell_out()
225 if (cell && current_time && !event_is_ready(&cell->event, current_time)) in snd_seq_prioq_cell_out()
226 cell = NULL; in snd_seq_prioq_cell_out()
227 if (cell) { in snd_seq_prioq_cell_out()
228 f->head = cell->next; in snd_seq_prioq_cell_out()
231 if (f->tail == cell) in snd_seq_prioq_cell_out()
232 f->tail = NULL; in snd_seq_prioq_cell_out()
234 cell->next = NULL; in snd_seq_prioq_cell_out()
235 f->cells--; in snd_seq_prioq_cell_out()
238 spin_unlock_irqrestore(&f->lock, flags); in snd_seq_prioq_cell_out()
239 return cell; in snd_seq_prioq_cell_out()
249 return f->cells; in snd_seq_prioq_avail()
252 static inline int prioq_match(struct snd_seq_event_cell *cell, in prioq_match() argument
255 if (cell->event.source.client == client || in prioq_match()
256 cell->event.dest.client == client) in prioq_match()
257 return 1; in prioq_match()
260 switch (cell->event.flags & SNDRV_SEQ_TIME_STAMP_MASK) { in prioq_match()
262 if (cell->event.time.tick) in prioq_match()
263 return 1; in prioq_match()
266 if (cell->event.time.time.tv_sec || in prioq_match()
267 cell->event.time.time.tv_nsec) in prioq_match()
268 return 1; in prioq_match()
277 register struct snd_seq_event_cell *cell, *next; in snd_seq_prioq_leave() local
283 spin_lock_irqsave(&f->lock, flags); in snd_seq_prioq_leave()
284 cell = f->head; in snd_seq_prioq_leave()
285 while (cell) { in snd_seq_prioq_leave()
286 next = cell->next; in snd_seq_prioq_leave()
287 if (prioq_match(cell, client, timestamp)) { in snd_seq_prioq_leave()
288 /* remove cell from prioq */ in snd_seq_prioq_leave()
289 if (cell == f->head) { in snd_seq_prioq_leave()
290 f->head = cell->next; in snd_seq_prioq_leave()
292 prev->next = cell->next; in snd_seq_prioq_leave()
294 if (cell == f->tail) in snd_seq_prioq_leave()
295 f->tail = cell->next; in snd_seq_prioq_leave()
296 f->cells--; in snd_seq_prioq_leave()
297 /* add cell to free list */ in snd_seq_prioq_leave()
298 cell->next = NULL; in snd_seq_prioq_leave()
300 freefirst = cell; in snd_seq_prioq_leave()
302 freeprev->next = cell; in snd_seq_prioq_leave()
304 freeprev = cell; in snd_seq_prioq_leave()
309 cell->event.type, in snd_seq_prioq_leave()
310 cell->event.source.client, in snd_seq_prioq_leave()
311 cell->event.dest.client, in snd_seq_prioq_leave()
314 prev = cell; in snd_seq_prioq_leave()
316 cell = next; in snd_seq_prioq_leave()
318 spin_unlock_irqrestore(&f->lock, flags); in snd_seq_prioq_leave()
322 freenext = freefirst->next; in snd_seq_prioq_leave()
333 if (info->remove_mode & SNDRV_SEQ_REMOVE_DEST) { in prioq_remove_match()
334 if (ev->dest.client != info->dest.client || in prioq_remove_match()
335 ev->dest.port != info->dest.port) in prioq_remove_match()
338 if (info->remove_mode & SNDRV_SEQ_REMOVE_DEST_CHANNEL) { in prioq_remove_match()
342 if (ev->data.note.channel != info->channel) in prioq_remove_match()
345 if (info->remove_mode & SNDRV_SEQ_REMOVE_TIME_AFTER) { in prioq_remove_match()
346 if (info->remove_mode & SNDRV_SEQ_REMOVE_TIME_TICK) in prioq_remove_match()
347 res = snd_seq_compare_tick_time(&ev->time.tick, &info->time.tick); in prioq_remove_match()
349 res = snd_seq_compare_real_time(&ev->time.time, &info->time.time); in prioq_remove_match()
353 if (info->remove_mode & SNDRV_SEQ_REMOVE_TIME_BEFORE) { in prioq_remove_match()
354 if (info->remove_mode & SNDRV_SEQ_REMOVE_TIME_TICK) in prioq_remove_match()
355 res = snd_seq_compare_tick_time(&ev->time.tick, &info->time.tick); in prioq_remove_match()
357 res = snd_seq_compare_real_time(&ev->time.time, &info->time.time); in prioq_remove_match()
361 if (info->remove_mode & SNDRV_SEQ_REMOVE_EVENT_TYPE) { in prioq_remove_match()
362 if (ev->type != info->type) in prioq_remove_match()
365 if (info->remove_mode & SNDRV_SEQ_REMOVE_IGNORE_OFF) { in prioq_remove_match()
367 switch (ev->type) { in prioq_remove_match()
375 if (info->remove_mode & SNDRV_SEQ_REMOVE_TAG_MATCH) { in prioq_remove_match()
376 if (info->tag != ev->tag) in prioq_remove_match()
380 return 1; in prioq_remove_match()
387 struct snd_seq_event_cell *cell, *next; in snd_seq_prioq_remove_events() local
393 spin_lock_irqsave(&f->lock, flags); in snd_seq_prioq_remove_events()
394 cell = f->head; in snd_seq_prioq_remove_events()
396 while (cell) { in snd_seq_prioq_remove_events()
397 next = cell->next; in snd_seq_prioq_remove_events()
398 if (cell->event.source.client == client && in snd_seq_prioq_remove_events()
399 prioq_remove_match(info, &cell->event)) { in snd_seq_prioq_remove_events()
401 /* remove cell from prioq */ in snd_seq_prioq_remove_events()
402 if (cell == f->head) { in snd_seq_prioq_remove_events()
403 f->head = cell->next; in snd_seq_prioq_remove_events()
405 prev->next = cell->next; in snd_seq_prioq_remove_events()
408 if (cell == f->tail) in snd_seq_prioq_remove_events()
409 f->tail = cell->next; in snd_seq_prioq_remove_events()
410 f->cells--; in snd_seq_prioq_remove_events()
412 /* add cell to free list */ in snd_seq_prioq_remove_events()
413 cell->next = NULL; in snd_seq_prioq_remove_events()
415 freefirst = cell; in snd_seq_prioq_remove_events()
417 freeprev->next = cell; in snd_seq_prioq_remove_events()
420 freeprev = cell; in snd_seq_prioq_remove_events()
422 prev = cell; in snd_seq_prioq_remove_events()
424 cell = next; in snd_seq_prioq_remove_events()
426 spin_unlock_irqrestore(&f->lock, flags); in snd_seq_prioq_remove_events()
430 freenext = freefirst->next; in snd_seq_prioq_remove_events()