Commit aa8a3408 authored by Pekka Pessi's avatar Pekka Pessi

Reduced overhead in su_home_auto().

darcs-hash:20051220175157-65a35-ef04acb4eb56a9305d169f38325c533548d50a83.gz
parent a9106e8a
......@@ -172,6 +172,7 @@ void (*su_home_mutex_unlocker)(void *mutex);
enum {
SUB_N = 31, /**< Initial size */
SUB_N_AUTO = 7, /**< Initial size for autohome */
SUB_P = 29 /**< Secondary probe.
* Secondary probe must be relative prime
* with all sub_n values */
......@@ -189,18 +190,20 @@ typedef struct {
struct su_block_s {
su_home_t *sub_parent; /**< Parent home */
char *sub_preload; /**< Preload area */
su_home_stat_t *sub_stats; /**< Statistics.. */
unsigned sub_ref; /**< Reference count */
unsigned sub_used; /**< Number of blocks allocated */
unsigned sub_n; /**< Size of hash table */
su_home_stat_t *sub_stats; /**< Statistics.. */
char *sub_preload;
unsigned sub_prsize:16; /**< Preload size */
unsigned sub_prused:16; /**< Used from preload */
unsigned sub_auto:1; /**< This struct is from stack! */
unsigned sub_auto:1; /**< struct su_block_s is from stack! */
unsigned sub_preauto:1; /**< Preload is from stack! */
unsigned sub_auto_all:1; /**< Everything is from stack! */
unsigned :0;
su_alloc_t sub_nodes[SUB_N]; /**< Pointers to data/lower blocks */
};
......@@ -951,7 +954,7 @@ su_home_t *su_home_auto(void *area, int size)
su_home_t *home;
su_block_t *sub;
size_t homesize = ALIGN(sizeof *home);
size_t subsize = ALIGN(sizeof *sub);
size_t subsize = ALIGN(offsetof(su_block_t, sub_nodes[SUB_N_AUTO]));
size_t prepsize;
char *p = area;
......@@ -967,7 +970,7 @@ su_home_t *su_home_auto(void *area, int size)
sub = memset(p + homesize, 0, subsize);
home->suh_blocks = sub;
sub->sub_n = SUB_N;
sub->sub_n = SUB_N_AUTO;
sub->sub_preload = p + prepsize;
sub->sub_prsize = size - prepsize;
sub->sub_preauto = 1;
......
......@@ -81,8 +81,11 @@ SU_DLL void su_home_preload(su_home_t *h, int n, int size);
SU_DLL su_home_t *su_home_auto(void *area, int size);
#define SU_HOME_AUTO_SIZE(n) \
(((n) + sizeof(su_home_t) + 74 * sizeof(void *) - 1)/sizeof(su_home_t))
#define SU_HOME_AUTO_SIZE(n) \
(((n) + ((sizeof(su_home_t) + 7) & ~8) + \
((3 * sizeof (void *) + 4 * sizeof(unsigned) + \
7 * (sizeof (long) + sizeof(void *)) + 7) & ~8)) \
/ sizeof(su_home_t))
SU_DLL int su_home_move(su_home_t *dst, su_home_t *src);
......
......@@ -539,8 +539,20 @@ static int test_auto(void)
TEST(hs->hs_allocs.hsa_preload + hs->hs_allocs.hsa_number, 8191 + 8191 / 32);
TEST(hs->hs_frees.hsf_preload + hs->hs_frees.hsf_number, 8191 + 8191 / 32 - 1);
/*
This test depends on macro SU_HOME_AUTO_SIZE() calculating
offsetof(su_block_t, sub_nodes[7]) correctly with
((3 * sizeof (void *) + 4 * sizeof(unsigned) +
7 * (sizeof (long) + sizeof(void *)) + 7)
*/
TEST_1(hs->hs_frees.hsf_preload == hs->hs_allocs.hsa_preload);
su_free(tmphome, b);
for (i = 1; i < 8192; i++)
TEST_1(b = su_alloc(tmphome, 1));
TEST_VOID(su_home_deinit(tmphome));
END();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment