Skip to content

Commit

Permalink
fix logging when POOL_DEBUG is defined
Browse files Browse the repository at this point in the history
  • Loading branch information
radkesvat committed Jun 14, 2024
1 parent d1fe033 commit 1599086
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 38 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ option(INCLUDE_OPENSSL_SERVER "link OpenSSlServer staticly to the core" TRUE)
option(INCLUDE_OPENSSL_CLIENT "link OpenSSLClient staticly to the core" TRUE)
option(INCLUDE_TROJAN_AUTH_SERVER "link TrojanAuthServer staticly to the core" TRUE)
option(INCLUDE_TROJAN_SOCKS_SERVER "link TrojanSocksServer staticly to the core" TRUE)
option(INCLUDE_WOLFSSL_SERVER "link WolfSSLServer staticly to the core" FALSE) # temporarely disabled for compile speed
option(INCLUDE_WOLFSSL_CLIENT "link WolfSSLClient staticly to the core" FALSE) # temporarely disabled for compile speed
option(INCLUDE_WOLFSSL_SERVER "link WolfSSLServer staticly to the core" TRUE) # temporarely disabled for compile speed
option(INCLUDE_WOLFSSL_CLIENT "link WolfSSLClient staticly to the core" TRUE) # temporarely disabled for compile speed
option(INCLUDE_BORINGSSL_SERVER "link BoringSSLServer staticly to the core" FALSE) #conflicts with openssl/noprefix ?
option(INCLUDE_HTTP2_SERVER "link Http2Server staticly to the core" TRUE)
option(INCLUDE_HTTP2_CLIENT "link Http2Client staticly to the core" TRUE)
Expand Down
38 changes: 35 additions & 3 deletions ww/generic_pool.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,46 @@
#include "generic_pool.h"
#include "utils/mathutils.h"
#include "ww.h"

#ifdef POOL_DEBUG
#include "loggers/network_logger.h"
#endif
#define GENERIC_POOL_DEFAULT_WIDTH ((unsigned long) ((ram_profile)))

extern void poolReCharge(generic_pool_t *pool);
extern void poolShrink(generic_pool_t *pool);
extern pool_item_t *popPoolItem(generic_pool_t *pool);
extern void reusePoolItem(generic_pool_t *pool, pool_item_t *b);

void poolReCharge(generic_pool_t *pool)
{
const size_t increase = ((pool->cap - pool->len) < (pool->cap) / 2 ? (pool->cap - pool->len) : (pool->cap / 2));

for (size_t i = pool->len; i < (pool->len + increase); i++)
{
pool->available[i] = pool->create_item_handle(pool);
}
pool->len += increase;
#if defined(DEBUG) && defined(POOL_DEBUG)
hlogd("BufferPool: allocated %d new buffers, %zu are in use", increase, pool->in_use);
#endif
}

void poolShrink(generic_pool_t *pool)
{
const size_t decrease = (pool->len < (pool->cap / 2) ? pool->len : (pool->cap / 2));

for (size_t i = pool->len - decrease; i < pool->len; i++)
{
pool->destroy_item_handle(pool, pool->available[i]);
}
pool->len -= decrease;

#if defined(DEBUG) && defined(POOL_DEBUG)
hlogd("BufferPool: freed %d buffers, %zu are in use", decrease, pool->in_use);
#endif
#ifdef OS_LINUX
// malloc_trim(0);
#endif
}

static void poolFirstCharge(generic_pool_t *pool)
{
pool->len = pool->cap / 2;
Expand Down
38 changes: 5 additions & 33 deletions ww/generic_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
*/

#define POOL_DEBUG
#define BYPASS_POOL
// #define POOL_DEBUG
// #define BYPASS_POOL


struct generic_pool_s;

Expand Down Expand Up @@ -59,37 +60,8 @@ struct generic_pool_s

typedef struct generic_pool_s generic_pool_t;

inline void poolReCharge(generic_pool_t *pool)
{
const size_t increase = ((pool->cap - pool->len) < (pool->cap) / 2 ? (pool->cap - pool->len) : (pool->cap / 2));

for (size_t i = pool->len; i < (pool->len + increase); i++)
{
pool->available[i] = pool->create_item_handle(pool);
}
pool->len += increase;
#if defined(DEBUG) && defined(POOL_DEBUG)
LOGD("BufferPool: allocated %d new buffers, %zu are in use", increase, pool->in_use);
#endif
}

inline void poolShrink(generic_pool_t *pool)
{
const size_t decrease = (pool->len < (pool->cap / 2) ? pool->len : (pool->cap / 2));

for (size_t i = pool->len - decrease; i < pool->len; i++)
{
pool->destroy_item_handle(pool, pool->available[i]);
}
pool->len -= decrease;

#if defined(DEBUG) && defined(POOL_DEBUG)
LOGD("BufferPool: freed %d buffers, %zu are in use", decrease, pool->in_use);
#endif
#ifdef OS_LINUX
// malloc_trim(0);
#endif
}
void poolReCharge(generic_pool_t *pool);
void poolShrink(generic_pool_t *pool);

inline pool_item_t *popPoolItem(generic_pool_t *pool)
{
Expand Down

0 comments on commit 1599086

Please sign in to comment.