Lines Matching refs:thr

163 	worker_thread *thr;
182 worker_error(worker_thread *thr, lzma_ret ret)
187 mythread_sync(thr->coder->mutex) {
188 if (thr->coder->thread_error == LZMA_OK)
189 thr->coder->thread_error = ret;
191 mythread_cond_signal(&thr->coder->cond);
199 worker_encode(worker_thread *thr, worker_state state)
201 assert(thr->progress_in == 0);
202 assert(thr->progress_out == 0);
205 thr->block_options = (lzma_block){
207 .check = thr->coder->stream_flags.check,
208 .compressed_size = thr->coder->outq.buf_size_max,
209 .uncompressed_size = thr->coder->block_size,
213 .filters = thr->coder->filters,
220 lzma_ret ret = lzma_block_header_size(&thr->block_options);
222 worker_error(thr, ret);
227 ret = lzma_block_encoder_init(&thr->block_encoder,
228 thr->allocator, &thr->block_options);
230 worker_error(thr, ret);
237 thr->outbuf->size = thr->block_options.header_size;
238 const size_t out_size = thr->coder->outq.buf_size_max;
241 mythread_sync(thr->mutex) {
242 // Store in_pos and out_pos into *thr so that
248 // later from thr->outbuf.
249 thr->progress_in = in_pos;
250 thr->progress_out = thr->outbuf->size;
252 while (in_size == thr->in_size
253 && thr->state == THR_RUN)
254 mythread_cond_wait(&thr->cond, &thr->mutex);
256 state = thr->state;
257 in_size = thr->in_size;
277 ret = thr->block_encoder.code(
278 thr->block_encoder.coder, thr->allocator,
279 thr->in, &in_pos, in_limit, thr->outbuf->buf,
280 &thr->outbuf->size, out_size, action);
281 } while (ret == LZMA_OK && thr->outbuf->size < out_size);
290 ret = lzma_block_header_encode(&thr->block_options,
291 thr->outbuf->buf);
293 worker_error(thr, ret);
304 mythread_sync(thr->mutex) {
305 while (thr->state == THR_RUN)
306 mythread_cond_wait(&thr->cond, &thr->mutex);
308 state = thr->state;
309 in_size = thr->in_size;
316 thr->outbuf->size = 0;
317 ret = lzma_block_uncomp_encode(&thr->block_options,
318 thr->in, in_size, thr->outbuf->buf,
319 &thr->outbuf->size, out_size);
323 worker_error(thr, LZMA_PROG_ERROR);
330 worker_error(thr, ret);
336 thr->outbuf->unpadded_size
337 = lzma_block_unpadded_size(&thr->block_options);
338 assert(thr->outbuf->unpadded_size != 0);
339 thr->outbuf->uncompressed_size = thr->block_options.uncompressed_size;
348 worker_thread *thr = thr_ptr;
353 mythread_sync(thr->mutex) {
357 if (thr->state == THR_STOP) {
358 thr->state = THR_IDLE;
359 mythread_cond_signal(&thr->cond);
362 state = thr->state;
366 mythread_cond_wait(&thr->cond, &thr->mutex);
374 state = worker_encode(thr, state);
382 mythread_sync(thr->mutex) {
383 if (thr->state != THR_EXIT) {
384 thr->state = THR_IDLE;
385 mythread_cond_signal(&thr->cond);
389 mythread_sync(thr->coder->mutex) {
392 thr->outbuf->finished = state == THR_FINISH;
395 thr->coder->progress_in
396 += thr->outbuf->uncompressed_size;
397 thr->coder->progress_out += thr->outbuf->size;
398 thr->progress_in = 0;
399 thr->progress_out = 0;
402 thr->next = thr->coder->threads_free;
403 thr->coder->threads_free = thr;
405 mythread_cond_signal(&thr->coder->cond);
410 mythread_mutex_destroy(&thr->mutex);
411 mythread_cond_destroy(&thr->cond);
413 lzma_next_end(&thr->block_encoder, thr->allocator);
414 lzma_free(thr->in, thr->allocator);
475 worker_thread *thr = &coder->threads[coder->threads_initialized];
477 thr->in = lzma_alloc(coder->block_size, allocator);
478 if (thr->in == NULL)
481 if (mythread_mutex_init(&thr->mutex))
484 if (mythread_cond_init(&thr->cond))
487 thr->state = THR_IDLE;
488 thr->allocator = allocator;
489 thr->coder = coder;
490 thr->progress_in = 0;
491 thr->progress_out = 0;
492 thr->block_encoder = LZMA_NEXT_CODER_INIT;
494 if (mythread_create(&thr->thread_id, &worker_start, thr))
498 coder->thr = thr;
503 mythread_cond_destroy(&thr->cond);
506 mythread_mutex_destroy(&thr->mutex);
509 lzma_free(thr->in, allocator);
525 coder->thr = coder->threads_free;
530 if (coder->thr == NULL) {
541 mythread_sync(coder->thr->mutex) {
542 coder->thr->state = THR_RUN;
543 coder->thr->in_size = 0;
544 coder->thr->outbuf = lzma_outq_get_buf(&coder->outq);
545 mythread_cond_signal(&coder->thr->cond);
558 || (coder->thr != NULL && action != LZMA_RUN)) {
559 if (coder->thr == NULL) {
562 if (coder->thr == NULL)
567 size_t thr_in_size = coder->thr->in_size;
568 lzma_bufcpy(in, in_pos, in_size, coder->thr->in,
582 mythread_sync(coder->thr->mutex) {
583 if (coder->thr->state == THR_IDLE) {
591 coder->thr->in_size = thr_in_size;
594 coder->thr->state = THR_FINISH;
596 mythread_cond_signal(&coder->thr->cond);
611 coder->thr = NULL;
1016 coder->thr = NULL;