]> granicus.if.org Git - pgbouncer/commitdiff
move db/user/pool alloc also to slabs
authorMarko Kreen <markokr@gmail.com>
Fri, 11 Jan 2008 21:52:00 +0000 (21:52 +0000)
committerMarko Kreen <markokr@gmail.com>
Fri, 11 Jan 2008 21:52:00 +0000 (21:52 +0000)
include/objects.h
src/janitor.c
src/objects.c

index 3e241cbd594d4b79eb85565ccb4b26e68fb04063..92f44a78dc3a819fe0ebf5f262ab14b8478df1fa 100644 (file)
@@ -23,6 +23,9 @@ extern StatList database_list;
 extern StatList login_client_list;
 extern ObjectCache *client_cache;
 extern ObjectCache *server_cache;
+extern ObjectCache *db_cache;
+extern ObjectCache *pool_cache;
+extern ObjectCache *user_cache;
 
 PgDatabase *find_database(const char *name);
 PgUser *find_user(const char *name);
index a596313c1326a41ad353579db9d2739afece73a6..301e0900c73c6ccac5144758df7eb7ec89782120 100644 (file)
@@ -527,7 +527,7 @@ static void kill_pool(PgPool *pool)
 
        list_del(&pool->map_head);
        statlist_remove(&pool->head, &pool_list);
-       free(pool);
+       obj_free(pool_cache, pool);
 }
 
 static void kill_database(PgDatabase *db)
@@ -543,9 +543,9 @@ static void kill_database(PgDatabase *db)
                        kill_pool(pool);
        }
        if (db->forced_user)
-               free(db->forced_user);
+               obj_free(user_cache, db->forced_user);
        statlist_remove(&db->head, &database_list);
-       free(db);
+       obj_free(db_cache, db);
 }
 
 /* as [pgbouncer] section can be loaded after databases,
index 70c5686a3cb58d661087f5b788b0b44f5c52a135..7e155493cb3a5b19173e93fa7615ce699f03b309 100644 (file)
@@ -38,6 +38,9 @@ STATLIST(login_client_list);
 
 ObjectCache *server_cache;
 ObjectCache *client_cache;
+ObjectCache *db_cache;
+ObjectCache *pool_cache;
+ObjectCache *user_cache;
 
 /*
  * libevent may still report events when event_del()
@@ -114,6 +117,12 @@ static int user_node_cmp(long userptr, Node *node)
 void init_objects(void)
 {
        tree_init(&user_tree, user_node_cmp, NULL);
+       user_cache = objcache_create("user_cache", sizeof(PgUser), 0, NULL, NULL);
+       db_cache = objcache_create("db_cache", sizeof(PgDatabase), 0, NULL, NULL);
+       pool_cache = objcache_create("pool_cache", sizeof(PgPool), 0, NULL, NULL);
+
+       if (!user_cache || !db_cache || !pool_cache)
+               fatal("cannot create initial caches");
 }
 
 /* initialization after config loading */
@@ -300,7 +309,7 @@ PgDatabase *add_database(const char *name)
 
        /* create new object if needed */
        if (db == NULL) {
-               db = zmalloc(sizeof(*db));
+               db = obj_alloc(db_cache);
                if (!db)
                        return NULL;
 
@@ -318,7 +327,7 @@ PgUser *add_user(const char *name, const char *passwd)
        PgUser *user = find_user(name);
 
        if (user == NULL) {
-               user = zmalloc(sizeof(*user));
+               user = obj_alloc(user_cache);
                if (!user)
                        return NULL;
 
@@ -338,7 +347,7 @@ PgUser *force_user(PgDatabase *db, const char *name, const char *passwd)
 {
        PgUser *user = db->forced_user;
        if (!user) {
-               user = zmalloc(sizeof(*user));
+               user = obj_alloc(user_cache);
                if (!user)
                        return NULL;
                list_init(&user->head);
@@ -379,7 +388,7 @@ static PgPool *new_pool(PgDatabase *db, PgUser *user)
 {
        PgPool *pool;
 
-       pool = zmalloc(sizeof(*pool));
+       pool = obj_alloc(pool_cache);
        if (!pool)
                return NULL;