Lines Matching refs:coder
69 lzma_stream_coder *coder; member
187 mythread_sync(thr->coder->mutex) { in worker_error()
188 if (thr->coder->thread_error == LZMA_OK) in worker_error()
189 thr->coder->thread_error = ret; in worker_error()
191 mythread_cond_signal(&thr->coder->cond); in worker_error()
207 .check = thr->coder->stream_flags.check, in worker_encode()
208 .compressed_size = thr->coder->outq.buf_size_max, in worker_encode()
209 .uncompressed_size = thr->coder->block_size, in worker_encode()
213 .filters = thr->coder->filters, in worker_encode()
238 const size_t out_size = thr->coder->outq.buf_size_max; in worker_encode()
278 thr->block_encoder.coder, thr->allocator, in worker_encode()
389 mythread_sync(thr->coder->mutex) { in worker_start()
395 thr->coder->progress_in in worker_start()
397 thr->coder->progress_out += thr->outbuf->size; in worker_start()
402 thr->next = thr->coder->threads_free; in worker_start()
403 thr->coder->threads_free = thr; in worker_start()
405 mythread_cond_signal(&thr->coder->cond); in worker_start()
421 threads_stop(lzma_stream_coder *coder, bool wait_for_threads) in threads_stop() argument
424 for (uint32_t i = 0; i < coder->threads_initialized; ++i) { in threads_stop()
425 mythread_sync(coder->threads[i].mutex) { in threads_stop()
426 coder->threads[i].state = THR_STOP; in threads_stop()
427 mythread_cond_signal(&coder->threads[i].cond); in threads_stop()
435 for (uint32_t i = 0; i < coder->threads_initialized; ++i) { in threads_stop()
436 mythread_sync(coder->threads[i].mutex) { in threads_stop()
437 while (coder->threads[i].state != THR_IDLE) in threads_stop()
438 mythread_cond_wait(&coder->threads[i].cond, in threads_stop()
439 &coder->threads[i].mutex); in threads_stop()
450 threads_end(lzma_stream_coder *coder, const lzma_allocator *allocator) in threads_end() argument
452 for (uint32_t i = 0; i < coder->threads_initialized; ++i) { in threads_end()
453 mythread_sync(coder->threads[i].mutex) { in threads_end()
454 coder->threads[i].state = THR_EXIT; in threads_end()
455 mythread_cond_signal(&coder->threads[i].cond); in threads_end()
459 for (uint32_t i = 0; i < coder->threads_initialized; ++i) { in threads_end()
460 int ret = mythread_join(coder->threads[i].thread_id); in threads_end()
465 lzma_free(coder->threads, allocator); in threads_end()
472 initialize_new_thread(lzma_stream_coder *coder, in initialize_new_thread() argument
475 worker_thread *thr = &coder->threads[coder->threads_initialized]; in initialize_new_thread()
477 thr->in = lzma_alloc(coder->block_size, allocator); in initialize_new_thread()
489 thr->coder = coder; in initialize_new_thread()
497 ++coder->threads_initialized; in initialize_new_thread()
498 coder->thr = thr; in initialize_new_thread()
515 get_thread(lzma_stream_coder *coder, const lzma_allocator *allocator) in get_thread() argument
519 if (!lzma_outq_has_buf(&coder->outq)) in get_thread()
523 mythread_sync(coder->mutex) { in get_thread()
524 if (coder->threads_free != NULL) { in get_thread()
525 coder->thr = coder->threads_free; in get_thread()
526 coder->threads_free = coder->threads_free->next; in get_thread()
530 if (coder->thr == NULL) { in get_thread()
532 if (coder->threads_initialized == coder->threads_max) in get_thread()
536 return_if_error(initialize_new_thread(coder, allocator)); in get_thread()
541 mythread_sync(coder->thr->mutex) { in get_thread()
542 coder->thr->state = THR_RUN; in get_thread()
543 coder->thr->in_size = 0; in get_thread()
544 coder->thr->outbuf = lzma_outq_get_buf(&coder->outq); in get_thread()
545 mythread_cond_signal(&coder->thr->cond); in get_thread()
553 stream_encode_in(lzma_stream_coder *coder, const lzma_allocator *allocator, in stream_encode_in() argument
558 || (coder->thr != NULL && action != LZMA_RUN)) { in stream_encode_in()
559 if (coder->thr == NULL) { in stream_encode_in()
561 const lzma_ret ret = get_thread(coder, allocator); in stream_encode_in()
562 if (coder->thr == NULL) in stream_encode_in()
567 size_t thr_in_size = coder->thr->in_size; in stream_encode_in()
568 lzma_bufcpy(in, in_pos, in_size, coder->thr->in, in stream_encode_in()
569 &thr_in_size, coder->block_size); in stream_encode_in()
577 const bool finish = thr_in_size == coder->block_size in stream_encode_in()
582 mythread_sync(coder->thr->mutex) { in stream_encode_in()
583 if (coder->thr->state == THR_IDLE) { in stream_encode_in()
591 coder->thr->in_size = thr_in_size; in stream_encode_in()
594 coder->thr->state = THR_FINISH; in stream_encode_in()
596 mythread_cond_signal(&coder->thr->cond); in stream_encode_in()
603 mythread_sync(coder->mutex) { in stream_encode_in()
604 ret = coder->thread_error; in stream_encode_in()
611 coder->thr = NULL; in stream_encode_in()
621 wait_for_work(lzma_stream_coder *coder, mythread_condtime *wait_abs, in wait_for_work() argument
624 if (coder->timeout != 0 && !*has_blocked) { in wait_for_work()
634 mythread_condtime_set(wait_abs, &coder->cond, coder->timeout); in wait_for_work()
639 mythread_sync(coder->mutex) { in wait_for_work()
647 while ((!has_input || coder->threads_free == NULL in wait_for_work()
648 || !lzma_outq_has_buf(&coder->outq)) in wait_for_work()
649 && !lzma_outq_is_readable(&coder->outq) in wait_for_work()
650 && coder->thread_error == LZMA_OK in wait_for_work()
652 if (coder->timeout != 0) in wait_for_work()
654 &coder->cond, &coder->mutex, in wait_for_work()
657 mythread_cond_wait(&coder->cond, in wait_for_work()
658 &coder->mutex); in wait_for_work()
672 lzma_stream_coder *coder = coder_ptr; in stream_encode_mt() local
674 switch (coder->sequence) { in stream_encode_mt()
676 lzma_bufcpy(coder->header, &coder->header_pos, in stream_encode_mt()
677 sizeof(coder->header), in stream_encode_mt()
679 if (coder->header_pos < sizeof(coder->header)) in stream_encode_mt()
682 coder->header_pos = 0; in stream_encode_mt()
683 coder->sequence = SEQ_BLOCK; in stream_encode_mt()
698 mythread_sync(coder->mutex) { in stream_encode_mt()
700 ret = coder->thread_error; in stream_encode_mt()
707 ret = lzma_outq_read(&coder->outq, in stream_encode_mt()
715 ret = lzma_index_append(coder->index, in stream_encode_mt()
729 threads_stop(coder, false); in stream_encode_mt()
734 ret = stream_encode_in(coder, allocator, in stream_encode_mt()
737 threads_stop(coder, false); in stream_encode_mt()
760 if (lzma_outq_is_empty(&coder->outq)) { in stream_encode_mt()
783 if (wait_for_work(coder, &wait_abs, &has_blocked, in stream_encode_mt()
791 &coder->index_encoder, allocator, in stream_encode_mt()
792 coder->index)); in stream_encode_mt()
793 coder->sequence = SEQ_INDEX; in stream_encode_mt()
799 coder->progress_out += lzma_index_size(coder->index) in stream_encode_mt()
808 const lzma_ret ret = coder->index_encoder.code( in stream_encode_mt()
809 coder->index_encoder.coder, allocator, in stream_encode_mt()
816 coder->stream_flags.backward_size in stream_encode_mt()
817 = lzma_index_size(coder->index); in stream_encode_mt()
818 if (lzma_stream_footer_encode(&coder->stream_flags, in stream_encode_mt()
819 coder->header) != LZMA_OK) in stream_encode_mt()
822 coder->sequence = SEQ_STREAM_FOOTER; in stream_encode_mt()
828 lzma_bufcpy(coder->header, &coder->header_pos, in stream_encode_mt()
829 sizeof(coder->header), in stream_encode_mt()
831 return coder->header_pos < sizeof(coder->header) in stream_encode_mt()
843 lzma_stream_coder *coder = coder_ptr; in stream_encoder_mt_end() local
846 threads_end(coder, allocator); in stream_encoder_mt_end()
847 lzma_outq_end(&coder->outq, allocator); in stream_encoder_mt_end()
849 for (size_t i = 0; coder->filters[i].id != LZMA_VLI_UNKNOWN; ++i) in stream_encoder_mt_end()
850 lzma_free(coder->filters[i].options, allocator); in stream_encoder_mt_end()
852 lzma_next_end(&coder->index_encoder, allocator); in stream_encoder_mt_end()
853 lzma_index_end(coder->index, allocator); in stream_encoder_mt_end()
855 mythread_cond_destroy(&coder->cond); in stream_encoder_mt_end()
856 mythread_mutex_destroy(&coder->mutex); in stream_encoder_mt_end()
858 lzma_free(coder, allocator); in stream_encoder_mt_end()
918 lzma_stream_coder *coder = coder_ptr; in get_progress() local
922 mythread_sync(coder->mutex) { in get_progress()
923 *progress_in = coder->progress_in; in get_progress()
924 *progress_out = coder->progress_out; in get_progress()
926 for (size_t i = 0; i < coder->threads_initialized; ++i) { in get_progress()
927 mythread_sync(coder->threads[i].mutex) { in get_progress()
928 *progress_in += coder->threads[i].progress_in; in get_progress()
929 *progress_out += coder->threads[i] in get_progress()
973 lzma_stream_coder *coder = next->coder; in stream_encoder_mt_init() local
974 if (coder == NULL) { in stream_encoder_mt_init()
975 coder = lzma_alloc(sizeof(lzma_stream_coder), allocator); in stream_encoder_mt_init()
976 if (coder == NULL) in stream_encoder_mt_init()
979 next->coder = coder; in stream_encoder_mt_init()
985 if (mythread_mutex_init(&coder->mutex)) { in stream_encoder_mt_init()
986 lzma_free(coder, allocator); in stream_encoder_mt_init()
987 next->coder = NULL; in stream_encoder_mt_init()
991 if (mythread_cond_init(&coder->cond)) { in stream_encoder_mt_init()
992 mythread_mutex_destroy(&coder->mutex); in stream_encoder_mt_init()
993 lzma_free(coder, allocator); in stream_encoder_mt_init()
994 next->coder = NULL; in stream_encoder_mt_init()
1003 coder->filters[0].id = LZMA_VLI_UNKNOWN; in stream_encoder_mt_init()
1004 coder->index_encoder = LZMA_NEXT_CODER_INIT; in stream_encoder_mt_init()
1005 coder->index = NULL; in stream_encoder_mt_init()
1006 memzero(&coder->outq, sizeof(coder->outq)); in stream_encoder_mt_init()
1007 coder->threads = NULL; in stream_encoder_mt_init()
1008 coder->threads_max = 0; in stream_encoder_mt_init()
1009 coder->threads_initialized = 0; in stream_encoder_mt_init()
1013 coder->sequence = SEQ_STREAM_HEADER; in stream_encoder_mt_init()
1014 coder->block_size = (size_t)(block_size); in stream_encoder_mt_init()
1015 coder->thread_error = LZMA_OK; in stream_encoder_mt_init()
1016 coder->thr = NULL; in stream_encoder_mt_init()
1020 if (coder->threads_max != options->threads) { in stream_encoder_mt_init()
1021 threads_end(coder, allocator); in stream_encoder_mt_init()
1023 coder->threads = NULL; in stream_encoder_mt_init()
1024 coder->threads_max = 0; in stream_encoder_mt_init()
1026 coder->threads_initialized = 0; in stream_encoder_mt_init()
1027 coder->threads_free = NULL; in stream_encoder_mt_init()
1029 coder->threads = lzma_alloc( in stream_encoder_mt_init()
1032 if (coder->threads == NULL) in stream_encoder_mt_init()
1035 coder->threads_max = options->threads; in stream_encoder_mt_init()
1039 threads_stop(coder, true); in stream_encoder_mt_init()
1043 return_if_error(lzma_outq_init(&coder->outq, allocator, in stream_encoder_mt_init()
1047 coder->timeout = options->timeout; in stream_encoder_mt_init()
1050 for (size_t i = 0; coder->filters[i].id != LZMA_VLI_UNKNOWN; ++i) in stream_encoder_mt_init()
1051 lzma_free(coder->filters[i].options, allocator); in stream_encoder_mt_init()
1054 filters, coder->filters, allocator)); in stream_encoder_mt_init()
1057 lzma_index_end(coder->index, allocator); in stream_encoder_mt_init()
1058 coder->index = lzma_index_init(allocator); in stream_encoder_mt_init()
1059 if (coder->index == NULL) in stream_encoder_mt_init()
1063 coder->stream_flags.version = 0; in stream_encoder_mt_init()
1064 coder->stream_flags.check = options->check; in stream_encoder_mt_init()
1066 &coder->stream_flags, coder->header)); in stream_encoder_mt_init()
1068 coder->header_pos = 0; in stream_encoder_mt_init()
1071 coder->progress_in = 0; in stream_encoder_mt_init()
1072 coder->progress_out = LZMA_STREAM_HEADER_SIZE; in stream_encoder_mt_init()