35 #ifndef PARALLEL_TRONCONNEUSE_HPP
36 #define PARALLEL_TRONCONNEUSE_HPP
38 #include "../my_config.h"
48 #include <libthreadar/libthreadar.hpp>
64 enum class tronco_flags { normal = 0, stop = 1, eof = 2, die = 3, data_error = 4, exception_below = 5, exception_worker = 6, exception_error = 7 };
104 std::unique_ptr<crypto_module> & ptr);
122 virtual bool skippable(skippability direction,
const infinint & amount)
override;
189 enum class thread_status { running, suspended, dead };
212 std::deque<std::unique_ptr<crypto_segment> > lus_data;
213 std::deque<signed int> lus_flags;
219 std::unique_ptr<crypto_segment> tempo_write;
224 std::shared_ptr<libthreadar::ratelier_scatter<crypto_segment> > scatter;
225 std::shared_ptr<libthreadar::ratelier_gather<crypto_segment> > gather;
226 std::shared_ptr<libthreadar::barrier> waiter;
227 std::shared_ptr<heap<crypto_segment> > tas;
231 std::deque<crypto_worker> travailleur;
232 std::unique_ptr<read_below> crypto_reader;
233 std::unique_ptr<write_below> crypto_writer;
306 static U_I get_ratelier_size(U_I num_worker) {
return num_worker + num_worker/2; };
307 static U_I get_heap_size(U_I num_worker);
317 class read_below:
public libthreadar::thread
320 read_below(
const std::shared_ptr<libthreadar::ratelier_scatter<crypto_segment> > & to_workers,
321 const std::shared_ptr<libthreadar::barrier> & waiter,
323 U_I clear_block_size,
324 generic_file* encrypted_side,
325 const std::shared_ptr<heap<crypto_segment> > xtas,
326 infinint init_shift):
330 clear_buf_size(clear_block_size),
331 encrypted(encrypted_side),
333 initial_shift(init_shift),
335 trailing_clear_data(nullptr)
336 { flag = tronco_flags::normal; };
338 ~read_below() {
if(ptr) tas->put(move(ptr)); };
350 void set_initial_shift(
const infinint & x) { initial_shift = x; };
358 void set_pos(
const infinint & pos) { skip_to = pos; };
378 const infinint & get_clear_flow_start()
const {
return clear_flow_start; };
386 const infinint & get_pos_in_flow()
const {
return pos_in_flow; };
390 virtual void inherited_run()
override;
393 std::shared_ptr<libthreadar::ratelier_scatter <crypto_segment> > workers;
394 std::shared_ptr<libthreadar::barrier> waiting;
397 generic_file* encrypted;
398 archive_version version;
399 std::shared_ptr<heap<crypto_segment> > tas;
400 infinint initial_shift;
403 std::unique_ptr<crypto_segment> ptr;
409 infinint crypt_offset;
410 U_I encrypted_buf_size;
416 infinint clear_flow_start;
417 infinint pos_in_flow;
420 infinint get_ready_for_new_offset();
424 void position_clear2crypt(
const infinint & pos,
425 infinint & file_buf_start,
426 infinint & clear_buf_start,
427 infinint & pos_in_buf,
428 infinint & block_num);
439 class write_below:
public libthreadar::thread
442 write_below(
const std::shared_ptr<libthreadar::ratelier_gather<crypto_segment> > & from_workers,
443 const std::shared_ptr<libthreadar::barrier> & waiter,
445 generic_file* encrypted_side,
446 const std::shared_ptr<heap<crypto_segment> > xtas):
447 workers(from_workers),
451 encrypted(encrypted_side),
455 {
if(encrypted ==
nullptr)
throw SRC_BUG; };
457 bool exception_pending()
const {
return error; };
458 const infinint & get_error_block()
const {
return error_block; };
461 virtual void inherited_run()
override;
464 std::shared_ptr<libthreadar::ratelier_gather<crypto_segment> > workers;
465 std::shared_ptr<libthreadar::barrier> waiting;
468 generic_file* encrypted;
469 std::shared_ptr<heap<crypto_segment> > tas;
471 infinint error_block;
472 std::deque<std::unique_ptr<crypto_segment> >ones;
473 std::deque<signed int> flags;
486 class crypto_worker:
public libthreadar::thread
489 crypto_worker(std::shared_ptr<libthreadar::ratelier_scatter <crypto_segment> > & read_side,
490 std::shared_ptr<libthreadar::ratelier_gather <crypto_segment> > & write_side,
491 std::shared_ptr<libthreadar::barrier> waiter,
492 std::unique_ptr<crypto_module> && ptr,
500 {
if(!reader || !writer || !waiting || !crypto)
throw SRC_BUG; };
503 virtual void inherited_run()
override;
506 enum class status { fine, inform, sent };
508 std::shared_ptr<libthreadar::ratelier_scatter <crypto_segment> > & reader;
509 std::shared_ptr<libthreadar::ratelier_gather <crypto_segment> > & writer;
510 std::shared_ptr<libthreadar::barrier> waiting;
511 std::unique_ptr<crypto_module> crypto;
513 std::unique_ptr<crypto_segment> ptr;