diff options
-rw-r--r-- | src/nxt_buf.c | 19 | ||||
-rw-r--r-- | src/nxt_buf.h | 23 | ||||
-rw-r--r-- | src/nxt_event_engine.c | 59 | ||||
-rw-r--r-- | src/nxt_event_engine.h | 4 |
4 files changed, 83 insertions, 22 deletions
diff --git a/src/nxt_buf.c b/src/nxt_buf.c index 91846e4d..2d52efca 100644 --- a/src/nxt_buf.c +++ b/src/nxt_buf.c @@ -207,6 +207,13 @@ nxt_buf_completion(nxt_task_t *task, void *obj, void *data) mp = b->data; nxt_mp_free(mp, b); + nxt_buf_parent_completion(task, parent); +} + + +void +nxt_buf_parent_completion(nxt_task_t *task, nxt_buf_t *parent) +{ if (parent != NULL) { nxt_debug(task, "parent retain:%uD", parent->retain); @@ -272,17 +279,7 @@ nxt_buf_ts_completion(nxt_task_t *task, void *obj, void *data) nxt_mp_free(mp, b); nxt_mp_release(mp); - if (parent != NULL) { - nxt_debug(task, "parent retain:%uD", parent->retain); - - parent->retain--; - - if (parent->retain == 0) { - parent->mem.pos = parent->mem.free; - - parent->completion_handler(task, parent, parent->parent); - } - } + nxt_buf_parent_completion(task, parent); } diff --git a/src/nxt_buf.h b/src/nxt_buf.h index 9c22d650..25e8499a 100644 --- a/src/nxt_buf.h +++ b/src/nxt_buf.h @@ -77,17 +77,17 @@ struct nxt_buf_s { uint32_t retain; - uint8_t is_file; /* 1 bit */ - - uint16_t is_mmap:1; - uint16_t is_port_mmap:1; - - uint16_t is_sync:1; - uint16_t is_nobuf:1; - uint16_t is_flush:1; - uint16_t is_last:1; - uint16_t is_port_mmap_sent:1; - uint16_t is_ts:1; + uint8_t cache_hint; + + uint8_t is_file:1; + uint8_t is_mmap:1; + uint8_t is_port_mmap:1; + uint8_t is_sync:1; + uint8_t is_nobuf:1; + uint8_t is_flush:1; + uint8_t is_last:1; + uint8_t is_port_mmap_sent:1; + uint8_t is_ts:1; nxt_buf_mem_t mem; @@ -250,6 +250,7 @@ NXT_EXPORT nxt_buf_t *nxt_buf_sync_alloc(nxt_mp_t *mp, nxt_uint_t flags); NXT_EXPORT nxt_int_t nxt_buf_ts_handle(nxt_task_t *task, void *obj, void *data); +NXT_EXPORT void nxt_buf_parent_completion(nxt_task_t *task, nxt_buf_t *parent); NXT_EXPORT nxt_buf_t *nxt_buf_make_plain(nxt_mp_t *mp, nxt_buf_t *src, size_t size); diff --git a/src/nxt_event_engine.c b/src/nxt_event_engine.c index c2c66c82..c46158b7 100644 --- a/src/nxt_event_engine.c +++ b/src/nxt_event_engine.c @@ -676,6 +676,65 @@ done: } +void * +nxt_event_engine_buf_mem_alloc(nxt_event_engine_t *engine, size_t size) +{ + nxt_buf_t *b; + uint8_t hint; + + hint = NXT_EVENT_ENGINE_NO_MEM_HINT; + + b = nxt_event_engine_mem_alloc(engine, &hint, NXT_BUF_MEM_SIZE + size); + if (nxt_slow_path(b == NULL)) { + return NULL; + } + + nxt_memzero(b, NXT_BUF_MEM_SIZE); + + b->cache_hint = hint; + b->data = engine; + b->completion_handler = nxt_event_engine_buf_mem_completion; + + if (size != 0) { + b->mem.start = nxt_pointer_to(b, NXT_BUF_MEM_SIZE); + b->mem.pos = b->mem.start; + b->mem.free = b->mem.start; + b->mem.end = b->mem.start + size; + } + + return b; +} + + +void +nxt_event_engine_buf_mem_free(nxt_event_engine_t *engine, nxt_buf_t *b) +{ + size_t size; + + size = NXT_BUF_MEM_SIZE + nxt_buf_mem_size(&b->mem); + + nxt_event_engine_mem_free(engine, b->cache_hint, b, size); +} + + +void +nxt_event_engine_buf_mem_completion(nxt_task_t *task, void *obj, void *data) +{ + nxt_event_engine_t *engine; + nxt_buf_t *b, *parent; + + b = obj; + parent = data; + + nxt_debug(task, "buf completion: %p %p", b, b->mem.start); + + engine = b->data; + nxt_event_engine_buf_mem_free(engine, b); + + nxt_buf_parent_completion(task, parent); +} + + #if (NXT_DEBUG) void nxt_event_engine_thread_adopt(nxt_event_engine_t *engine) diff --git a/src/nxt_event_engine.h b/src/nxt_event_engine.h index 0c349f7e..6b05d510 100644 --- a/src/nxt_event_engine.h +++ b/src/nxt_event_engine.h @@ -520,6 +520,10 @@ void *nxt_event_engine_mem_alloc(nxt_event_engine_t *engine, uint8_t *hint, size_t size); void nxt_event_engine_mem_free(nxt_event_engine_t *engine, uint8_t hint, void *p, size_t size); +void *nxt_event_engine_buf_mem_alloc(nxt_event_engine_t *engine, size_t size); +void nxt_event_engine_buf_mem_free(nxt_event_engine_t *engine, nxt_buf_t *b); +void nxt_event_engine_buf_mem_completion(nxt_task_t *task, void *obj, + void *data); nxt_inline nxt_event_engine_t * |