From fe696f6a909517ceb29016e2e0ed7abd37abaed9 Mon Sep 17 00:00:00 2001 From: MORIOKA Tomohiko Date: Sun, 19 May 2013 12:02:15 +0900 Subject: [PATCH] (concord_opened_feature_list): New variable. (concord_opened_feature_list_last): New variable. (concord_opened_feature_list_length): New variable. (concord_opened_feature_list_limit): New variable. (concord_opened_index_list): New variable. (concord_opened_index_list_last): New variable. (concord_opened_index_list_length): New variable. (concord_opened_index_list_limit): New variable. (concord_genre_open_feature): Initialize `table->next'. (concord_feature_setup_db): Use `concord_opened_feature_list'. (concord_genre_open_index): Initialize `table->next'. (concord_index_setup_db): Use `concord_opened_index_list'. --- concord.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/concord.c b/concord.c index 2a646d6..4e220e9 100644 --- a/concord.c +++ b/concord.c @@ -28,6 +28,16 @@ #include "cos-hash.h" #include "concord-bdb.h" +COS_Feature concord_opened_feature_list = NULL; +COS_Feature concord_opened_feature_list_last = NULL; +size_t concord_opened_feature_list_length = 0; +size_t concord_opened_feature_list_limit = 96; + +COS_Feature_INDEX concord_opened_index_list = NULL; +COS_Feature_INDEX concord_opened_index_list_last = NULL; +size_t concord_opened_index_list_length = 0; +size_t concord_opened_index_list_limit = 32; + int CONCORD_String_size (const CONCORD_String s) @@ -546,6 +556,7 @@ concord_genre_open_feature (CONCORD_Genre genre, const char* feature) } strcpy (table->name, feature); table->value_table = NULL; + table->next = NULL; return table; } @@ -613,6 +624,17 @@ concord_feature_setup_db (CONCORD_Feature feature, int writable) { CONCORD_Genre genre = feature->genre; + if ( concord_opened_feature_list_length + >= concord_opened_feature_list_limit ) + { + CONCORD_Feature top_feature = concord_opened_feature_list; + + CONCORD_BDB_close (top_feature->db); + top_feature->db = NULL; + concord_opened_feature_list = top_feature->next; + top_feature->next = NULL; + concord_opened_feature_list_length--; + } feature->db = CONCORD_BDB_open (genre->ds->location, genre->name, "feature", feature->name, @@ -621,6 +643,17 @@ concord_feature_setup_db (CONCORD_Feature feature, int writable) if (feature->db == NULL) return -1; feature->access = access; + if ( concord_opened_feature_list == NULL ) + { + concord_opened_feature_list = feature; + concord_opened_feature_list_last = feature; + } + else + { + concord_opened_feature_list_last->next = feature; + concord_opened_feature_list_last = feature; + } + concord_opened_feature_list_length++; } return 0; } @@ -753,6 +786,7 @@ concord_genre_open_index (CONCORD_Genre genre, const char* index) } strcpy (table->name, index); table->decoding_table = NULL; + table->next = NULL; return table; } @@ -820,6 +854,17 @@ concord_index_setup_db (CONCORD_INDEX index, int writable) { CONCORD_Genre genre = index->genre; + if ( concord_opened_index_list_length + >= concord_opened_index_list_limit ) + { + CONCORD_INDEX top_index = concord_opened_index_list; + + CONCORD_BDB_close (top_index->db); + top_index->db = NULL; + concord_opened_index_list = top_index->next; + top_index->next = NULL; + concord_opened_index_list_length--; + } index->db = CONCORD_BDB_open (genre->ds->location, genre->name, "index", index->name, @@ -828,6 +873,17 @@ concord_index_setup_db (CONCORD_INDEX index, int writable) if (index->db == NULL) return -1; index->access = access; + if ( concord_opened_index_list == NULL ) + { + concord_opened_index_list = index; + concord_opened_index_list_last = index; + } + else + { + concord_opened_index_list_last->next = index; + concord_opened_index_list_last = index; + } + concord_opened_index_list_length++; } return 0; } -- 1.7.10.4