Skip to content

Commit

Permalink
reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
radkesvat committed Aug 5, 2024
1 parent 0a6a42e commit cc150f5
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 45 deletions.
46 changes: 22 additions & 24 deletions ww/buffer_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#include <string.h>
// #define BYPASS_BUFFERPOOL

// NOLINTBEGIN

#define MEMORY_PROFILE_SMALL (RAM_PROFILE >= kRamProfileM1Memory ? kRamProfileM1Memory : RAM_PROFILE)
#define MEMORY_PROFILE_SELECTED RAM_PROFILE

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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);
}
2 changes: 1 addition & 1 deletion ww/buffer_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion ww/generic_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions ww/pipe_line.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions ww/shiftbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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
Expand All @@ -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)
{
Expand All @@ -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);
Expand Down Expand Up @@ -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));

Expand Down
17 changes: 8 additions & 9 deletions ww/shiftbuffer.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "ww.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion ww/ww.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma once
#include "buffer_pool.h"
#include "hthread.h"
#include "managers/memory_manager.h"

Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit cc150f5

Please sign in to comment.