Merge branch 'master' of ssh://git.dcc.fc.up.pt/yap-6.3

This commit is contained in:
Vítor Santos Costa 2011-12-22 11:43:44 +00:00
commit 39b035a309
5 changed files with 135 additions and 115 deletions

View File

@ -41,7 +41,7 @@
*********************/ *********************/
#ifdef USE_PAGES_MALLOC #ifdef USE_PAGES_MALLOC
#define STRUCTS_PER_PAGE(STR_TYPE) ((Yap_page_size - STRUCT_SIZE(struct page_header)) / STRUCT_SIZE(STR_TYPE)) #define STRUCTS_PER_PAGE(STR_TYPE) ((Yap_page_size - ADJUST_SIZE(sizeof(struct page_header))) / ADJUST_SIZE(sizeof(STR_TYPE)))
#define INIT_PAGES(PG, STR_TYPE) \ #define INIT_PAGES(PG, STR_TYPE) \
INIT_LOCK(Pg_lock(PG)); \ INIT_LOCK(Pg_lock(PG)); \

View File

@ -38,7 +38,6 @@ extern int Yap_page_size;
#define ADJUST_SIZE(SIZE) ((SIZE + ALIGN) & ALIGNMASK) #define ADJUST_SIZE(SIZE) ((SIZE + ALIGN) & ALIGNMASK)
#define ADJUST_SIZE_TO_PAGE(SIZE) ((SIZE) - (SIZE) % Yap_page_size + Yap_page_size) #define ADJUST_SIZE_TO_PAGE(SIZE) ((SIZE) - (SIZE) % Yap_page_size + Yap_page_size)
#define STRUCT_SIZE(STR_TYPE) ADJUST_SIZE(sizeof(STR_TYPE))
#define PAGE_HEADER(STR) (pg_hd_ptr)((unsigned long int)STR - (unsigned long int)STR % Yap_page_size) #define PAGE_HEADER(STR) (pg_hd_ptr)((unsigned long int)STR - (unsigned long int)STR % Yap_page_size)
#define STRUCT_NEXT(STR) ((STR)->next) #define STRUCT_NEXT(STR) ((STR)->next)

View File

@ -12,7 +12,7 @@
************************************************************************/ ************************************************************************/
/********************** /**********************
** Typedefs ** ** typedefs **
**********************/ **********************/
typedef double realtime; typedef double realtime;
@ -53,9 +53,9 @@ cptr_to_offset_with_null(choiceptr node)
/********************************************************** /**************************************************
** Structs ma_h_inner_struct and ma_hash_entry ** ** ma_h_inner_struct and ma_hash_entry **
**********************************************************/ **************************************************/
#if (defined(TABLING) || !defined(YAPOR_COW)) && defined(MULTI_ASSIGNMENT_VARIABLES) #if (defined(TABLING) || !defined(YAPOR_COW)) && defined(MULTI_ASSIGNMENT_VARIABLES)
#define MAVARS_HASH_SIZE 512 #define MAVARS_HASH_SIZE 512
@ -97,9 +97,9 @@ struct threads_dependency_frame {
/********************************* /**************************
** Struct page_header ** ** page_header **
*********************************/ **************************/
#ifdef USE_PAGES_MALLOC #ifdef USE_PAGES_MALLOC
typedef struct page_header { typedef struct page_header {
@ -117,101 +117,113 @@ typedef struct page_header {
/*************************** /*****************************************
** Struct pages ** ** global_page and local_page **
***************************/ *****************************************/
struct pages { struct global_page_entry {
#if defined(YAPOR) || defined(THREADS) #if defined(YAPOR) || defined(THREADS)
lockvar lock; lockvar lock;
#endif /* YAPOR || THREADS */ #endif /* YAPOR || THREADS */
#ifdef USE_PAGES_MALLOC #ifdef USE_PAGES_MALLOC
int structs_per_page;
struct page_header *first_free_page; struct page_header *first_free_page;
int structs_per_page;
volatile long pages_allocated;
#endif /* USE_PAGES_MALLOC */
volatile long structs_in_use;
};
struct local_page_entry {
#if defined(YAPOR) || defined(THREADS)
lockvar lock;
#endif /* YAPOR || THREADS */
#ifdef USE_PAGES_MALLOC
struct page_header *first_free_page;
int structs_per_page;
volatile long pages_allocated; volatile long pages_allocated;
#endif /* USE_PAGES_MALLOC */ #endif /* USE_PAGES_MALLOC */
volatile long structs_in_use; volatile long structs_in_use;
}; };
#define Pg_lock(X) ((X).lock) #define Pg_lock(X) ((X).lock)
#define Pg_str_per_pg(X) ((X).structs_per_page)
#define Pg_free_pg(X) ((X).first_free_page) #define Pg_free_pg(X) ((X).first_free_page)
#define Pg_str_per_pg(X) ((X).structs_per_page)
#define Pg_pg_alloc(X) ((X).pages_allocated) #define Pg_pg_alloc(X) ((X).pages_allocated)
#define Pg_str_in_use(X) ((X).structs_in_use) #define Pg_str_in_use(X) ((X).structs_in_use)
#define Pg_str_free(X) (Pg_pg_alloc(X) * Pg_str_per_pg(X) - Pg_str_in_use(X)) #define Pg_str_free(X) (Pg_pg_alloc(X) * Pg_str_per_pg(X) - Pg_str_in_use(X))
/********************************** /***************************
** Struct global_pages ** ** global_pages **
**********************************/ ***************************/
struct global_pages { struct global_pages {
struct pages void_pages; struct global_page_entry void_pages;
#ifdef TABLING #ifdef TABLING
struct pages table_entry_pages; struct global_page_entry table_entry_pages;
#if defined(THREADS_FULL_SHARING) || defined(THREADS_CONSUMER_SHARING) #if defined(THREADS_FULL_SHARING) || defined(THREADS_CONSUMER_SHARING)
struct pages subgoal_entry_pages; struct global_page_entry subgoal_entry_pages;
#endif #endif
#if !defined(THREADS_NO_SHARING) && !defined(THREADS_SUBGOAL_SHARING) && !defined(THREADS_FULL_SHARING) && !defined(THREADS_CONSUMER_SHARING) #if !defined(THREADS_NO_SHARING) && !defined(THREADS_SUBGOAL_SHARING) && !defined(THREADS_FULL_SHARING) && !defined(THREADS_CONSUMER_SHARING)
struct pages subgoal_frame_pages; struct global_page_entry subgoal_frame_pages;
struct pages dependency_frame_pages; struct global_page_entry dependency_frame_pages;
#endif #endif
#if !defined(THREADS_NO_SHARING) #if !defined(THREADS_NO_SHARING)
struct pages subgoal_trie_node_pages; struct global_page_entry subgoal_trie_node_pages;
struct pages subgoal_trie_hash_pages; struct global_page_entry subgoal_trie_hash_pages;
#endif #endif
#if !defined(THREADS_NO_SHARING) && !defined(THREADS_SUBGOAL_SHARING) #if !defined(THREADS_NO_SHARING) && !defined(THREADS_SUBGOAL_SHARING)
struct pages answer_trie_node_pages; struct global_page_entry answer_trie_node_pages;
struct pages answer_trie_hash_pages; struct global_page_entry answer_trie_hash_pages;
#endif #endif
struct pages global_trie_node_pages; struct global_page_entry global_trie_node_pages;
struct pages global_trie_hash_pages; struct global_page_entry global_trie_hash_pages;
#endif /* TABLING */ #endif /* TABLING */
#ifdef YAPOR #ifdef YAPOR
struct pages or_frame_pages; struct global_page_entry or_frame_pages;
struct pages query_goal_solution_frame_pages; struct global_page_entry query_goal_solution_frame_pages;
struct pages query_goal_answer_frame_pages; struct global_page_entry query_goal_answer_frame_pages;
#endif /* YAPOR */ #endif /* YAPOR */
#if defined(YAPOR) && defined(TABLING) #if defined(YAPOR) && defined(TABLING)
struct pages suspension_frame_pages; struct global_page_entry suspension_frame_pages;
#endif /* YAPOR && TABLING */ #endif /* YAPOR && TABLING */
#ifdef TABLING_INNER_CUTS #ifdef TABLING_INNER_CUTS
struct pages table_subgoal_solution_frame_pages; struct global_page_entry table_subgoal_solution_frame_pages;
struct pages table_subgoal_answer_frame_pages; struct global_page_entry table_subgoal_answer_frame_pages;
#endif /* TABLING_INNER_CUTS */ #endif /* TABLING_INNER_CUTS */
}; };
/********************************* /**************************
** Struct local_pages ** ** local_pages **
*********************************/ **************************/
#if defined(TABLING) && (defined(YAPOR) || defined(THREADS)) #if defined(TABLING) && (defined(YAPOR) || defined(THREADS))
struct local_pages { struct local_pages {
#if defined(YAPOR) #if defined(YAPOR)
struct answer_trie_node *next_free_answer_trie_node; struct answer_trie_node *next_free_answer_trie_node;
#elif defined(THREADS) #elif defined(THREADS)
struct pages void_pages; struct local_page_entry void_pages;
struct pages subgoal_frame_pages; struct local_page_entry subgoal_frame_pages;
struct pages dependency_frame_pages; struct local_page_entry dependency_frame_pages;
#if defined(THREADS_NO_SHARING) #if defined(THREADS_NO_SHARING)
struct pages subgoal_trie_node_pages; struct local_page_entry subgoal_trie_node_pages;
struct pages subgoal_trie_hash_pages; struct local_page_entry subgoal_trie_hash_pages;
#elif defined(THREADS_SUBGOAL_SHARING) || defined(THREADS_FULL_SHARING) || defined(THREADS_CONSUMER_SHARING) #elif defined(THREADS_SUBGOAL_SHARING) || defined(THREADS_FULL_SHARING) || defined(THREADS_CONSUMER_SHARING)
struct subgoal_trie_node *next_free_subgoal_trie_node; struct subgoal_trie_node *next_free_subgoal_trie_node;
struct subgoal_trie_hash *next_free_subgoal_trie_hash; struct subgoal_trie_hash *next_free_subgoal_trie_hash;
#endif #endif
#if defined(THREADS_NO_SHARING) || defined(THREADS_SUBGOAL_SHARING) #if defined(THREADS_NO_SHARING) || defined(THREADS_SUBGOAL_SHARING)
struct pages answer_trie_node_pages; struct local_page_entry answer_trie_node_pages;
struct pages answer_trie_hash_pages; struct local_page_entry answer_trie_hash_pages;
#elif defined(THREADS_FULL_SHARING) || defined(THREADS_CONSUMER_SHARING) #elif defined(THREADS_FULL_SHARING) || defined(THREADS_CONSUMER_SHARING)
struct answer_trie_node *next_free_answer_trie_node; struct answer_trie_node *next_free_answer_trie_node;
struct answer_trie_hash *next_free_answer_trie_hash; struct answer_trie_hash *next_free_answer_trie_hash;
#endif #endif
#if defined(THREADS_FULL_SHARING) #if defined(THREADS_FULL_SHARING)
struct pages answer_ref_node_pages; struct local_page_entry answer_ref_node_pages;
#endif #endif
#endif /* YAPOR - THREADS */ #endif /* YAPOR - THREADS */
}; };
@ -219,9 +231,9 @@ struct local_pages {
/***************************************** /**********************************
** Struct global_optyap_locks ** ** global_optyap_locks **
*****************************************/ **********************************/
#ifdef YAPOR #ifdef YAPOR
struct global_optyap_locks { struct global_optyap_locks {
@ -243,9 +255,9 @@ struct global_optyap_locks {
/****************************************** /***********************************
** Struct local_optyap_signals ** ** local_optyap_signals **
******************************************/ ***********************************/
#ifdef YAPOR #ifdef YAPOR
struct local_optyap_signals { struct local_optyap_signals {
@ -272,7 +284,7 @@ struct local_optyap_signals {
/********************************* /*********************************
* Struct global_optyap_data ** ** global_optyap_data **
*********************************/ *********************************/
struct global_optyap_data { struct global_optyap_data {
@ -406,9 +418,9 @@ struct global_optyap_data {
/*************************************** /********************************
** Struct local_optyap_data ** ** local_optyap_data **
***************************************/ ********************************/
struct local_optyap_data { struct local_optyap_data {
#if defined(TABLING) && (defined(YAPOR) || defined(THREADS)) #if defined(TABLING) && (defined(YAPOR) || defined(THREADS))

View File

@ -59,7 +59,7 @@ typedef struct table_entry {
/*********************************************************************** /***********************************************************************
** global_trie_node, subgoal_trie_node and answer_trie_node ** ** subgoal_trie_node, answer_trie_node and global_trie_node **
***********************************************************************/ ***********************************************************************/
typedef struct subgoal_trie_node { typedef struct subgoal_trie_node {
@ -108,7 +108,7 @@ typedef struct global_trie_node {
/*********************************************************************** /***********************************************************************
** global_trie_hash, subgoal_trie_hash and answer_trie_hash ** ** subgoal_trie_hash, answer_trie_hash and global_trie_hash **
***********************************************************************/ ***********************************************************************/
typedef struct subgoal_trie_hash { typedef struct subgoal_trie_hash {

View File

@ -130,27 +130,27 @@ static inline sg_node_ptr subgoal_trie_check_insert_entry(tab_ent_ptr tab_ent, s
count_nodes++; count_nodes++;
if (count_nodes >= MAX_NODES_PER_BUCKET && Hash_num_nodes(hash) > Hash_num_buckets(hash)) { if (count_nodes >= MAX_NODES_PER_BUCKET && Hash_num_nodes(hash) > Hash_num_buckets(hash)) {
/* expand current hash */ /* expand current hash */
sg_node_ptr chain_node, next_node, *old_bucket, *hash_old_buckets, *hash_new_buckets; sg_node_ptr chain_node, next_node, *old_bucket, *old_hash_buckets, *new_hash_buckets;
int num_buckets; int num_buckets;
num_buckets = Hash_num_buckets(hash) * 2; num_buckets = Hash_num_buckets(hash) * 2;
ALLOC_HASH_BUCKETS(hash_new_buckets, num_buckets); ALLOC_HASH_BUCKETS(new_hash_buckets, num_buckets);
hash_old_buckets = Hash_buckets(hash); old_hash_buckets = Hash_buckets(hash);
old_bucket = hash_old_buckets + Hash_num_buckets(hash); old_bucket = old_hash_buckets + Hash_num_buckets(hash);
do { do {
if (*--old_bucket) { if (*--old_bucket) {
chain_node = *old_bucket; chain_node = *old_bucket;
do { do {
bucket = hash_new_buckets + HASH_ENTRY(TrNode_entry(chain_node), num_buckets); bucket = new_hash_buckets + HASH_ENTRY(TrNode_entry(chain_node), num_buckets);
next_node = TrNode_next(chain_node); next_node = TrNode_next(chain_node);
TrNode_next(chain_node) = *bucket; TrNode_next(chain_node) = *bucket;
*bucket = chain_node; *bucket = chain_node;
chain_node = next_node; chain_node = next_node;
} while (chain_node); } while (chain_node);
} }
} while (old_bucket != hash_old_buckets); } while (old_bucket != old_hash_buckets);
FREE_HASH_BUCKETS(hash_old_buckets); Hash_buckets(hash) = new_hash_buckets;
Hash_buckets(hash) = hash_new_buckets;
Hash_num_buckets(hash) = num_buckets; Hash_num_buckets(hash) = num_buckets;
FREE_HASH_BUCKETS(old_hash_buckets);
} }
UNLOCK_SUBGOAL_NODE(parent_node); UNLOCK_SUBGOAL_NODE(parent_node);
return child_node; return child_node;
@ -273,9 +273,12 @@ subgoal_trie_hash:
sg_node_ptr *bucket, first_node; sg_node_ptr *bucket, first_node;
int num_buckets, count_nodes = 0; int num_buckets, count_nodes = 0;
num_buckets = Hash_num_buckets(hash); do {
bucket = Hash_buckets(hash) + HASH_ENTRY(t, num_buckets); num_buckets = Hash_num_buckets(hash);
first_node = child_node = *bucket; // __sync_synchronize();
bucket = Hash_buckets(hash) + HASH_ENTRY(t, num_buckets);
first_node = child_node = *bucket;
} while (num_buckets != Hash_num_buckets(hash));
while (child_node) { while (child_node) {
if (TrNode_entry(child_node) == t) if (TrNode_entry(child_node) == t)
return child_node; return child_node;
@ -320,26 +323,26 @@ subgoal_trie_hash:
count_nodes++; count_nodes++;
if (count_nodes >= MAX_NODES_PER_BUCKET && Hash_num_nodes(hash) > Hash_num_buckets(hash)) { if (count_nodes >= MAX_NODES_PER_BUCKET && Hash_num_nodes(hash) > Hash_num_buckets(hash)) {
/* expand current hash */ /* expand current hash */
sg_node_ptr chain_node, next_node, *old_bucket, *hash_old_buckets, *hash_new_buckets; sg_node_ptr chain_node, next_node, *old_bucket, *old_hash_buckets, *new_hash_buckets;
num_buckets = Hash_num_buckets(hash) * 2; num_buckets = Hash_num_buckets(hash) * 2;
ALLOC_HASH_BUCKETS(hash_new_buckets, num_buckets); ALLOC_HASH_BUCKETS(new_hash_buckets, num_buckets);
hash_old_buckets = Hash_buckets(hash); old_hash_buckets = Hash_buckets(hash);
old_bucket = hash_old_buckets + Hash_num_buckets(hash); old_bucket = old_hash_buckets + Hash_num_buckets(hash);
do { do {
if (*--old_bucket) { if (*--old_bucket) {
chain_node = *old_bucket; chain_node = *old_bucket;
do { do {
bucket = hash_new_buckets + HASH_ENTRY(TrNode_entry(chain_node), num_buckets); bucket = new_hash_buckets + HASH_ENTRY(TrNode_entry(chain_node), num_buckets);
next_node = TrNode_next(chain_node); next_node = TrNode_next(chain_node);
TrNode_next(chain_node) = *bucket; TrNode_next(chain_node) = *bucket;
*bucket = chain_node; *bucket = chain_node;
chain_node = next_node; chain_node = next_node;
} while (chain_node); } while (chain_node);
} }
} while (old_bucket != hash_old_buckets); } while (old_bucket != old_hash_buckets);
FREE_HASH_BUCKETS(hash_old_buckets); Hash_buckets(hash) = new_hash_buckets;
Hash_buckets(hash) = hash_new_buckets;
Hash_num_buckets(hash) = num_buckets; Hash_num_buckets(hash) = num_buckets;
FREE_HASH_BUCKETS(old_hash_buckets);
} }
UNLOCK_SUBGOAL_NODE(parent_node); UNLOCK_SUBGOAL_NODE(parent_node);
return child_node; return child_node;
@ -428,27 +431,27 @@ static inline ans_node_ptr answer_trie_check_insert_entry(sg_fr_ptr sg_fr, ans_n
count_nodes++; count_nodes++;
if (count_nodes >= MAX_NODES_PER_BUCKET && Hash_num_nodes(hash) > Hash_num_buckets(hash)) { if (count_nodes >= MAX_NODES_PER_BUCKET && Hash_num_nodes(hash) > Hash_num_buckets(hash)) {
/* expand current hash */ /* expand current hash */
ans_node_ptr chain_node, next_node, *old_bucket, *hash_old_buckets, *hash_new_buckets; ans_node_ptr chain_node, next_node, *old_bucket, *old_hash_buckets, *new_hash_buckets;
int num_buckets; int num_buckets;
num_buckets = Hash_num_buckets(hash) * 2; num_buckets = Hash_num_buckets(hash) * 2;
ALLOC_HASH_BUCKETS(hash_new_buckets, num_buckets); ALLOC_HASH_BUCKETS(new_hash_buckets, num_buckets);
hash_old_buckets = Hash_buckets(hash); old_hash_buckets = Hash_buckets(hash);
old_bucket = hash_old_buckets + Hash_num_buckets(hash); old_bucket = old_hash_buckets + Hash_num_buckets(hash);
do { do {
if (*--old_bucket) { if (*--old_bucket) {
chain_node = *old_bucket; chain_node = *old_bucket;
do { do {
bucket = hash_new_buckets + HASH_ENTRY(TrNode_entry(chain_node), num_buckets); bucket = new_hash_buckets + HASH_ENTRY(TrNode_entry(chain_node), num_buckets);
next_node = TrNode_next(chain_node); next_node = TrNode_next(chain_node);
TrNode_next(chain_node) = *bucket; TrNode_next(chain_node) = *bucket;
*bucket = chain_node; *bucket = chain_node;
chain_node = next_node; chain_node = next_node;
} while (chain_node); } while (chain_node);
} }
} while (old_bucket != hash_old_buckets); } while (old_bucket != old_hash_buckets);
FREE_HASH_BUCKETS(hash_old_buckets); Hash_buckets(hash) = new_hash_buckets;
Hash_buckets(hash) = hash_new_buckets;
Hash_num_buckets(hash) = num_buckets; Hash_num_buckets(hash) = num_buckets;
FREE_HASH_BUCKETS(old_hash_buckets);
} }
UNLOCK_ANSWER_NODE(parent_node); UNLOCK_ANSWER_NODE(parent_node);
return child_node; return child_node;
@ -572,9 +575,12 @@ answer_trie_hash:
ans_node_ptr *bucket, first_node; ans_node_ptr *bucket, first_node;
int num_buckets, count_nodes = 0; int num_buckets, count_nodes = 0;
num_buckets = Hash_num_buckets(hash); do {
bucket = Hash_buckets(hash) + HASH_ENTRY(t, num_buckets); num_buckets = Hash_num_buckets(hash);
first_node = child_node = *bucket; // __sync_synchronize();
bucket = Hash_buckets(hash) + HASH_ENTRY(t, num_buckets);
first_node = child_node = *bucket;
} while (num_buckets != Hash_num_buckets(hash));
while (child_node) { while (child_node) {
if (TrNode_entry(child_node) == t) if (TrNode_entry(child_node) == t)
return child_node; return child_node;
@ -619,26 +625,26 @@ answer_trie_hash:
count_nodes++; count_nodes++;
if (count_nodes >= MAX_NODES_PER_BUCKET && Hash_num_nodes(hash) > Hash_num_buckets(hash)) { if (count_nodes >= MAX_NODES_PER_BUCKET && Hash_num_nodes(hash) > Hash_num_buckets(hash)) {
/* expand current hash */ /* expand current hash */
ans_node_ptr chain_node, next_node, *old_bucket, *hash_old_buckets, *hash_new_buckets; ans_node_ptr chain_node, next_node, *old_bucket, *old_hash_buckets, *new_hash_buckets;
num_buckets = Hash_num_buckets(hash) * 2; num_buckets = Hash_num_buckets(hash) * 2;
ALLOC_HASH_BUCKETS(hash_new_buckets, num_buckets); ALLOC_HASH_BUCKETS(new_hash_buckets, num_buckets);
hash_old_buckets = Hash_buckets(hash); old_hash_buckets = Hash_buckets(hash);
old_bucket = hash_old_buckets + Hash_num_buckets(hash); old_bucket = old_hash_buckets + Hash_num_buckets(hash);
do { do {
if (*--old_bucket) { if (*--old_bucket) {
chain_node = *old_bucket; chain_node = *old_bucket;
do { do {
bucket = hash_new_buckets + HASH_ENTRY(TrNode_entry(chain_node), num_buckets); bucket = new_hash_buckets + HASH_ENTRY(TrNode_entry(chain_node), num_buckets);
next_node = TrNode_next(chain_node); next_node = TrNode_next(chain_node);
TrNode_next(chain_node) = *bucket; TrNode_next(chain_node) = *bucket;
*bucket = chain_node; *bucket = chain_node;
chain_node = next_node; chain_node = next_node;
} while (chain_node); } while (chain_node);
} }
} while (old_bucket != hash_old_buckets); } while (old_bucket != old_hash_buckets);
FREE_HASH_BUCKETS(hash_old_buckets); Hash_buckets(hash) = new_hash_buckets;
Hash_buckets(hash) = hash_new_buckets;
Hash_num_buckets(hash) = num_buckets; Hash_num_buckets(hash) = num_buckets;
FREE_HASH_BUCKETS(old_hash_buckets);
} }
UNLOCK_ANSWER_NODE(parent_node); UNLOCK_ANSWER_NODE(parent_node);
return child_node; return child_node;
@ -725,27 +731,27 @@ static inline gt_node_ptr global_trie_check_insert_entry(gt_node_ptr parent_node
count_nodes++; count_nodes++;
if (count_nodes >= MAX_NODES_PER_BUCKET && Hash_num_nodes(hash) > Hash_num_buckets(hash)) { if (count_nodes >= MAX_NODES_PER_BUCKET && Hash_num_nodes(hash) > Hash_num_buckets(hash)) {
/* expand current hash */ /* expand current hash */
gt_node_ptr chain_node, next_node, *old_bucket, *hash_old_buckets, *hash_new_buckets; gt_node_ptr chain_node, next_node, *old_bucket, *old_hash_buckets, *new_hash_buckets;
int num_buckets; int num_buckets;
num_buckets = Hash_num_buckets(hash) * 2; num_buckets = Hash_num_buckets(hash) * 2;
ALLOC_HASH_BUCKETS(hash_new_buckets, num_buckets); ALLOC_HASH_BUCKETS(new_hash_buckets, num_buckets);
hash_old_buckets = Hash_buckets(hash); old_hash_buckets = Hash_buckets(hash);
old_bucket = hash_old_buckets + Hash_num_buckets(hash); old_bucket = old_hash_buckets + Hash_num_buckets(hash);
do { do {
if (*--old_bucket) { if (*--old_bucket) {
chain_node = *old_bucket; chain_node = *old_bucket;
do { do {
bucket = hash_new_buckets + HASH_ENTRY(TrNode_entry(chain_node), num_buckets); bucket = new_hash_buckets + HASH_ENTRY(TrNode_entry(chain_node), num_buckets);
next_node = TrNode_next(chain_node); next_node = TrNode_next(chain_node);
TrNode_next(chain_node) = *bucket; TrNode_next(chain_node) = *bucket;
*bucket = chain_node; *bucket = chain_node;
chain_node = next_node; chain_node = next_node;
} while (chain_node); } while (chain_node);
} }
} while (old_bucket != hash_old_buckets); } while (old_bucket != old_hash_buckets);
FREE_HASH_BUCKETS(hash_old_buckets); Hash_buckets(hash) = new_hash_buckets;
Hash_buckets(hash) = hash_new_buckets;
Hash_num_buckets(hash) = num_buckets; Hash_num_buckets(hash) = num_buckets;
FREE_HASH_BUCKETS(old_hash_buckets);
} }
UNLOCK_GLOBAL_NODE(parent_node); UNLOCK_GLOBAL_NODE(parent_node);
return child_node; return child_node;
@ -869,9 +875,12 @@ global_trie_hash:
gt_node_ptr *bucket, first_node; gt_node_ptr *bucket, first_node;
int num_buckets, count_nodes = 0; int num_buckets, count_nodes = 0;
num_buckets = Hash_num_buckets(hash); do {
bucket = Hash_buckets(hash) + HASH_ENTRY(t, num_buckets); num_buckets = Hash_num_buckets(hash);
first_node = child_node = *bucket; // __sync_synchronize();
bucket = Hash_buckets(hash) + HASH_ENTRY(t, num_buckets);
first_node = child_node = *bucket;
} while (num_buckets != Hash_num_buckets(hash));
while (child_node) { while (child_node) {
if (TrNode_entry(child_node) == t) if (TrNode_entry(child_node) == t)
return child_node; return child_node;
@ -916,26 +925,26 @@ global_trie_hash:
count_nodes++; count_nodes++;
if (count_nodes >= MAX_NODES_PER_BUCKET && Hash_num_nodes(hash) > Hash_num_buckets(hash)) { if (count_nodes >= MAX_NODES_PER_BUCKET && Hash_num_nodes(hash) > Hash_num_buckets(hash)) {
/* expand current hash */ /* expand current hash */
gt_node_ptr chain_node, next_node, *old_bucket, *hash_old_buckets, *hash_new_buckets; gt_node_ptr chain_node, next_node, *old_bucket, *old_hash_buckets, *new_hash_buckets;
num_buckets = Hash_num_buckets(hash) * 2; num_buckets = Hash_num_buckets(hash) * 2;
ALLOC_HASH_BUCKETS(hash_new_buckets, num_buckets); ALLOC_HASH_BUCKETS(new_hash_buckets, num_buckets);
hash_old_buckets = Hash_buckets(hash); old_hash_buckets = Hash_buckets(hash);
old_bucket = hash_old_buckets + Hash_num_buckets(hash); old_bucket = old_hash_buckets + Hash_num_buckets(hash);
do { do {
if (*--old_bucket) { if (*--old_bucket) {
chain_node = *old_bucket; chain_node = *old_bucket;
do { do {
bucket = hash_new_buckets + HASH_ENTRY(TrNode_entry(chain_node), num_buckets); bucket = new_hash_buckets + HASH_ENTRY(TrNode_entry(chain_node), num_buckets);
next_node = TrNode_next(chain_node); next_node = TrNode_next(chain_node);
TrNode_next(chain_node) = *bucket; TrNode_next(chain_node) = *bucket;
*bucket = chain_node; *bucket = chain_node;
chain_node = next_node; chain_node = next_node;
} while (chain_node); } while (chain_node);
} }
} while (old_bucket != hash_old_buckets); } while (old_bucket != old_hash_buckets);
FREE_HASH_BUCKETS(hash_old_buckets); Hash_buckets(hash) = new_hash_buckets;
Hash_buckets(hash) = hash_new_buckets;
Hash_num_buckets(hash) = num_buckets; Hash_num_buckets(hash) = num_buckets;
FREE_HASH_BUCKETS(old_hash_buckets);
} }
UNLOCK_GLOBAL_NODE(parent_node); UNLOCK_GLOBAL_NODE(parent_node);
return child_node; return child_node;