Mercurial > hg > nginx
comparison src/os/unix/ngx_files.c @ 6441:9fd738b85fad
Threads: task pointer stored in ngx_file_t.
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.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 18 Mar 2016 06:43:52 +0300 |
parents | 3832b608dc8d |
children | 6e10518f95d8 |
comparison
equal
deleted
inserted
replaced
6440:248aa2757332 | 6441:9fd738b85fad |
---|---|
86 ngx_err_t err; | 86 ngx_err_t err; |
87 } ngx_thread_read_ctx_t; | 87 } ngx_thread_read_ctx_t; |
88 | 88 |
89 | 89 |
90 ssize_t | 90 ssize_t |
91 ngx_thread_read(ngx_thread_task_t **taskp, ngx_file_t *file, u_char *buf, | 91 ngx_thread_read(ngx_file_t *file, u_char *buf, size_t size, off_t offset, |
92 size_t size, off_t offset, ngx_pool_t *pool) | 92 ngx_pool_t *pool) |
93 { | 93 { |
94 ngx_thread_task_t *task; | 94 ngx_thread_task_t *task; |
95 ngx_thread_read_ctx_t *ctx; | 95 ngx_thread_read_ctx_t *ctx; |
96 | 96 |
97 ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0, | 97 ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0, |
98 "thread read: %d, %p, %uz, %O", | 98 "thread read: %d, %p, %uz, %O", |
99 file->fd, buf, size, offset); | 99 file->fd, buf, size, offset); |
100 | 100 |
101 task = *taskp; | 101 task = file->thread_task; |
102 | 102 |
103 if (task == NULL) { | 103 if (task == NULL) { |
104 task = ngx_thread_task_alloc(pool, sizeof(ngx_thread_read_ctx_t)); | 104 task = ngx_thread_task_alloc(pool, sizeof(ngx_thread_read_ctx_t)); |
105 if (task == NULL) { | 105 if (task == NULL) { |
106 return NGX_ERROR; | 106 return NGX_ERROR; |
107 } | 107 } |
108 | 108 |
109 task->handler = ngx_thread_read_handler; | 109 task->handler = ngx_thread_read_handler; |
110 | 110 |
111 *taskp = task; | 111 file->thread_task = task; |
112 } | 112 } |
113 | 113 |
114 ctx = task->ctx; | 114 ctx = task->ctx; |
115 | 115 |
116 if (task->event.complete) { | 116 if (task->event.complete) { |