Lines Matching refs:coder

68 	lzma_stream_coder *coder;  member
207 mythread_sync(thr->coder->mutex) { in worker_error()
208 if (thr->coder->thread_error == LZMA_OK) in worker_error()
209 thr->coder->thread_error = ret; in worker_error()
211 mythread_cond_signal(&thr->coder->cond); in worker_error()
227 .check = thr->coder->stream_flags.check, in worker_encode()
229 .uncompressed_size = thr->coder->block_size, in worker_encode()
295 thr->block_encoder.coder, thr->allocator, in worker_encode()
408 mythread_sync(thr->coder->mutex) { in worker_start()
417 thr->coder->progress_in in worker_start()
419 thr->coder->progress_out += out_pos; in worker_start()
424 thr->next = thr->coder->threads_free; in worker_start()
425 thr->coder->threads_free = thr; in worker_start()
427 mythread_cond_signal(&thr->coder->cond); in worker_start()
445 threads_stop(lzma_stream_coder *coder, bool wait_for_threads) in threads_stop() argument
448 for (uint32_t i = 0; i < coder->threads_initialized; ++i) { in threads_stop()
449 mythread_sync(coder->threads[i].mutex) { in threads_stop()
450 coder->threads[i].state = THR_STOP; in threads_stop()
451 mythread_cond_signal(&coder->threads[i].cond); in threads_stop()
459 for (uint32_t i = 0; i < coder->threads_initialized; ++i) { in threads_stop()
460 mythread_sync(coder->threads[i].mutex) { in threads_stop()
461 while (coder->threads[i].state != THR_IDLE) in threads_stop()
462 mythread_cond_wait(&coder->threads[i].cond, in threads_stop()
463 &coder->threads[i].mutex); in threads_stop()
474 threads_end(lzma_stream_coder *coder, const lzma_allocator *allocator) in threads_end() argument
476 for (uint32_t i = 0; i < coder->threads_initialized; ++i) { in threads_end()
477 mythread_sync(coder->threads[i].mutex) { in threads_end()
478 coder->threads[i].state = THR_EXIT; in threads_end()
479 mythread_cond_signal(&coder->threads[i].cond); in threads_end()
483 for (uint32_t i = 0; i < coder->threads_initialized; ++i) { in threads_end()
484 int ret = mythread_join(coder->threads[i].thread_id); in threads_end()
489 lzma_free(coder->threads, allocator); in threads_end()
496 initialize_new_thread(lzma_stream_coder *coder, in initialize_new_thread() argument
499 worker_thread *thr = &coder->threads[coder->threads_initialized]; in initialize_new_thread()
501 thr->in = lzma_alloc(coder->block_size, allocator); in initialize_new_thread()
513 thr->coder = coder; in initialize_new_thread()
522 ++coder->threads_initialized; in initialize_new_thread()
523 coder->thr = thr; in initialize_new_thread()
540 get_thread(lzma_stream_coder *coder, const lzma_allocator *allocator) in get_thread() argument
544 if (!lzma_outq_has_buf(&coder->outq)) in get_thread()
549 return_if_error(lzma_outq_prealloc_buf(&coder->outq, allocator, in get_thread()
550 coder->outbuf_alloc_size)); in get_thread()
555 if (coder->filters_cache[0].id == LZMA_VLI_UNKNOWN) in get_thread()
557 coder->filters, coder->filters_cache, allocator)); in get_thread()
560 mythread_sync(coder->mutex) { in get_thread()
561 if (coder->threads_free != NULL) { in get_thread()
562 coder->thr = coder->threads_free; in get_thread()
563 coder->threads_free = coder->threads_free->next; in get_thread()
567 if (coder->thr == NULL) { in get_thread()
569 if (coder->threads_initialized == coder->threads_max) in get_thread()
573 return_if_error(initialize_new_thread(coder, allocator)); in get_thread()
578 mythread_sync(coder->thr->mutex) { in get_thread()
579 coder->thr->state = THR_RUN; in get_thread()
580 coder->thr->in_size = 0; in get_thread()
581 coder->thr->outbuf = lzma_outq_get_buf(&coder->outq, NULL); in get_thread()
586 lzma_filters_free(coder->thr->filters, allocator); in get_thread()
587 memcpy(coder->thr->filters, coder->filters_cache, in get_thread()
588 sizeof(coder->filters_cache)); in get_thread()
589 coder->filters_cache[0].id = LZMA_VLI_UNKNOWN; in get_thread()
591 mythread_cond_signal(&coder->thr->cond); in get_thread()
599 stream_encode_in(lzma_stream_coder *coder, const lzma_allocator *allocator, in stream_encode_in() argument
604 || (coder->thr != NULL && action != LZMA_RUN)) { in stream_encode_in()
605 if (coder->thr == NULL) { in stream_encode_in()
607 const lzma_ret ret = get_thread(coder, allocator); in stream_encode_in()
608 if (coder->thr == NULL) in stream_encode_in()
613 size_t thr_in_size = coder->thr->in_size; in stream_encode_in()
614 lzma_bufcpy(in, in_pos, in_size, coder->thr->in, in stream_encode_in()
615 &thr_in_size, coder->block_size); in stream_encode_in()
623 const bool finish = thr_in_size == coder->block_size in stream_encode_in()
628 mythread_sync(coder->thr->mutex) { in stream_encode_in()
629 if (coder->thr->state == THR_IDLE) { in stream_encode_in()
637 coder->thr->in_size = thr_in_size; in stream_encode_in()
640 coder->thr->state = THR_FINISH; in stream_encode_in()
642 mythread_cond_signal(&coder->thr->cond); in stream_encode_in()
649 mythread_sync(coder->mutex) { in stream_encode_in()
650 ret = coder->thread_error; in stream_encode_in()
657 coder->thr = NULL; in stream_encode_in()
667 wait_for_work(lzma_stream_coder *coder, mythread_condtime *wait_abs, in wait_for_work() argument
670 if (coder->timeout != 0 && !*has_blocked) { in wait_for_work()
684 mythread_condtime_set(wait_abs, &coder->cond, coder->timeout); in wait_for_work()
689 mythread_sync(coder->mutex) { in wait_for_work()
697 while ((!has_input || coder->threads_free == NULL in wait_for_work()
698 || !lzma_outq_has_buf(&coder->outq)) in wait_for_work()
699 && !lzma_outq_is_readable(&coder->outq) in wait_for_work()
700 && coder->thread_error == LZMA_OK in wait_for_work()
702 if (coder->timeout != 0) in wait_for_work()
704 &coder->cond, &coder->mutex, in wait_for_work()
707 mythread_cond_wait(&coder->cond, in wait_for_work()
708 &coder->mutex); in wait_for_work()
722 lzma_stream_coder *coder = coder_ptr; in stream_encode_mt() local
724 switch (coder->sequence) { in stream_encode_mt()
726 lzma_bufcpy(coder->header, &coder->header_pos, in stream_encode_mt()
727 sizeof(coder->header), in stream_encode_mt()
729 if (coder->header_pos < sizeof(coder->header)) in stream_encode_mt()
732 coder->header_pos = 0; in stream_encode_mt()
733 coder->sequence = SEQ_BLOCK; in stream_encode_mt()
748 mythread_sync(coder->mutex) { in stream_encode_mt()
750 ret = coder->thread_error; in stream_encode_mt()
757 ret = lzma_outq_read(&coder->outq, allocator, in stream_encode_mt()
765 ret = lzma_index_append(coder->index, in stream_encode_mt()
769 threads_stop(coder, false); in stream_encode_mt()
782 threads_stop(coder, false); in stream_encode_mt()
787 ret = stream_encode_in(coder, allocator, in stream_encode_mt()
790 threads_stop(coder, false); in stream_encode_mt()
813 if (lzma_outq_is_empty(&coder->outq)) { in stream_encode_mt()
836 if (wait_for_work(coder, &wait_abs, &has_blocked, in stream_encode_mt()
844 &coder->index_encoder, allocator, in stream_encode_mt()
845 coder->index)); in stream_encode_mt()
846 coder->sequence = SEQ_INDEX; in stream_encode_mt()
852 coder->progress_out += lzma_index_size(coder->index) in stream_encode_mt()
861 const lzma_ret ret = coder->index_encoder.code( in stream_encode_mt()
862 coder->index_encoder.coder, allocator, in stream_encode_mt()
869 coder->stream_flags.backward_size in stream_encode_mt()
870 = lzma_index_size(coder->index); in stream_encode_mt()
871 if (lzma_stream_footer_encode(&coder->stream_flags, in stream_encode_mt()
872 coder->header) != LZMA_OK) in stream_encode_mt()
875 coder->sequence = SEQ_STREAM_FOOTER; in stream_encode_mt()
881 lzma_bufcpy(coder->header, &coder->header_pos, in stream_encode_mt()
882 sizeof(coder->header), in stream_encode_mt()
884 return coder->header_pos < sizeof(coder->header) in stream_encode_mt()
896 lzma_stream_coder *coder = coder_ptr; in stream_encoder_mt_end() local
899 threads_end(coder, allocator); in stream_encoder_mt_end()
900 lzma_outq_end(&coder->outq, allocator); in stream_encoder_mt_end()
902 lzma_filters_free(coder->filters, allocator); in stream_encoder_mt_end()
903 lzma_filters_free(coder->filters_cache, allocator); in stream_encoder_mt_end()
905 lzma_next_end(&coder->index_encoder, allocator); in stream_encoder_mt_end()
906 lzma_index_end(coder->index, allocator); in stream_encoder_mt_end()
908 mythread_cond_destroy(&coder->cond); in stream_encoder_mt_end()
909 mythread_mutex_destroy(&coder->mutex); in stream_encoder_mt_end()
911 lzma_free(coder, allocator); in stream_encoder_mt_end()
922 lzma_stream_coder *coder = coder_ptr; in stream_encoder_mt_update() local
926 if (coder->sequence > SEQ_BLOCK) in stream_encoder_mt_update()
931 if (coder->thr != NULL) in stream_encoder_mt_update()
945 lzma_filters_free(coder->filters, allocator); in stream_encoder_mt_update()
946 lzma_filters_free(coder->filters_cache, allocator); in stream_encoder_mt_update()
949 memcpy(coder->filters, temp, sizeof(temp)); in stream_encoder_mt_update()
1008 lzma_stream_coder *coder = coder_ptr; in get_progress() local
1012 mythread_sync(coder->mutex) { in get_progress()
1013 *progress_in = coder->progress_in; in get_progress()
1014 *progress_out = coder->progress_out; in get_progress()
1016 for (size_t i = 0; i < coder->threads_initialized; ++i) { in get_progress()
1017 mythread_sync(coder->threads[i].mutex) { in get_progress()
1018 *progress_in += coder->threads[i].progress_in; in get_progress()
1019 *progress_out += coder->threads[i] in get_progress()
1065 lzma_stream_coder *coder = next->coder; in stream_encoder_mt_init() local
1066 if (coder == NULL) { in stream_encoder_mt_init()
1067 coder = lzma_alloc(sizeof(lzma_stream_coder), allocator); in stream_encoder_mt_init()
1068 if (coder == NULL) in stream_encoder_mt_init()
1071 next->coder = coder; in stream_encoder_mt_init()
1077 if (mythread_mutex_init(&coder->mutex)) { in stream_encoder_mt_init()
1078 lzma_free(coder, allocator); in stream_encoder_mt_init()
1079 next->coder = NULL; in stream_encoder_mt_init()
1083 if (mythread_cond_init(&coder->cond)) { in stream_encoder_mt_init()
1084 mythread_mutex_destroy(&coder->mutex); in stream_encoder_mt_init()
1085 lzma_free(coder, allocator); in stream_encoder_mt_init()
1086 next->coder = NULL; in stream_encoder_mt_init()
1095 coder->filters[0].id = LZMA_VLI_UNKNOWN; in stream_encoder_mt_init()
1096 coder->filters_cache[0].id = LZMA_VLI_UNKNOWN; in stream_encoder_mt_init()
1097 coder->index_encoder = LZMA_NEXT_CODER_INIT; in stream_encoder_mt_init()
1098 coder->index = NULL; in stream_encoder_mt_init()
1099 memzero(&coder->outq, sizeof(coder->outq)); in stream_encoder_mt_init()
1100 coder->threads = NULL; in stream_encoder_mt_init()
1101 coder->threads_max = 0; in stream_encoder_mt_init()
1102 coder->threads_initialized = 0; in stream_encoder_mt_init()
1106 coder->sequence = SEQ_STREAM_HEADER; in stream_encoder_mt_init()
1107 coder->block_size = (size_t)(block_size); in stream_encoder_mt_init()
1108 coder->outbuf_alloc_size = (size_t)(outbuf_size_max); in stream_encoder_mt_init()
1109 coder->thread_error = LZMA_OK; in stream_encoder_mt_init()
1110 coder->thr = NULL; in stream_encoder_mt_init()
1114 if (coder->threads_max != options->threads) { in stream_encoder_mt_init()
1115 threads_end(coder, allocator); in stream_encoder_mt_init()
1117 coder->threads = NULL; in stream_encoder_mt_init()
1118 coder->threads_max = 0; in stream_encoder_mt_init()
1120 coder->threads_initialized = 0; in stream_encoder_mt_init()
1121 coder->threads_free = NULL; in stream_encoder_mt_init()
1123 coder->threads = lzma_alloc( in stream_encoder_mt_init()
1126 if (coder->threads == NULL) in stream_encoder_mt_init()
1129 coder->threads_max = options->threads; in stream_encoder_mt_init()
1133 threads_stop(coder, true); in stream_encoder_mt_init()
1137 return_if_error(lzma_outq_init(&coder->outq, allocator, in stream_encoder_mt_init()
1141 coder->timeout = options->timeout; in stream_encoder_mt_init()
1144 lzma_filters_free(coder->filters, allocator); in stream_encoder_mt_init()
1145 lzma_filters_free(coder->filters_cache, allocator); in stream_encoder_mt_init()
1149 filters, coder->filters, allocator)); in stream_encoder_mt_init()
1152 lzma_index_end(coder->index, allocator); in stream_encoder_mt_init()
1153 coder->index = lzma_index_init(allocator); in stream_encoder_mt_init()
1154 if (coder->index == NULL) in stream_encoder_mt_init()
1158 coder->stream_flags.version = 0; in stream_encoder_mt_init()
1159 coder->stream_flags.check = options->check; in stream_encoder_mt_init()
1161 &coder->stream_flags, coder->header)); in stream_encoder_mt_init()
1163 coder->header_pos = 0; in stream_encoder_mt_init()
1166 coder->progress_in = 0; in stream_encoder_mt_init()
1167 coder->progress_out = LZMA_STREAM_HEADER_SIZE; in stream_encoder_mt_init()