2000-08-16 13:35:36 +00:00
|
|
|
/*
|
2001-02-11 15:45:35 +00:00
|
|
|
* Bag of pointers
|
2001-02-09 11:20:31 +00:00
|
|
|
* Copyright (c) 2001 by Abramo Bagnara <abramo@alsa-project.org>
|
2000-08-16 13:35:36 +00:00
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or modify
|
2001-12-30 09:22:54 +00:00
|
|
|
* it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
* published by the Free Software Foundation; either version 2.1 of
|
2000-08-16 13:35:36 +00:00
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2001-12-30 09:22:54 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2000-08-16 13:35:36 +00:00
|
|
|
*
|
2001-12-30 09:22:54 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2000-08-16 13:35:36 +00:00
|
|
|
* License along with this library; if not, write to the Free Software
|
2017-11-14 14:29:26 +01:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2000-08-16 13:35:36 +00:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2001-02-09 11:20:31 +00:00
|
|
|
#include "mixer_local.h"
|
2000-08-16 13:35:36 +00:00
|
|
|
|
2001-02-11 15:45:35 +00:00
|
|
|
int bag_new(bag_t **bag)
|
2000-08-16 13:35:36 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
bag_t *b = malloc(sizeof(*b));
|
|
|
|
|
if (!b)
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
INIT_LIST_HEAD(b);
|
|
|
|
|
*bag = b;
|
2000-08-16 13:35:36 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2001-02-11 15:45:35 +00:00
|
|
|
void bag_free(bag_t *bag)
|
2000-08-16 13:35:36 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
assert(list_empty(bag));
|
|
|
|
|
free(bag);
|
2000-08-16 13:35:36 +00:00
|
|
|
}
|
|
|
|
|
|
2001-02-11 15:45:35 +00:00
|
|
|
int bag_empty(bag_t *bag)
|
2000-08-16 13:35:36 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
return list_empty(bag);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int bag_add(bag_t *bag, void *ptr)
|
|
|
|
|
{
|
|
|
|
|
bag1_t *b = malloc(sizeof(*b));
|
|
|
|
|
if (!b)
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
b->ptr = ptr;
|
|
|
|
|
list_add_tail(&b->list, bag);
|
2000-08-16 13:35:36 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2001-02-11 15:45:35 +00:00
|
|
|
int bag_del(bag_t *bag, void *ptr)
|
2000-08-16 13:35:36 +00:00
|
|
|
{
|
2001-02-13 12:53:19 +00:00
|
|
|
struct list_head *pos;
|
|
|
|
|
list_for_each(pos, bag) {
|
2001-02-11 15:45:35 +00:00
|
|
|
bag1_t *b = list_entry(pos, bag1_t, list);
|
|
|
|
|
if (b->ptr == ptr) {
|
|
|
|
|
list_del(&b->list);
|
2005-01-13 17:00:11 +00:00
|
|
|
free(b);
|
2001-02-11 15:45:35 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return -ENOENT;
|
2001-02-09 11:20:31 +00:00
|
|
|
}
|
|
|
|
|
|
2001-02-11 15:45:35 +00:00
|
|
|
void bag_del_all(bag_t *bag)
|
2001-02-09 11:20:31 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
while (!list_empty(bag))
|
|
|
|
|
list_del(bag->next);
|
2000-08-16 13:35:36 +00:00
|
|
|
}
|