4
* Copyright 2009 PCMan <pcman.tw@gmail.com>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24
FmList* fm_list_new(FmListFuncs* funcs)
26
FmList* list = g_slice_new(FmList);
28
g_queue_init(&list->list);
33
FmList* fm_list_ref(gpointer list)
35
g_atomic_int_inc(&FM_LIST(list)->n_ref);
39
void fm_list_unref(gpointer list)
41
if(g_atomic_int_dec_and_test(&FM_LIST(list)->n_ref))
43
g_queue_foreach((GQueue*)list, (GFunc)FM_LIST(list)->funcs->item_unref, NULL);
44
g_slice_free(FmList, list);
48
void fm_list_clear(gpointer list)
50
g_queue_foreach((GQueue*)list, (GFunc)FM_LIST(list)->funcs->item_unref, NULL);
51
g_queue_clear((GQueue*)list);
54
void fm_list_remove(gpointer list, gpointer data)
56
GList* l = ((GQueue*)list)->head;
61
FM_LIST(list)->funcs->item_unref(data);
66
g_queue_delete_link((GQueue*)data, l);
69
void fm_list_remove_all(gpointer list, gpointer data)
71
/* FIXME: the performance can be better... */
72
GList* l = ((GQueue*)list)->head;
76
FM_LIST(list)->funcs->item_unref(data);
78
g_queue_remove_all((GQueue*)list, data);
81
void fm_list_delete_link(gpointer list, gpointer l_)
83
FM_LIST(list)->funcs->item_unref(((GList*)l_)->data);
84
g_queue_delete_link((GQueue*)list, l_);