]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - SQUASHFS/squashfs-tools-4.4/squashfs-tools/caches-queues-lists.h
Update CI
[Ventoy.git] / SQUASHFS / squashfs-tools-4.4 / squashfs-tools / caches-queues-lists.h
1 #ifndef CACHES_QUEUES_LISTS_H
2 #define CACHES_QUEUES_LISTS_H
3 /*
4 * Create a squashfs filesystem. This is a highly compressed read only
5 * filesystem.
6 *
7 * Copyright (c) 2013, 2014, 2019
8 * Phillip Lougher <phillip@squashfs.org.uk>
9 *
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.
14 *
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.
19 *
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.
23 *
24 * caches-queues-lists.h
25 */
26
27 #define INSERT_LIST(NAME, TYPE) \
28 void insert_##NAME##_list(TYPE **list, TYPE *entry) { \
29 if(*list) { \
30 entry->NAME##_next = *list; \
31 entry->NAME##_prev = (*list)->NAME##_prev; \
32 (*list)->NAME##_prev->NAME##_next = entry; \
33 (*list)->NAME##_prev = entry; \
34 } else { \
35 *list = entry; \
36 entry->NAME##_prev = entry->NAME##_next = entry; \
37 } \
38 }
39
40
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 */ \
45 *list = NULL; \
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; \
50 if(*list == entry) \
51 *list = entry->NAME##_next; \
52 } \
53 entry->NAME##_prev = entry->NAME##_next = NULL; \
54 }
55
56
57 #define INSERT_HASH_TABLE(NAME, TYPE, HASH_FUNCTION, FIELD, LINK) \
58 void insert_##NAME##_hash_table(TYPE *container, struct file_buffer *entry) \
59 { \
60 int hash = HASH_FUNCTION(entry->FIELD); \
61 \
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; \
67 }
68
69
70 #define REMOVE_HASH_TABLE(NAME, TYPE, HASH_FUNCTION, FIELD, LINK) \
71 void remove_##NAME##_hash_table(TYPE *container, struct file_buffer *entry) \
72 { \
73 if(entry->LINK##_prev) \
74 entry->LINK##_prev->LINK##_next = entry->LINK##_next; \
75 else \
76 container->hash_table[HASH_FUNCTION(entry->FIELD)] = \
77 entry->LINK##_next; \
78 if(entry->LINK##_next) \
79 entry->LINK##_next->LINK##_prev = entry->LINK##_prev; \
80 \
81 entry->LINK##_prev = entry->LINK##_next = NULL; \
82 }
83
84 #define HASH_SIZE 65536
85 #define CALCULATE_HASH(n) ((n) & 0xffff)
86
87
88 /* struct describing a cache entry passed between threads */
89 struct file_buffer {
90 long long index;
91 long long sequence;
92 long long file_size;
93 union {
94 long long block;
95 unsigned short checksum;
96 };
97 struct cache *cache;
98 union {
99 struct file_info *dupl_start;
100 struct file_buffer *hash_next;
101 };
102 union {
103 int duplicate;
104 struct file_buffer *hash_prev;
105 };
106 union {
107 struct {
108 struct file_buffer *free_next;
109 struct file_buffer *free_prev;
110 };
111 struct {
112 struct file_buffer *seq_next;
113 struct file_buffer *seq_prev;
114 };
115 };
116 int size;
117 int c_byte;
118 char used;
119 char fragment;
120 char error;
121 char locked;
122 char wait_on_unlock;
123 char noD;
124 char data[0] __attribute__((aligned));
125 };
126
127
128 /* struct describing queues used to pass data between threads */
129 struct queue {
130 int size;
131 int readp;
132 int writep;
133 pthread_mutex_t mutex;
134 pthread_cond_t empty;
135 pthread_cond_t full;
136 void **data;
137 };
138
139
140 /*
141 * struct describing seq_queues used to pass data between the read
142 * thread and the deflate and main threads
143 */
144 struct seq_queue {
145 int fragment_count;
146 int block_count;
147 long long sequence;
148 struct file_buffer *hash_table[HASH_SIZE];
149 pthread_mutex_t mutex;
150 pthread_cond_t wait;
151 };
152
153
154 /* Cache status struct. Caches are used to keep
155 track of memory buffers passed between different threads */
156 struct cache {
157 int max_buffers;
158 int count;
159 int buffer_size;
160 int noshrink_lookup;
161 int first_freelist;
162 union {
163 int used;
164 int max_count;
165 };
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];
171 };
172
173
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,
194 char *);
195 extern void cache_wait_unlock(struct file_buffer *);
196 extern void cache_unlock(struct file_buffer *);
197
198 extern int first_freelist;
199 #endif