This simplifies the interface of the ngx_thread_read() function.
Additionally, most of the thread operations now explicitly set
file->thread_task, file->thread_handler and file->thread_ctx,
to facilitate use of thread operations in other places.
(Potential problems remain with sendfile in threads though - it uses
file->thread_handler as set in ngx_output_chain(), and it should not
be overwritten to an incompatible one.)
In collaboration with Valentin Bartenev.
ngx_int_t (*thread_handler)(ngx_thread_task_t *task,
ngx_file_t *file);
void *thread_ctx;
+ ngx_thread_task_t *thread_task;
#endif
#if (NGX_HAVE_FILE_AIO)
} else
#endif
#if (NGX_THREADS)
- if (src->file->thread_handler) {
- n = ngx_thread_read(&ctx->thread_task, src->file, dst->pos,
- (size_t) size, src->file_pos, ctx->pool);
+ if (ctx->thread_handler) {
+ src->file->thread_task = ctx->thread_task;
+ src->file->thread_handler = ctx->thread_handler;
+ src->file->thread_ctx = ctx->filter_ctx;
+
+ n = ngx_thread_read(src->file, dst->pos, (size_t) size,
+ src->file_pos, ctx->pool);
if (n == NGX_AGAIN) {
+ ctx->thread_task = src->file->thread_task;
return NGX_AGAIN;
}
#if (NGX_THREADS)
if (clcf->aio == NGX_HTTP_AIO_THREADS) {
+ c->file.thread_task = c->thread_task;
c->file.thread_handler = ngx_http_cache_thread_handler;
c->file.thread_ctx = r;
- n = ngx_thread_read(&c->thread_task, &c->file, c->buf->pos,
- c->body_start, 0, r->pool);
+ n = ngx_thread_read(&c->file, c->buf->pos, c->body_start, 0, r->pool);
+ c->thread_task = c->file.thread_task;
c->reading = (n == NGX_AGAIN);
return n;
ssize_t
-ngx_thread_read(ngx_thread_task_t **taskp, ngx_file_t *file, u_char *buf,
- size_t size, off_t offset, ngx_pool_t *pool)
+ngx_thread_read(ngx_file_t *file, u_char *buf, size_t size, off_t offset,
+ ngx_pool_t *pool)
{
ngx_thread_task_t *task;
ngx_thread_read_ctx_t *ctx;
"thread read: %d, %p, %uz, %O",
file->fd, buf, size, offset);
- task = *taskp;
+ task = file->thread_task;
if (task == NULL) {
task = ngx_thread_task_alloc(pool, sizeof(ngx_thread_read_ctx_t));
task->handler = ngx_thread_read_handler;
- *taskp = task;
+ file->thread_task = task;
}
ctx = task->ctx;
#endif
#if (NGX_THREADS)
-ssize_t ngx_thread_read(ngx_thread_task_t **taskp, ngx_file_t *file,
- u_char *buf, size_t size, off_t offset, ngx_pool_t *pool);
+ssize_t ngx_thread_read(ngx_file_t *file, u_char *buf, size_t size,
+ off_t offset, ngx_pool_t *pool);
#endif