1 #ifndef CACHES_QUEUES_LISTS_H
2 #define CACHES_QUEUES_LISTS_H
4 * Create a squashfs filesystem. This is a highly compressed read only
7 * Copyright (c) 2013, 2014, 2019
8 * Phillip Lougher <phillip@squashfs.org.uk>
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2,
13 * or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 * caches-queues-lists.h
27 #define INSERT_LIST(NAME, TYPE) \
28 void insert_##NAME##_list(TYPE **list, TYPE *entry) { \
30 entry->NAME##_next = *list; \
31 entry->NAME##_prev = (*list)->NAME##_prev; \
32 (*list)->NAME##_prev->NAME##_next = entry; \
33 (*list)->NAME##_prev = entry; \
36 entry->NAME##_prev = entry->NAME##_next = entry; \
41 #define REMOVE_LIST(NAME, TYPE) \
42 void remove_##NAME##_list(TYPE **list, TYPE *entry) { \
43 if(entry->NAME##_prev == entry && entry->NAME##_next == entry) { \
44 /* only this entry in the list */ \
46 } else if(entry->NAME##_prev != NULL && entry->NAME##_next != NULL) { \
47 /* more than one entry in the list */ \
48 entry->NAME##_next->NAME##_prev = entry->NAME##_prev; \
49 entry->NAME##_prev->NAME##_next = entry->NAME##_next; \
51 *list = entry->NAME##_next; \
53 entry->NAME##_prev = entry->NAME##_next = NULL; \
57 #define INSERT_HASH_TABLE(NAME, TYPE, HASH_FUNCTION, FIELD, LINK) \
58 void insert_##NAME##_hash_table(TYPE *container, struct file_buffer *entry) \
60 int hash = HASH_FUNCTION(entry->FIELD); \
62 entry->LINK##_next = container->hash_table[hash]; \
63 container->hash_table[hash] = entry; \
64 entry->LINK##_prev = NULL; \
65 if(entry->LINK##_next) \
66 entry->LINK##_next->LINK##_prev = entry; \
70 #define REMOVE_HASH_TABLE(NAME, TYPE, HASH_FUNCTION, FIELD, LINK) \
71 void remove_##NAME##_hash_table(TYPE *container, struct file_buffer *entry) \
73 if(entry->LINK##_prev) \
74 entry->LINK##_prev->LINK##_next = entry->LINK##_next; \
76 container->hash_table[HASH_FUNCTION(entry->FIELD)] = \
78 if(entry->LINK##_next) \
79 entry->LINK##_next->LINK##_prev = entry->LINK##_prev; \
81 entry->LINK##_prev = entry->LINK##_next = NULL; \
84 #define HASH_SIZE 65536
85 #define CALCULATE_HASH(n) ((n) & 0xffff)
88 /* struct describing a cache entry passed between threads */
95 unsigned short checksum
;
99 struct file_info
*dupl_start
;
100 struct file_buffer
*hash_next
;
104 struct file_buffer
*hash_prev
;
108 struct file_buffer
*free_next
;
109 struct file_buffer
*free_prev
;
112 struct file_buffer
*seq_next
;
113 struct file_buffer
*seq_prev
;
124 char data
[0] __attribute__((aligned
));
128 /* struct describing queues used to pass data between threads */
133 pthread_mutex_t mutex
;
134 pthread_cond_t empty
;
141 * struct describing seq_queues used to pass data between the read
142 * thread and the deflate and main threads
148 struct file_buffer
*hash_table
[HASH_SIZE
];
149 pthread_mutex_t mutex
;
154 /* Cache status struct. Caches are used to keep
155 track of memory buffers passed between different threads */
166 pthread_mutex_t mutex
;
167 pthread_cond_t wait_for_free
;
168 pthread_cond_t wait_for_unlock
;
169 struct file_buffer
*free_list
;
170 struct file_buffer
*hash_table
[HASH_SIZE
];
174 extern struct queue
*queue_init(int);
175 extern void queue_put(struct queue
*, void *);
176 extern void *queue_get(struct queue
*);
177 extern int queue_empty(struct queue
*);
178 extern void queue_flush(struct queue
*);
179 extern void dump_queue(struct queue
*);
180 extern struct seq_queue
*seq_queue_init();
181 extern void seq_queue_put(struct seq_queue
*, struct file_buffer
*);
182 extern void dump_seq_queue(struct seq_queue
*, int);
183 extern struct file_buffer
*seq_queue_get(struct seq_queue
*);
184 extern void seq_queue_flush(struct seq_queue
*);
185 extern struct cache
*cache_init(int, int, int, int);
186 extern struct file_buffer
*cache_lookup(struct cache
*, long long);
187 extern struct file_buffer
*cache_get(struct cache
*, long long);
188 extern struct file_buffer
*cache_get_nohash(struct cache
*);
189 extern void cache_hash(struct file_buffer
*, long long);
190 extern void cache_block_put(struct file_buffer
*);
191 extern void dump_cache(struct cache
*);
192 extern struct file_buffer
*cache_get_nowait(struct cache
*, long long);
193 extern struct file_buffer
*cache_lookup_nowait(struct cache
*, long long,
195 extern void cache_wait_unlock(struct file_buffer
*);
196 extern void cache_unlock(struct file_buffer
*);
198 extern int first_freelist
;