Lines Matching refs:thr

183 	worker_thread *thr;
202 worker_error(worker_thread *thr, lzma_ret ret)
207 mythread_sync(thr->coder->mutex) {
208 if (thr->coder->thread_error == LZMA_OK)
209 thr->coder->thread_error = ret;
211 mythread_cond_signal(&thr->coder->cond);
219 worker_encode(worker_thread *thr, size_t *out_pos, worker_state state)
221 assert(thr->progress_in == 0);
222 assert(thr->progress_out == 0);
225 thr->block_options = (lzma_block){
227 .check = thr->coder->stream_flags.check,
228 .compressed_size = thr->outbuf->allocated,
229 .uncompressed_size = thr->coder->block_size,
230 .filters = thr->filters,
237 lzma_ret ret = lzma_block_header_size(&thr->block_options);
239 worker_error(thr, ret);
244 ret = lzma_block_encoder_init(&thr->block_encoder,
245 thr->allocator, &thr->block_options);
247 worker_error(thr, ret);
254 *out_pos = thr->block_options.header_size;
255 const size_t out_size = thr->outbuf->allocated;
258 mythread_sync(thr->mutex) {
259 // Store in_pos and *out_pos into *thr so that
265 // later from thr->outbuf.
266 thr->progress_in = in_pos;
267 thr->progress_out = *out_pos;
269 while (in_size == thr->in_size
270 && thr->state == THR_RUN)
271 mythread_cond_wait(&thr->cond, &thr->mutex);
273 state = thr->state;
274 in_size = thr->in_size;
294 ret = thr->block_encoder.code(
295 thr->block_encoder.coder, thr->allocator,
296 thr->in, &in_pos, in_limit, thr->outbuf->buf,
307 ret = lzma_block_header_encode(&thr->block_options,
308 thr->outbuf->buf);
310 worker_error(thr, ret);
321 mythread_sync(thr->mutex) {
322 while (thr->state == THR_RUN)
323 mythread_cond_wait(&thr->cond, &thr->mutex);
325 state = thr->state;
326 in_size = thr->in_size;
334 ret = lzma_block_uncomp_encode(&thr->block_options,
335 thr->in, in_size, thr->outbuf->buf,
340 worker_error(thr, LZMA_PROG_ERROR);
347 worker_error(thr, ret);
353 thr->outbuf->unpadded_size
354 = lzma_block_unpadded_size(&thr->block_options);
355 assert(thr->outbuf->unpadded_size != 0);
356 thr->outbuf->uncompressed_size = thr->block_options.uncompressed_size;
365 worker_thread *thr = thr_ptr;
370 mythread_sync(thr->mutex) {
374 if (thr->state == THR_STOP) {
375 thr->state = THR_IDLE;
376 mythread_cond_signal(&thr->cond);
379 state = thr->state;
383 mythread_cond_wait(&thr->cond, &thr->mutex);
393 state = worker_encode(thr, &out_pos, state);
401 mythread_sync(thr->mutex) {
402 if (thr->state != THR_EXIT) {
403 thr->state = THR_IDLE;
404 mythread_cond_signal(&thr->cond);
408 mythread_sync(thr->coder->mutex) {
412 thr->outbuf->pos = out_pos;
413 thr->outbuf->finished = true;
417 thr->coder->progress_in
418 += thr->outbuf->uncompressed_size;
419 thr->coder->progress_out += out_pos;
420 thr->progress_in = 0;
421 thr->progress_out = 0;
424 thr->next = thr->coder->threads_free;
425 thr->coder->threads_free = thr;
427 mythread_cond_signal(&thr->coder->cond);
432 lzma_filters_free(thr->filters, thr->allocator);
434 mythread_mutex_destroy(&thr->mutex);
435 mythread_cond_destroy(&thr->cond);
437 lzma_next_end(&thr->block_encoder, thr->allocator);
438 lzma_free(thr->in, thr->allocator);
499 worker_thread *thr = &coder->threads[coder->threads_initialized];
501 thr->in = lzma_alloc(coder->block_size, allocator);
502 if (thr->in == NULL)
505 if (mythread_mutex_init(&thr->mutex))
508 if (mythread_cond_init(&thr->cond))
511 thr->state = THR_IDLE;
512 thr->allocator = allocator;
513 thr->coder = coder;
514 thr->progress_in = 0;
515 thr->progress_out = 0;
516 thr->block_encoder = LZMA_NEXT_CODER_INIT;
517 thr->filters[0].id = LZMA_VLI_UNKNOWN;
519 if (mythread_create(&thr->thread_id, &worker_start, thr))
523 coder->thr = thr;
528 mythread_cond_destroy(&thr->cond);
531 mythread_mutex_destroy(&thr->mutex);
534 lzma_free(thr->in, allocator);
562 coder->thr = coder->threads_free;
567 if (coder->thr == NULL) {
578 mythread_sync(coder->thr->mutex) {
579 coder->thr->state = THR_RUN;
580 coder->thr->in_size = 0;
581 coder->thr->outbuf = lzma_outq_get_buf(&coder->outq, NULL);
586 lzma_filters_free(coder->thr->filters, allocator);
587 memcpy(coder->thr->filters, coder->filters_cache,
591 mythread_cond_signal(&coder->thr->cond);
604 || (coder->thr != NULL && action != LZMA_RUN)) {
605 if (coder->thr == NULL) {
608 if (coder->thr == NULL)
613 size_t thr_in_size = coder->thr->in_size;
614 lzma_bufcpy(in, in_pos, in_size, coder->thr->in,
628 mythread_sync(coder->thr->mutex) {
629 if (coder->thr->state == THR_IDLE) {
637 coder->thr->in_size = thr_in_size;
640 coder->thr->state = THR_FINISH;
642 mythread_cond_signal(&coder->thr->cond);
657 coder->thr = NULL;
931 if (coder->thr != NULL)
1110 coder->thr = NULL;