mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-10-29 05:40:25 -04:00
Added the safe version of the list_for_each function.
This commit is contained in:
parent
db53ac9b41
commit
6ea4260c1c
6 changed files with 35 additions and 28 deletions
|
|
@ -753,7 +753,7 @@ int inet_pending_handler(waiter_t *waiter, unsigned short events)
|
|||
inet_pending_t *pdata;
|
||||
client_t *client;
|
||||
uint32_t cookie;
|
||||
struct list_head *item, *next;
|
||||
struct list_head *item;
|
||||
int remove = 0;
|
||||
if (events & POLLHUP)
|
||||
remove = 1;
|
||||
|
|
@ -775,7 +775,7 @@ int inet_pending_handler(waiter_t *waiter, unsigned short events)
|
|||
return 0;
|
||||
}
|
||||
|
||||
list_for_each(item, next, &inet_pendings) {
|
||||
list_for_each(item, &inet_pendings) {
|
||||
pdata = list_entry(item, inet_pending_t, list);
|
||||
if (pdata->cookie == cookie)
|
||||
goto found;
|
||||
|
|
|
|||
|
|
@ -139,10 +139,18 @@ static __inline__ void list_splice(struct list_head *list, struct list_head *hea
|
|||
/**
|
||||
* list_for_each - iterate over a list
|
||||
* @pos: the &struct list_head to use as a loop counter.
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define list_for_each(pos, head) \
|
||||
for (pos = (head)->next ; pos != (head); pos = pos->next)
|
||||
|
||||
/**
|
||||
* list_for_each_safe - iterate over a list safely (actual pointer can be invalidated)
|
||||
* @pos: the &struct list_head to use as a loop counter.
|
||||
* @next: the &struct list_head to use to save next.
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define list_for_each(pos, npos, head) \
|
||||
#define list_for_each_safe(pos, npos, head) \
|
||||
for (pos = (head)->next, npos = pos->next ; pos != (head); pos = npos, npos = pos->next)
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -54,8 +54,8 @@ int bag_add(bag_t *bag, void *ptr)
|
|||
|
||||
int bag_del(bag_t *bag, void *ptr)
|
||||
{
|
||||
struct list_head *pos, *next;
|
||||
list_for_each(pos, next, bag) {
|
||||
struct list_head *pos;
|
||||
list_for_each(pos, bag) {
|
||||
bag1_t *b = list_entry(pos, bag1_t, list);
|
||||
if (b->ptr == ptr) {
|
||||
list_del(&b->list);
|
||||
|
|
|
|||
|
|
@ -96,8 +96,8 @@ static int hctl_elem_event_handler(snd_hctl_elem_t *helem,
|
|||
case SND_CTL_EVENT_INFO:
|
||||
{
|
||||
int err = 0;
|
||||
bag_iterator_t i, n;
|
||||
bag_for_each(i, n, bag) {
|
||||
bag_iterator_t i;
|
||||
bag_for_each(i, bag) {
|
||||
snd_mixer_elem_t *melem = bag_iterator_entry(i);
|
||||
snd_mixer_class_t *class = melem->class;
|
||||
err = class->event(class, event, helem, melem);
|
||||
|
|
@ -110,7 +110,7 @@ static int hctl_elem_event_handler(snd_hctl_elem_t *helem,
|
|||
{
|
||||
int err;
|
||||
bag_iterator_t i, n;
|
||||
bag_for_each(i, n, bag) {
|
||||
bag_for_each_safe(i, n, bag) {
|
||||
snd_mixer_elem_t *melem = bag_iterator_entry(i);
|
||||
snd_mixer_class_t *class = melem->class;
|
||||
err = class->event(class, event, helem, melem);
|
||||
|
|
@ -137,14 +137,14 @@ static int hctl_event_handler(snd_hctl_t *hctl, snd_ctl_event_type_t event,
|
|||
switch (event) {
|
||||
case SND_CTL_EVENT_ADD:
|
||||
{
|
||||
struct list_head *pos, *next;
|
||||
struct list_head *pos;
|
||||
bag_t *bag;
|
||||
int err = bag_new(&bag);
|
||||
if (err < 0)
|
||||
return err;
|
||||
snd_hctl_elem_set_callback(elem, hctl_elem_event_handler);
|
||||
snd_hctl_elem_set_callback_private(elem, bag);
|
||||
list_for_each(pos, next, &mixer->classes) {
|
||||
list_for_each(pos, &mixer->classes) {
|
||||
snd_mixer_class_t *c;
|
||||
c = list_entry(pos, snd_mixer_class_t, list);
|
||||
err = c->event(c, event, elem, NULL);
|
||||
|
|
@ -189,8 +189,8 @@ int snd_mixer_attach(snd_mixer_t *mixer, const char *name)
|
|||
|
||||
int snd_mixer_detach(snd_mixer_t *mixer, const char *name)
|
||||
{
|
||||
struct list_head *pos, *next;
|
||||
list_for_each(pos, next, &mixer->slaves) {
|
||||
struct list_head *pos;
|
||||
list_for_each(pos, &mixer->slaves) {
|
||||
snd_mixer_slave_t *s;
|
||||
s = list_entry(pos, snd_mixer_slave_t, list);
|
||||
if (strcmp(name, snd_hctl_name(s->hctl)) == 0) {
|
||||
|
|
@ -292,11 +292,9 @@ int snd_mixer_elem_remove(snd_mixer_elem_t *elem)
|
|||
idx = _snd_mixer_find_elem(mixer, elem, &dir);
|
||||
if (dir != 0)
|
||||
return -EINVAL;
|
||||
__again:
|
||||
bag_for_each(i, n, &elem->helems) {
|
||||
bag_for_each_safe(i, n, &elem->helems) {
|
||||
snd_hctl_elem_t *helem = bag_iterator_entry(i);
|
||||
snd_mixer_elem_detach(elem, helem);
|
||||
goto __again; /* FIXME: optimize */
|
||||
}
|
||||
err = snd_mixer_elem_throw_event(elem, SND_CTL_EVENT_REMOVE);
|
||||
list_del(&elem->list);
|
||||
|
|
@ -320,12 +318,12 @@ int snd_mixer_elem_change(snd_mixer_elem_t *elem)
|
|||
|
||||
int snd_mixer_class_register(snd_mixer_class_t *class, snd_mixer_t *mixer)
|
||||
{
|
||||
struct list_head *pos, *next;
|
||||
struct list_head *pos;
|
||||
class->mixer = mixer;
|
||||
list_add_tail(&class->list, &mixer->classes);
|
||||
if (!class->event)
|
||||
return 0;
|
||||
list_for_each(pos, next, &mixer->slaves) {
|
||||
list_for_each(pos, &mixer->slaves) {
|
||||
int err;
|
||||
snd_mixer_slave_t *slave;
|
||||
snd_hctl_elem_t *elem;
|
||||
|
|
@ -360,8 +358,8 @@ int snd_mixer_class_unregister(snd_mixer_class_t *class)
|
|||
|
||||
int snd_mixer_load(snd_mixer_t *mixer)
|
||||
{
|
||||
struct list_head *pos, *next;
|
||||
list_for_each(pos, next, &mixer->slaves) {
|
||||
struct list_head *pos;
|
||||
list_for_each(pos, &mixer->slaves) {
|
||||
int err;
|
||||
snd_mixer_slave_t *s;
|
||||
s = list_entry(pos, snd_mixer_slave_t, list);
|
||||
|
|
@ -374,8 +372,8 @@ int snd_mixer_load(snd_mixer_t *mixer)
|
|||
|
||||
void snd_mixer_free(snd_mixer_t *mixer)
|
||||
{
|
||||
struct list_head *pos, *next;
|
||||
list_for_each(pos, next, &mixer->slaves) {
|
||||
struct list_head *pos;
|
||||
list_for_each(pos, &mixer->slaves) {
|
||||
snd_mixer_slave_t *s;
|
||||
s = list_entry(pos, snd_mixer_slave_t, list);
|
||||
snd_hctl_free(s->hctl);
|
||||
|
|
@ -456,10 +454,10 @@ int snd_mixer_set_compare(snd_mixer_t *mixer, snd_mixer_compare_t msort)
|
|||
|
||||
int snd_mixer_poll_descriptors(snd_mixer_t *mixer, struct pollfd *pfds, unsigned int space)
|
||||
{
|
||||
struct list_head *pos, *next;
|
||||
struct list_head *pos;
|
||||
unsigned int count = 0;
|
||||
assert(mixer);
|
||||
list_for_each(pos, next, &mixer->slaves) {
|
||||
list_for_each(pos, &mixer->slaves) {
|
||||
snd_mixer_slave_t *s;
|
||||
int n;
|
||||
s = list_entry(pos, snd_mixer_slave_t, list);
|
||||
|
|
@ -532,10 +530,10 @@ snd_mixer_elem_t *snd_mixer_elem_prev(snd_mixer_elem_t *elem)
|
|||
|
||||
int snd_mixer_handle_events(snd_mixer_t *mixer)
|
||||
{
|
||||
struct list_head *pos, *next;
|
||||
struct list_head *pos;
|
||||
assert(mixer);
|
||||
mixer->events = 0;
|
||||
list_for_each(pos, next, &mixer->slaves) {
|
||||
list_for_each(pos, &mixer->slaves) {
|
||||
int err;
|
||||
snd_mixer_slave_t *s;
|
||||
s = list_entry(pos, snd_mixer_slave_t, list);
|
||||
|
|
|
|||
|
|
@ -39,7 +39,8 @@ int bag_empty(bag_t *bag);
|
|||
typedef struct list_head *bag_iterator_t;
|
||||
|
||||
#define bag_iterator_entry(i) (list_entry((i), bag1_t, list)->ptr)
|
||||
#define bag_for_each(pos, next, bag) list_for_each(pos, next, bag)
|
||||
#define bag_for_each(pos, bag) list_for_each(pos, bag)
|
||||
#define bag_for_each_safe(pos, next, bag) list_for_each_safe(pos, next, bag)
|
||||
|
||||
#define MIXER_COMPARE_WEIGHT_SIMPLE_BASE 0
|
||||
#define MIXER_COMPARE_WEIGHT_NEXT_BASE 10000000
|
||||
|
|
|
|||
|
|
@ -836,8 +836,8 @@ int snd_mixer_selem_register(snd_mixer_t *mixer, snd_mixer_class_t **classp)
|
|||
snd_mixer_elem_t *snd_mixer_find_selem(snd_mixer_t *mixer,
|
||||
const snd_mixer_selem_id_t *id)
|
||||
{
|
||||
struct list_head *list, *next;
|
||||
list_for_each(list, next, &mixer->elems) {
|
||||
struct list_head *list;
|
||||
list_for_each(list, &mixer->elems) {
|
||||
snd_mixer_elem_t *e;
|
||||
selem_t *s;
|
||||
e = list_entry(list, snd_mixer_elem_t, list);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue