1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2010-2017 L-SMASH project
6 * Authors: Yusuke Nakamura <muken.the.vfrmaniac@gmail.com>
8 * Permission to use, copy, modify, and/or distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 *****************************************************************************/
21 /* This file is available under an ISC license. */
23 typedef void (*lsmash_entry_data_eliminator
)( void *data
); /* very same as free() of standard C lib; void free( void * );
24 * If 'data' is equal to NULL, the eliminator must do nothing. */
26 typedef struct lsmash_entry_tag lsmash_entry_t
;
28 struct lsmash_entry_tag
39 lsmash_entry_t
*last_accessed_entry
;
40 uint32_t last_accessed_number
;
42 lsmash_entry_data_eliminator eliminator
;
43 } lsmash_entry_list_t
;
45 /* Utility macros to avoid 'lsmash_entry_data_eliminator' casts to the 'eliminator' argument */
46 #define lsmash_list_init( list, eliminator ) \
47 lsmash_list_init_orig( list, (lsmash_entry_data_eliminator)(eliminator) )
48 #define lsmash_list_init_simple( list ) \
49 lsmash_list_init_orig( list, (lsmash_entry_data_eliminator)lsmash_free )
51 #define lsmash_list_create( eliminator ) \
52 lsmash_list_create_orig( (lsmash_entry_data_eliminator)(eliminator) )
53 #define lsmash_list_create_simple() \
54 lsmash_list_create_orig( (lsmash_entry_data_eliminator)lsmash_free )
56 /* functions for internal usage */
57 void lsmash_list_init_orig
59 lsmash_entry_list_t
*list
,
60 lsmash_entry_data_eliminator eliminator
63 lsmash_entry_list_t
*lsmash_list_create_orig
65 lsmash_entry_data_eliminator eliminator
68 void lsmash_list_destroy
70 lsmash_entry_list_t
*list
73 int lsmash_list_add_entry
75 lsmash_entry_list_t
*list
,
79 int lsmash_list_remove_entry_direct
81 lsmash_entry_list_t
*list
,
85 int lsmash_list_remove_entry
87 lsmash_entry_list_t
*list
,
91 int lsmash_list_remove_entry_tail
93 lsmash_entry_list_t
*list
96 void lsmash_list_remove_entries
98 lsmash_entry_list_t
*list
101 void lsmash_list_move_entries
103 lsmash_entry_list_t
*dst
,
104 lsmash_entry_list_t
*src
107 lsmash_entry_t
*lsmash_list_get_entry
109 lsmash_entry_list_t
*list
,
110 uint32_t entry_number
113 void *lsmash_list_get_entry_data
115 lsmash_entry_list_t
*list
,
116 uint32_t entry_number