Parolin 0.7.9 6796
Console (soon DLLs) to do a tar like job
Loading...
Searching...
No Matches
lzop2_multi.c
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
3 #2023 X March 21 19:50 PM Brasília Time
4
5* *
6* Licensa de Copia (C) <2023> <Aurora Boreal> *
7* *
8* Este programa e software livre: voce pode redistribuir isto e/ou *
9* modificar isto sobre os termos do GNU Licensa Geral Pública como 25
10* publicado pela Fundacao de Software Livre, tanto a versão 3 da *
11* Licensa, ou (dependendo da sua opcao) qualquer versao posterior. *
12* *
13* Este programa e distribuido na esperanca que isto vai ser util, *
14* mas SEM QUALQUER GARANTIA; sem ate mesmo a implicada garantia de *
15* COMERCIALIZAcaO ou CABIMENTO PARA UM FIM PARTICULAR. Veja a *
16* Licensa Geral Publica para mais detalhes. *
17* *
18* Você deve ter recebido uma cópia da LICENSA GERAL PUBLICA e a GNU *
19* Licensa Publica Menor junto com este programa *
20* Se não, veja <http://www.gnu.org/licenses/>. *
21* *
22* Suporte: sourceforge.net github.com *
23* *
24* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
25
26* Pereira: arsoftware25@gmail.com ricardo@arsoftware.net.br *
27* xcx: arsoftware10@gmail.com charli@arsoftware.net.br *
28 Yasmin: yasmin@arsoftware.net.br *
29 pereira1001@users.sourceforge.net
30 */
31
32
33
34double
35inittimer2_8(int value)
36{
37
38 static double freq = 0;
39 static LARGE_INTEGER first;
40 static LARGE_INTEGER second;
41
42 if (0 == value)
43 {
44
45 if (freq == 0)
46 {
47
48 QueryPerformanceFrequency(&first);
49 freq = (double)first.QuadPart;
50 }
51
52 QueryPerformanceCounter(&first);
53
54 return 0;
55 }
56
57 if (1 == value)
58 {
59
60 QueryPerformanceCounter(&second);
61
62 second.QuadPart = second.QuadPart - first.QuadPart;
63
64 return (double)second.QuadPart / freq;
65 }
66
67 return 0;
68}
69
70static uint64_t bytes_in_each_slice_z[129];
71static uint64_t offset_of_each_slice_z[129];
72
73extern int *cores_used_z_8;
74
75#include "lzop2_thread.c"
76
77int __valquiriacall compress2_uncompress_k_real_mt_z_8(char *input_z, char *output_z)
78{
79 my_thread_struct_z *ptr_my_struct_z;
80 FILE *dest_z = NULL;
81 FILE *input_file;
82 FILE *temp_z = NULL;
83 int ret_z;
84 bool adjust_z = true;
85 int ret2_z;
86 int retvalue_z = 0;
87 int n_threads_copy;
88 int n_thread_counter;
89 int ret_arp;
90 int thread_counter = 0;
91 int i_z;
92 int64_t remaining_z;
93 char signature_z[5] = "AR__";
94 static char buffer[CHUNK];
95 ar_data ar = {0};
96
97 pedro_dprintf(-1, "dentro threads %d\n", n_threads_z_8);
98
99 thread_return_value_z_8 = 0; //initial thread error value
100
101 //n_threads_copy = n_threads_z_8;
102
103 n_thread_counter = 0;
104
105 //primeiro precisa detectar quantos threads foram usados no arquivo compactado
106
107 {
108
109 input_file = _wfopen(utf8_2_wide_dl(input_z), L"rb");
110
111 }
112 /* removing weird code... ;-)
113 else
114 input_file = fopen(input_z, "rb"); //never will be called, don´t be afraid
115 */
116 if (NULL == input_file)
117 {
118 return 1; //Cannot open input file
119 }
120
121 signature_z[3] = 0x53; // new lzop2 multi-thread and single-thread signature
122
123 while (1)
124 {
125
126 memset(&ar, 0, sizeof(ar));
127 ret_arp = fread(&ar, 1, sizeof(ar), input_file);
128
129 if (0 == ret_arp)
130 {
131 goto saida_z;
132 }
133
134 if (ret_arp != sizeof(ar))
135 {
136 retvalue_z = 5;
137 goto saida_z;
138 }
139
140 if (0 != memcmp(ar.string, signature_z, 4))
141 {
142 pedro_dprintf(-1, "erro 7\n");
143 retvalue_z = 7;
144 goto saida_z;
145 }
146
147 ret_arp = fread(&remaining_z, 1, sizeof(remaining_z), input_file);
148
149 if (sizeof(remaining_z) != ret_arp)
150 {
151 retvalue_z = 5;
152 goto saida_z;
153 }
154 bytes_in_each_slice_z[thread_counter] = remaining_z;
155 offset_of_each_slice_z[thread_counter] = _ftelli64(input_file);
156
157 pedro_dprintf(-1, "itens %lld %lld\n",
158 bytes_in_each_slice_z[thread_counter],
159 offset_of_each_slice_z[thread_counter]);
160
161 _fseeki64(input_file, remaining_z, SEEK_CUR);
162
163 thread_counter++;
164 }
165
166saida_z:;
167
168 fclose(input_file);
169
170 pedro_dprintf(0, "8count of threads %d\n", thread_counter);
171
172 if (retvalue_z)
173 {
174 return 7;
175 }
176
177 //exit(27);
178
179 n_threads_z_8 = thread_counter;
180
182
184
185 n_threads_copy = thread_counter;
186 pedro_dprintf(-1, "veja 1\n");
187
188 inittimer2_8(0);
189
190 while (n_threads_copy--)
191 {
192 pedro_dprintf(-1, "running thread %d\n", n_thread_counter);
193
194 ptr_my_struct_z = calloc(1, sizeof(my_thread_struct_z));
195 assert(ptr_my_struct_z);
196
197 ptr_my_struct_z->thread_id_z = n_thread_counter;
198
199 {
200
201 ptr_my_struct_z->input_file = _wfopen(utf8_2_wide_dl(input_z), L"rb");
202
203 }
204
205 intpause_8 = 0;
206 intcancel_8 = 0;
207
208 ptr_my_struct_z->intpause_8 = &intpause_8;
209 ptr_my_struct_z->intcancel_8 = &intcancel_8;
210
211 bytes__read_thread_z_8[n_thread_counter] = 0;
212
213 ptr_my_struct_z->bytes_read_z =
214 &bytes__read_thread_z_8[n_thread_counter];
215
216 ptr_my_struct_z->size_of_input_file_z = ptr_my_struct_z->size_of_input_file_copy_z = bytes_in_each_slice_z[n_thread_counter];
217
218 ptr_my_struct_z->offset_z =
219 offset_of_each_slice_z[n_thread_counter];
220
221 if (!createtempfilename_and_keep_z_8(temp_path_z_8, temp_files_z_8[n_thread_counter], "LZ2"))
222 {
224 {
225 thread_return_value_z_8 = 407; //Cannot create temp file
226 }
227 }
228 else
229 {
230 if (true)
231 {
232#ifdef ARP_USE_ENHANCED_STDIO
233
234 ptr_my_struct_z->dest = fopen(temp_files_z_8[n_thread_counter], "wb");
235
236#else
237#error stdio
238 ptr_my_struct_z->dest = _wfopen(wpmode, L"wb");
239#endif
240 }
241
242 if (NULL == ptr_my_struct_z->dest)
243 {
245 {
246 thread_return_value_z_8 = 405; //Cannot open output tempfile
247 }
248 }
249 }
250
251 my_thread_handle_8[n_thread_counter] = (__INT32_OR_INT64)_beginthreadex(NULL, 0, my_thread_function_v27_8, ptr_my_struct_z, 0, NULL);
252
253 n_thread_counter++;
254 }
255
256 for (i_z = 0; i_z < n_threads_z_8; i_z++)
257 {
258 WaitForSingleObject((void *)my_thread_handle_8[i_z], INFINITE);
259 CloseHandle((void *)my_thread_handle_8[i_z]);
260 pedro_dprintf(-1, "Close next\n");
261 }
262
263 pedro_dprintf(-1, "comprimiu em %.3f\n", inittimer2_8(1));
264
265 if (true)
266 {
267
268 SetFileAttributesW(utf8_2_wide_dl(output_z), FILE_ATTRIBUTE_ARCHIVE);
269
270 }
271
272 //abrir arquivo
273
274 {
275
276 dest_z = _wfopen(utf8_2_wide_dl(output_z), L"wb");
277
278 }
279
280 if (NULL == dest_z)
281 {
283 {
284 thread_return_value_z_8 = 2; //Cannot open output file
285 }
286 }
287
288 inittimer2_8(0);
289 //depois de finalizar
290 for (i_z = 0; i_z < n_threads_z_8; i_z++)
291 {
292 pedro_dprintf(-1, "arquivo temp a del %s\n", temp_files_z_8[i_z]);
293 if (dest_z)
294 {
295
296 if (true)
297 {
298#ifdef ARP_USE_ENHANCED_STDIO
299
300 temp_z = fopen(temp_files_z_8[i_z], "rb");
301
302#else
303 temp_z = _wfopen(wpmode, L"rb");
304#endif
305 }
306
307 if (temp_z)
308 {
309 //Mr. Do
310
311 volta_amanda:;
312#ifdef ARP_USE_ENHANCED_STDIO
313 ret_z = fread(buffer, 1, CHUNK, temp_z);
314#else
315 ret_z = fread(buffer, 1, CHUNK, temp_z);
316#endif
317 if (0 > ret_z)
318 {
320 {
321 thread_return_value_z_8 = 5; //Cannot read from input file
322 }
323 }
324 else if (0 == ret_z)
325 {
326 ; //just go by...
327 }
328 else
329 {
330 adjust_z = false; //debugging
331 if (adjust_z)
332 {
333 pedro_dprintf(-1, "vai ajustar %s\n", output_z);
334 adjust_z = false;
335
336 ret2_z = _chsize_s(_fileno(dest_z), 295226633);
337 pedro_dprintf(-1, "value must be 0\n", ret2_z);
338 }
339 ret2_z = fwrite(buffer, 1, ret_z, dest_z);
340
341 if (ret2_z != ret_z)
342 {
344 {
345 thread_return_value_z_8 = 6; //Cannot write to output file
346 }
347 goto exit_loop_z;
348 }
350 //to make the compiler happy...
351
352 ret2_z = 0;
353 ret2_z++;
354
355 if (-1 == ret2_z)
356 {
357 ret2_z = -2;
358
359 return ret2_z;
360 }
361
363
364 goto volta_amanda;
365 }
366
367 exit_loop_z:;
368
369 fclose(temp_z);
370
371 }
372 else
373 {
375 {
376 thread_return_value_z_8 = 405; //Cannot open temp file
377 }
378 }
379 }
380
381 unlink(temp_files_z_8[i_z]); // future fix here
382
383 }
384
385 pedro_dprintf(-1, "demorou 1 %.3f\n", inittimer2_8(1));
386
387 inittimer2_8(0);
388
389 //precisa setar isto antes de retornar
390
391 pedro_dprintf(-1, "demorou 2 %.3f\n", inittimer2_8(1));
392 pedro_dprintf(-1, "final finalmente\n");
393
394 if (dest_z)
395 {
396 fclose(dest_z);
397 }
398
399 //exit(27);
400 finished_8 = 1; //e depois return
401 intstatus_8 = 0;
403
404 pedro_dprintf(-1, "final ...%s %d\n", temp_path_z_8, (int)thread_return_value_z_8);
405 exit(27);
406 return 0;
407}
#define FILE_ATTRIBUTE_ARCHIVE
Definition 7zTypes.h:147
void pedro_dprintf(int amanda_level, char *format,...)
Definition pedro.c:43
#define CHUNK
Definition brotli2.c:163
#define assert(condition)
Definition lz4.c:273
uint64_t offset_of_each_slice_z[129]
Definition lz5_multi.c:129
uint64_t bytes_in_each_slice_z[129]
Definition lz5_multi.c:128
Definition stdio_v3.h:12
char string[4]
Definition stdio_v3.h:13
Definition stdio_v3.h:23
int64_t offset_z
Definition stdio_v3.h:44
int64_t size_of_input_file_copy_z
Definition stdio_v3.h:46
int64_t * bytes_read_z
Definition stdio_v3.h:43
int * intcancel_8
Definition stdio_v3.h:28
FILE * dest
Definition stdio_v3.h:26
int thread_id_z
Definition stdio_v3.h:40
int * intpause_8
Definition stdio_v3.h:27
FILE * input_file
Definition stdio_v3.h:35
int64_t size_of_input_file_z
Definition stdio_v3.h:47
WCHAR * utf8_2_wide_dl(char *pUTF8)
Definition tar_1_33.c:745
#define __valquiriacall
Definition tar_1_33.c:80
#define __INT32_OR_INT64
Definition win64.h:41
#define SEEK_CUR
Definition zconf.h:499
int intcancel_8
Definition compress2dll.c:140
__INT32_OR_INT64 my_thread_handle_8[129]
Definition compress2_2_z.c:270
char temp_files_z_8[129][2048]
Definition compress2_2_z.c:271
int intpause_8
Definition compress2dll.c:139
int finished_8
Definition compress2_2_z.c:128
int thread_return_value_z_8
Definition compress2_2_z.c:272
int intstatus_8
Definition compress2dll.c:142
int createtempfilename_and_keep_z_8(char *path1, char *out_z, char *signature_z)
Create a tempfilename with in ANSI format (28/dec/2024), if you plan to allow other temp paths in the...
Definition compress2_2_z.c:199
int64_t bytes__read_thread_z_8[129]
Definition compress2_2_z.c:267
char temp_path_z_8[]
Definition compress2dll.c:108
int n_threads_z_8
Definition compress2dll.c:109
double inittimer2_8(int value)
Definition lzop2_multi.c:35
int __valquiriacall compress2_uncompress_k_real_mt_z_8(char *input_z, char *output_z)
Definition lzop2_multi.c:77
int * cores_used_z_8
Definition compress2dll.c:92
unsigned __stdcall my_thread_function_v27_8(void *my_argument_z)
Definition lzop2_thread.c:31
#define NULL
Definition getopt1.c:37
signature_z[3]
Definition zlib_interface.c:37