comparison src/core/ngx_output_chain.c @ 6022:1fdba317ee6d

Added support for offloading read() in thread pools.
author Valentin Bartenev <vbart@nginx.com>
date Sat, 14 Mar 2015 17:37:25 +0300
parents ccad84a174e0
children 6ab301ddf469
comparison
equal deleted inserted replaced
6021:117c77b22db1 6022:1fdba317ee6d
48 off_t bsize; 48 off_t bsize;
49 ngx_int_t rc, last; 49 ngx_int_t rc, last;
50 ngx_chain_t *cl, *out, **last_out; 50 ngx_chain_t *cl, *out, **last_out;
51 51
52 if (ctx->in == NULL && ctx->busy == NULL 52 if (ctx->in == NULL && ctx->busy == NULL
53 #if (NGX_HAVE_FILE_AIO) 53 #if (NGX_HAVE_FILE_AIO || NGX_THREADS)
54 && !ctx->aio 54 && !ctx->aio
55 #endif 55 #endif
56 ) 56 )
57 { 57 {
58 /* 58 /*
87 last_out = &out; 87 last_out = &out;
88 last = NGX_NONE; 88 last = NGX_NONE;
89 89
90 for ( ;; ) { 90 for ( ;; ) {
91 91
92 #if (NGX_HAVE_FILE_AIO) 92 #if (NGX_HAVE_FILE_AIO || NGX_THREADS)
93 if (ctx->aio) { 93 if (ctx->aio) {
94 return NGX_AGAIN; 94 return NGX_AGAIN;
95 } 95 }
96 #endif 96 #endif
97 97
231 231
232 if (ngx_buf_special(buf)) { 232 if (ngx_buf_special(buf)) {
233 return 1; 233 return 1;
234 } 234 }
235 235
236 #if (NGX_THREADS)
237 if (buf->in_file) {
238 buf->file->thread_handler = ctx->thread_handler;
239 buf->file->thread_ctx = ctx->filter_ctx;
240 }
241 #endif
242
236 if (buf->in_file && buf->file->directio) { 243 if (buf->in_file && buf->file->directio) {
237 return 0; 244 return 0;
238 } 245 }
239 246
240 sendfile = ctx->sendfile; 247 sendfile = ctx->sendfile;
557 } 564 }
558 565
559 #endif 566 #endif
560 567
561 #if (NGX_HAVE_FILE_AIO) 568 #if (NGX_HAVE_FILE_AIO)
562
563 if (ctx->aio_handler) { 569 if (ctx->aio_handler) {
564 n = ngx_file_aio_read(src->file, dst->pos, (size_t) size, 570 n = ngx_file_aio_read(src->file, dst->pos, (size_t) size,
565 src->file_pos, ctx->pool); 571 src->file_pos, ctx->pool);
566 if (n == NGX_AGAIN) { 572 if (n == NGX_AGAIN) {
567 ctx->aio_handler(ctx, src->file); 573 ctx->aio_handler(ctx, src->file);
568 return NGX_AGAIN; 574 return NGX_AGAIN;
569 } 575 }
570 576
571 } else { 577 } else
578 #endif
579 #if (NGX_THREADS)
580 if (src->file->thread_handler) {
581 n = ngx_thread_read(&ctx->thread_task, src->file, dst->pos,
582 (size_t) size, src->file_pos, ctx->pool);
583 if (n == NGX_AGAIN) {
584 ctx->aio = 1;
585 return NGX_AGAIN;
586 }
587
588 } else
589 #endif
590 {
572 n = ngx_read_file(src->file, dst->pos, (size_t) size, 591 n = ngx_read_file(src->file, dst->pos, (size_t) size,
573 src->file_pos); 592 src->file_pos);
574 } 593 }
575 #else
576
577 n = ngx_read_file(src->file, dst->pos, (size_t) size, src->file_pos);
578
579 #endif
580 594
581 #if (NGX_HAVE_ALIGNED_DIRECTIO) 595 #if (NGX_HAVE_ALIGNED_DIRECTIO)
582 596
583 if (ctx->unaligned) { 597 if (ctx->unaligned) {
584 ngx_err_t err; 598 ngx_err_t err;