diff --git a/ww/buffer_pool.c b/ww/buffer_pool.c index c49d4ca..0785b7b 100644 --- a/ww/buffer_pool.c +++ b/ww/buffer_pool.c @@ -11,8 +11,6 @@ #include // #define BYPASS_BUFFERPOOL -// NOLINTBEGIN - #define MEMORY_PROFILE_SMALL (RAM_PROFILE >= kRamProfileM1Memory ? kRamProfileM1Memory : RAM_PROFILE) #define MEMORY_PROFILE_SELECTED RAM_PROFILE @@ -25,13 +23,13 @@ struct buffer_pool_s { - uint16_t cap; - uint16_t free_threshold; - unsigned int large_buffers_len; - unsigned int small_buffers_len; - unsigned int large_buffers_size; - unsigned int small_buffers_size; - struct generic_pool_s *shift_buffer_pool; + uint16_t cap; + uint16_t free_threshold; + unsigned int large_buffers_len; + unsigned int small_buffers_len; + unsigned int large_buffers_size; + unsigned int small_buffers_size; + generic_pool_t *shift_buffer_pool; #if defined(DEBUG) && defined(BUFFER_POOL_DEBUG) atomic_size_t in_use; #endif @@ -227,8 +225,8 @@ shift_buffer_t *appendBufferMerge(buffer_pool_t *pool, shift_buffer_t *restrict return b2; } -static buffer_pool_t *allocBufferPool(struct master_pool_s *mp_large, struct master_pool_s *mp_small,struct generic_pool_s *sb_pool, - unsigned int bufcount, unsigned int large_buffer_size, +static buffer_pool_t *allocBufferPool(struct master_pool_s *mp_large, struct master_pool_s *mp_small, + generic_pool_t *sb_pool, unsigned int bufcount, unsigned int large_buffer_size, unsigned int small_buffer_size) { // stop using pool if you want less, simply uncomment lines in popbuffer and reuseBuffer @@ -241,19 +239,20 @@ static buffer_pool_t *allocBufferPool(struct master_pool_s *mp_large, struct mas buffer_pool_t *ptr_pool = globalMalloc(sizeof(buffer_pool_t)); - *ptr_pool = (buffer_pool_t) {.cap = bufcount, - .large_buffers_size = large_buffer_size, - .small_buffers_size = small_buffer_size, - .free_threshold = max(bufcount / 2, (bufcount * 2) / 3), - .shift_buffer_pool = sb_pool, + *ptr_pool = (buffer_pool_t) { + .cap = bufcount, + .large_buffers_size = large_buffer_size, + .small_buffers_size = small_buffer_size, + .free_threshold = max(bufcount / 2, (bufcount * 2) / 3), + .shift_buffer_pool = sb_pool, #if defined(DEBUG) && defined(BUFFER_POOL_DEBUG) - .in_use = 0, + .in_use = 0, #endif - .large_buffers_mp = mp_large, - .large_buffers = globalMalloc(container_len), - .small_buffers_mp = mp_small, - .small_buffers = globalMalloc(container_len), - }; + .large_buffers_mp = mp_large, + .large_buffers = globalMalloc(container_len), + .small_buffers_mp = mp_small, + .small_buffers = globalMalloc(container_len), + }; installMasterPoolAllocCallbacks(ptr_pool->large_buffers_mp, createLargeBufHandle, destroyLargeBufHandle); installMasterPoolAllocCallbacks(ptr_pool->small_buffers_mp, createSmallBufHandle, destroySmallBufHandle); @@ -267,8 +266,7 @@ static buffer_pool_t *allocBufferPool(struct master_pool_s *mp_large, struct mas return ptr_pool; } -buffer_pool_t *createBufferPool(struct master_pool_s *mp_large, struct master_pool_s *mp_small, - struct generic_pool_s *sb_pool) +buffer_pool_t *createBufferPool(struct master_pool_s *mp_large, struct master_pool_s *mp_small, generic_pool_t *sb_pool) { return allocBufferPool(mp_large, mp_small, sb_pool, BUFFERPOOL_CONTAINER_LEN, BUFFER_SIZE, SMALL_BUFSIZE); } diff --git a/ww/buffer_pool.h b/ww/buffer_pool.h index 033cd06..4e10791 100644 --- a/ww/buffer_pool.h +++ b/ww/buffer_pool.h @@ -30,7 +30,7 @@ typedef struct buffer_pool_s buffer_pool_t; buffer_pool_t *createBufferPool(struct master_pool_s *mp_large, struct master_pool_s *mp_small, - struct generic_pool_s *sb_pool); + generic_pool_t *sb_pool); shift_buffer_t *popBuffer(buffer_pool_t *pool); shift_buffer_t *popSmallBuffer(buffer_pool_t *pool); void reuseBuffer(buffer_pool_t *pool, shift_buffer_t *b); diff --git a/ww/generic_pool.h b/ww/generic_pool.h index e15f688..1964de6 100644 --- a/ww/generic_pool.h +++ b/ww/generic_pool.h @@ -24,6 +24,8 @@ // #define BYPASS_POOL struct generic_pool_s; +typedef struct generic_pool_s generic_pool_t; + // struct pool_item_s; // void typedef void pool_item_t; @@ -60,7 +62,6 @@ struct generic_pool_s GENERIC_POOL_FIELDS }; -typedef struct generic_pool_s generic_pool_t; void poolReCharge(generic_pool_t *pool); void poolShrink(generic_pool_t *pool); diff --git a/ww/pipe_line.h b/ww/pipe_line.h index 59bb426..5d50fbd 100644 --- a/ww/pipe_line.h +++ b/ww/pipe_line.h @@ -45,8 +45,8 @@ typedef void (*PipeLineFlowRoutine)(struct tunnel_s *, struct context_s *, struc typedef struct pipe_line_s pipe_line_t; -pool_item_t *allocPipeLineMsgPoolHandle(struct generic_pool_s *pool); -void destroyPipeLineMsgPoolHandle(struct generic_pool_s *pool, pool_item_t *item); +pool_item_t *allocPipeLineMsgPoolHandle(generic_pool_t *pool); +void destroyPipeLineMsgPoolHandle(generic_pool_t *pool, pool_item_t *item); void pipeOnUpLinePaused(void *state); void pipeOnUpLineResumed(void *state); void pipeOnDownLineResumed(void *state); diff --git a/ww/shiftbuffer.c b/ww/shiftbuffer.c index 0e2188e..4229b99 100644 --- a/ww/shiftbuffer.c +++ b/ww/shiftbuffer.c @@ -12,7 +12,7 @@ #define REFC_SIZE sizeof(shiftbuffer_refc_t) -pool_item_t *allocShiftBufferPoolHandle(struct generic_pool_s *pool) +pool_item_t *allocShiftBufferPoolHandle(generic_pool_t *pool) { (void) pool; shift_buffer_t *self = globalMalloc(sizeof(shift_buffer_t)); @@ -21,13 +21,13 @@ pool_item_t *allocShiftBufferPoolHandle(struct generic_pool_s *pool) return self; } -void destroyShiftBufferPoolHandle(struct generic_pool_s *pool, pool_item_t *item) +void destroyShiftBufferPoolHandle(generic_pool_t *pool, pool_item_t *item) { (void) pool; globalFree((shift_buffer_t *) item); } -void destroyShiftBuffer(struct generic_pool_s *pool, shift_buffer_t *self) +void destroyShiftBuffer(generic_pool_t *pool, shift_buffer_t *self) { assert(*(self->refc) > 0); // if its a shallow then the underlying buffer survives @@ -44,7 +44,7 @@ void destroyShiftBuffer(struct generic_pool_s *pool, shift_buffer_t *self) } } -shift_buffer_t *newShiftBuffer(struct generic_pool_s *pool, unsigned int pre_cap) // NOLINT +shift_buffer_t *newShiftBuffer(generic_pool_t *pool, unsigned int pre_cap) // NOLINT { if (pre_cap != 0 && pre_cap % 16 != 0) { @@ -68,7 +68,7 @@ shift_buffer_t *newShiftBuffer(struct generic_pool_s *pool, unsigned int pre_cap return self; } -shift_buffer_t *newShallowShiftBuffer(struct generic_pool_s *pool, shift_buffer_t *owner) +shift_buffer_t *newShallowShiftBuffer(generic_pool_t *pool, shift_buffer_t *owner) { *(owner->refc) += 1; shift_buffer_t *shallow = (shift_buffer_t *) popPoolItem(pool); @@ -203,14 +203,14 @@ void sliceBufferTo(shift_buffer_t *restrict dest, shift_buffer_t *restrict sourc setLen(dest, bytes); } -shift_buffer_t *sliceBuffer(struct generic_pool_s *pool, shift_buffer_t *const self, const unsigned int bytes) +shift_buffer_t *sliceBuffer(generic_pool_t *pool, shift_buffer_t *const self, const unsigned int bytes) { shift_buffer_t *newbuf = newShiftBuffer(pool, self->full_cap - (LEFTPADDING + RIGHTPADDING)); sliceBufferTo(newbuf, self, bytes); return newbuf; } -shift_buffer_t *shallowSliceBuffer(struct generic_pool_s *pool, shift_buffer_t *self, const unsigned int bytes) +shift_buffer_t *shallowSliceBuffer(generic_pool_t *pool, shift_buffer_t *self, const unsigned int bytes) { assert(bytes <= bufLen(self)); diff --git a/ww/shiftbuffer.h b/ww/shiftbuffer.h index f95dd4b..0108161 100644 --- a/ww/shiftbuffer.h +++ b/ww/shiftbuffer.h @@ -1,5 +1,6 @@ #pragma once +#include "ww.h" #include #include #include @@ -41,21 +42,19 @@ struct shift_buffer_s typedef struct shift_buffer_s shift_buffer_t; -struct generic_pool_s; +void *allocShiftBufferPoolHandle(generic_pool_t *pool); +void destroyShiftBufferPoolHandle(generic_pool_t *pool, void *item); -void *allocShiftBufferPoolHandle(struct generic_pool_s *pool); -void destroyShiftBufferPoolHandle(struct generic_pool_s *pool, void *item); - -shift_buffer_t *newShiftBuffer(struct generic_pool_s *pool, unsigned int pre_cap); -shift_buffer_t *newShallowShiftBuffer(struct generic_pool_s *pool, shift_buffer_t *owner); -void destroyShiftBuffer(struct generic_pool_s *pool, shift_buffer_t *self); +shift_buffer_t *newShiftBuffer(generic_pool_t *pool, unsigned int pre_cap); +shift_buffer_t *newShallowShiftBuffer(generic_pool_t *pool, shift_buffer_t *owner); +void destroyShiftBuffer(generic_pool_t *pool, shift_buffer_t *self); void reset(shift_buffer_t *self, unsigned int cap); void unShallow(shift_buffer_t *self); void expand(shift_buffer_t *self, unsigned int increase); void concatBuffer(shift_buffer_t *restrict root, const shift_buffer_t *restrict buf); void sliceBufferTo(shift_buffer_t *restrict dest, shift_buffer_t *restrict source, unsigned int bytes); -shift_buffer_t *sliceBuffer(struct generic_pool_s *pool, shift_buffer_t *self, unsigned int bytes); -shift_buffer_t *shallowSliceBuffer(struct generic_pool_s *pool, shift_buffer_t *self, unsigned int bytes); +shift_buffer_t *sliceBuffer(generic_pool_t *pool, shift_buffer_t *self, unsigned int bytes); +shift_buffer_t *shallowSliceBuffer(generic_pool_t *pool, shift_buffer_t *self, unsigned int bytes); static inline bool isShallow(shift_buffer_t *self) { diff --git a/ww/ww.h b/ww/ww.h index 2ba8e56..aa4906a 100644 --- a/ww/ww.h +++ b/ww/ww.h @@ -1,5 +1,4 @@ #pragma once -#include "buffer_pool.h" #include "hthread.h" #include "managers/memory_manager.h" @@ -90,6 +89,7 @@ void createWW(ww_construction_data_t data); _Noreturn void runMainThread(void); typedef uint8_t tid_t; +typedef struct generic_pool_s generic_pool_t; typedef struct worker_s {