📄 pool.c
字号:
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/pool.c,v 1.3 2003/01/15 14:04:33 josh Exp $ *//* * Copyright (C) 1999-2005 Wind River Systems, Inc. * All rights reserved. Provided under license only. * Distribution or other use of this software is only * permitted pursuant to the terms of a license agreement * from Wind River Systems (and is otherwise prohibited). * Refer to that license agreement for terms of use. *//* [clearcase]modification history-------------------01a,19apr05,job update copyright notices*//**************************************************************************** * Copyright 1999 Integrated Systems, Inc. * All rights reserved. ****************************************************************************/#include <wrn/wm/common/config.h>#include <wrn/wm/common/glue.h>#include <wrn/wm/attache/config.h>#include <wrn/wm/demo/snarklib.h>struct pool_shim { pool_id_t pool_id; int block_id;};struct pool_log_s {#if INSTALL_SNARK_POOL_TEST_METRICS int current; int hiwat;#endif int total;} pool_log[MEMPOOL_MAX_POOL_ID];void *glue_alloc_pool (size_t size, pool_id_t id){ void *tp; struct pool_shim *ps; if (size == 0) return 0; tp = malloc (size + sizeof(*ps)); if (tp == 0) return 0; ps = (struct pool_shim*)tp; ps->pool_id = id; ps->block_id = ++pool_log[id].total; BUG(BUG_MEMPOOL_TRACE, BUG_TRACE, (void *)ps, (BUG_OUT, "glue_alloc_pool: pool %u, block %d", id, ps->block_id));#if INSTALL_SNARK_POOL_TEST_METRICS ++pool_log[id].current; if (pool_log[id].hiwat < pool_log[id].current) pool_log[id].hiwat = pool_log[id].current;#endif return ((void *)&ps[1]);}void glue_free_pool (void *p, pool_id_t id) { struct pool_shim *ps = p; --ps; BUG(BUG_MEMPOOL_TRACE, BUG_TRACE, (void *)ps, (BUG_OUT, "glue_free_pool: pool %u, block %d", id, ps->block_id)); BUG_ASSERT(ps->pool_id == id);#if INSTALL_SNARK_POOL_TEST_METRICS --pool_log[id].current; BUG_ASSERT(pool_log[id].current >= 0);#endif free(ps);}#if INSTALL_SNARK_POOL_TEST_METRICSvoid pool_report(void){ int i; printf("memory pool report:\n" "id\tcurrent\thiwat\ttotal\n"); for (i = 0; i < MEMPOOL_MAX_POOL_ID; ++i) { if (pool_log[i].total > 0) { printf("%d\t%d\t%d\t%d\n", i, pool_log[i].current, pool_log[i].hiwat, pool_log[i].total); } }}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -