Skip to content

Commit

Permalink
Fix data race reported by ThreadSanitizer in caching pool (#3897)
Browse files Browse the repository at this point in the history
  • Loading branch information
nanangizz authored Mar 26, 2024
1 parent c0de1a4 commit 478aeb9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
4 changes: 4 additions & 0 deletions pjlib/include/pj/pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -849,12 +849,16 @@ struct pj_caching_pool

/**
* Total size of memory currently used by application.
*
* This field is deprecated.
*/
pj_size_t used_size;

/**
* The maximum size of memory used by application throughout the life
* of the caching pool.
*
* This field is deprecated.
*/
pj_size_t peak_used_size;

Expand Down
8 changes: 6 additions & 2 deletions pjlib/src/pj/pool_caching.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,12 @@ PJ_DEF(void) pj_caching_pool_init( pj_caching_pool *cp,
cp->factory.create_pool = &cpool_create_pool;
cp->factory.release_pool = &cpool_release_pool;
cp->factory.dump_status = &cpool_dump_status;
cp->factory.on_block_alloc = &cpool_on_block_alloc;
cp->factory.on_block_free = &cpool_on_block_free;

/* Deprecated, these callbacks are only used for updating cp.used_size &
* cp.peak_used_size which are no longer used.
*/
//cp->factory.on_block_alloc = &cpool_on_block_alloc;
//cp->factory.on_block_free = &cpool_on_block_free;

pool = pj_pool_create_on_buf("cachingpool", cp->pool_buf, sizeof(cp->pool_buf));
status = pj_lock_create_simple_mutex(pool, "cachingpool", &cp->lock);
Expand Down
5 changes: 3 additions & 2 deletions pjnath/src/pjturn-srv/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ static void dump_status(pj_turn_srv *srv)
}

printf("Worker threads : %d\n", srv->core.thread_cnt);
printf("Total mem usage: %u.%03uMB\n", (unsigned)(g_cp.used_size / 1000000),
(unsigned)((g_cp.used_size % 1000000)/1000));
/* Field used_size is deprecated by #3897 */
//printf("Total mem usage: %u.%03uMB\n", (unsigned)(g_cp.used_size / 1000000),
// (unsigned)((g_cp.used_size % 1000000)/1000));
printf("UDP port range : %u %u %u (next/min/max)\n", srv->ports.next_udp,
srv->ports.min_udp, srv->ports.max_udp);
printf("TCP port range : %u %u %u (next/min/max)\n", srv->ports.next_tcp,
Expand Down
5 changes: 3 additions & 2 deletions pjsip-apps/src/samples/pjsip-perf.c
Original file line number Diff line number Diff line change
Expand Up @@ -900,8 +900,9 @@ static void destroy_app()
if (app.pool) {
pj_pool_release(app.pool);
app.pool = NULL;
PJ_LOG(3,(THIS_FILE, "Peak memory size: %luMB",
app.cp.peak_used_size / 1000000));
/* Field peak_used_size is deprecated by #3897 */
//PJ_LOG(3,(THIS_FILE, "Peak memory size: %luMB",
// app.cp.peak_used_size / 1000000));
pj_caching_pool_destroy(&app.cp);
}

Expand Down
7 changes: 4 additions & 3 deletions pjsip/src/test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,10 @@ int test_main(char *testlist)
pj_log_set_level(4);

/* Dumping memory pool usage */
PJ_LOG(3,(THIS_FILE, "Peak memory size=%lu MB",
(unsigned long)
(caching_pool.peak_used_size / 1000000)));
/* Field peak_used_size is deprecated by #3897 */
//PJ_LOG(3,(THIS_FILE, "Peak memory size=%lu MB",
// (unsigned long)
// (caching_pool.peak_used_size / 1000000)));

pjsip_endpt_destroy(endpt);
pj_caching_pool_destroy(&caching_pool);
Expand Down

0 comments on commit 478aeb9

Please sign in to comment.