From: Mark H. <ma...@os...> - 2004-05-03 20:17:28
|
Jon, Here are the next set of list_head changes. These update the name sequence and subscription structures. The name sequence list is an hlist_head/hlist_node instead of a list_head. It's head has only one pointer so that the hash table didn't increase in size. Mark. cvs diff -u name_subscr.c name_subscr.h reg.c name_table.c bcast.h Index: name_subscr.c =================================================================== RCS file: /cvsroot/tipc/source/unstable/net/tipc/name_subscr.c,v retrieving revision 1.6 diff -u -r1.6 name_subscr.c --- name_subscr.c 11 Mar 2004 01:27:14 -0000 1.6 +++ name_subscr.c 3 May 2004 19:48:46 -0000 @@ -238,6 +238,7 @@ } this = (struct name_subscr*)k_malloc(sizeof(*this)); memset(this,0,sizeof(*this)); + INIT_LIST_HEAD(&this->nsub_list); s->ref = ref_lock_acquire(this,&this->lock); if (!s->ref){ warn("Obtained no ref for subsription\n"); Index: name_subscr.h =================================================================== RCS file: /cvsroot/tipc/source/unstable/net/tipc/name_subscr.h,v retrieving revision 1.3 diff -u -r1.3 name_subscr.h --- name_subscr.h 16 Feb 2004 23:00:02 -0000 1.3 +++ name_subscr.h 3 May 2004 19:48:46 -0000 @@ -89,7 +89,7 @@ struct name_subscr { struct tipc_name_subscr publ; - struct name_subscr *next; + struct list_head nsub_list; void (*event_handler) (struct tipc_name_event *); long unsigned int timer_ref; int expired; Index: reg.c =================================================================== RCS file: /cvsroot/tipc/source/unstable/net/tipc/reg.c,v retrieving revision 1.6 diff -u -r1.6 reg.c --- reg.c 16 Feb 2004 23:00:02 -0000 1.6 +++ reg.c 3 May 2004 19:48:46 -0000 @@ -267,12 +267,7 @@ return TIPC_OK; spin_lock_bh(®_lock); user = &users[s->reg.ref]; - if (s->reg.prev) - s->reg.prev->reg.next = s->reg.next; - else - user->subs = s->reg.next; - if (s->next) - s->reg.next->reg.prev = s->reg.prev; + list_del_init(&s->nsub_list); spin_unlock_bh(®_lock); return TIPC_OK; } Index: name_table.c =================================================================== RCS file: /cvsroot/tipc/source/unstable/net/tipc/name_table.c,v retrieving revision 1.14 diff -u -r1.14 name_table.c --- name_table.c 28 Apr 2004 21:55:26 -0000 1.14 +++ name_table.c 3 May 2004 19:48:46 -0000 @@ -118,8 +118,8 @@ #include "bcast.h" -static void nametbl_dump(void); -static void nametbl_print(struct print_buf *buf, const char *str); +void nametbl_dump(void); +void nametbl_print(struct print_buf *buf, const char *str); rwlock_t nametbl_lock = RW_LOCK_UNLOCKED; /* @@ -196,14 +196,13 @@ struct sub_seq* sseqs; uint alloc; uint first_free; - struct name_seq *prev; - struct name_seq *next; - struct name_subscr *subscriptions; + struct hlist_node ns_list; + struct list_head subscriptions; spinlock_t lock; }; struct name_seq * -nameseq_create(uint type, struct name_seq *next) +nameseq_create(uint type, struct hlist_head *seq_head) { struct name_seq *this = (struct name_seq *)k_malloc(sizeof(*this)); @@ -211,12 +210,12 @@ this->lock = SPIN_LOCK_UNLOCKED; this->type = type; this->sseqs = subseq_alloc(1); - dbg("nameseq_create() this = %x type %u, next =%x, ssseqs %x, ff: %u\n", - this,type, next,this->sseqs,this->first_free); + dbg("nameseq_create() this = %x type %u, ssseqs %x, ff: %u\n", + this,type, this->sseqs,this->first_free); this->alloc = 1; - this->next = next; - if (next) - next->prev = this; + INIT_HLIST_NODE(&this->ns_list); + INIT_LIST_HEAD(&this->subscriptions); + hlist_add_head(&this->ns_list, seq_head); return this; } @@ -288,7 +287,6 @@ uint scope, uint key) { - struct name_subscr *s = this->subscriptions; struct publication *publ; struct sub_seq *sseq; int created_subseq = 0; @@ -365,18 +363,21 @@ } } - if (!created_subseq) - return publ; + /* + * Any subscriptions waiting for notification? + */ + if (created_subseq) { + struct name_subscr *s, *st; + list_for_each_entry_safe(s, st, + &this->subscriptions, nsub_list) { - /* Any subscriptions waiting ? */ - while (s) { - namesub_report_overlap(s, + namesub_report_overlap(s, publ->lower, publ->upper, TIPC_PUBLISHED, publ->ref, publ->node); - s = s->next; + } } return publ; } @@ -388,11 +389,11 @@ tipc_net_addr_t node, uint key) { - struct name_subscr *s = this->subscriptions; struct publication *publ; struct publication *prev = 0; struct sub_seq *sseq = nameseq_find_subseq(this,inst); struct sub_seq *free; + struct name_subscr *s, *st; assert(this); if (!sseq) { int i; @@ -473,20 +474,22 @@ if (sseq->node_list || sseq->cluster_list || sseq->zone_list) return publ; - /* No more publications,contract subseq list: */ - + /* + * No more publications,contract subseq list: + */ free = &this->sseqs[this->first_free--]; memmove(sseq,sseq+1,(free-(sseq+1))*sizeof(*sseq)); - /* Any subscriptions waiting ? */ - while (s) { + /* + * Any subscriptions waiting ? + */ + list_for_each_entry_safe(s, st, &this->subscriptions, nsub_list) { namesub_report_overlap(s, publ->lower, publ->upper, TIPC_WITHDRAWN, publ->ref, publ->node); - s = s->next; } return publ; } @@ -529,8 +532,7 @@ { struct sub_seq *sseq = this->sseqs; - s->next = this->subscriptions; - this->subscriptions = s; + list_move(&s->nsub_list, &this->subscriptions); if (!sseq) return; @@ -545,10 +547,6 @@ } - - - - /* * struct name_table: translation table containing all existing * port name publications. Consists of 'name_seq' objects @@ -560,7 +558,7 @@ #define TABLE_SIZE (1<<14) struct name_table { - struct name_seq *types[TABLE_SIZE]; + struct hlist_head types[TABLE_SIZE]; uint key; uint local_publ_count; }; @@ -576,15 +574,22 @@ static struct name_seq* nametbl_find_seq(uint type) { - struct name_seq* seq; - dbg("find_seq %u,(%u,0x%x) table = %x, hash[type] = %u\n", - type,ntohl(type),type,table,hash(type)); - seq = table->types[hash(type)]; - dbg("found %x\n",seq); - while (seq && (seq->type != type)) { - seq = seq->next; + struct hlist_head *seq_head; + struct hlist_node *seq_node; + struct name_seq *ns; + + dbg("find_seq %u,(%u,0x%x) table = %p, hash[type] = %u\n", + type, ntohl(type), type, table, hash(type)); + + seq_head = &table->types[hash(type)]; + hlist_for_each_entry(ns, seq_node, seq_head, ns_list) { + if (ns->type == type) { + dbg("found %x\n", ns); + return ns; + } } - return seq; + + return 0; }; @@ -606,8 +611,7 @@ } dbg("Publishing <%u,%u,%u> from %x\n", type, lower, upper, node); if (!seq) { - struct name_seq *head = table->types[hash(type)]; - seq = table->types[hash(type)] = nameseq_create(type, head); + seq = nameseq_create(type, &table->types[hash(type)]); dbg("nametbl_insert_publ: created %x\n",seq); } assert(seq->type == type); @@ -626,13 +630,9 @@ return 0; dbg("Withdrawing <%u,%u> from %x\n", type, lower, node); publ = nameseq_remove_publ(seq, lower, node, key); - if (!seq->first_free && !seq->subscriptions) { - if (seq->prev) - seq->prev->next = seq->next; - else - table->types[hash(seq->type)] = seq->next; - if (seq->next) - seq->next->prev = seq->prev; + + if (!seq->first_free && list_empty(&seq->subscriptions)) { + hlist_del_init(&seq->ns_list); kfree(seq->sseqs); kfree(seq); } @@ -778,7 +778,6 @@ spin_unlock_bh(&seq->lock); goto not_found; } - found: spin_unlock_bh(&seq->lock); read_unlock_bh(&nametbl_lock); return true; @@ -797,7 +796,6 @@ struct name_seq* seq; int i = 0; struct publication* publ; - struct publication *publhead; struct sub_seq *sseq; int low_seq, high_seq; uint destport; @@ -921,8 +919,7 @@ struct name_seq *seq; seq = nametbl_find_seq(type); if (!seq) { - struct name_seq *head = table->types[hash(type)]; - seq = table->types[hash(type)] = nameseq_create(type, head); + seq = nameseq_create(type, &table->types[hash(type)]); } spin_lock_bh(&seq->lock); dbg("nametbl_subscribe:found %x for <%u,%u,%u>\n", @@ -936,21 +933,16 @@ nametbl_unsubscribe(struct name_subscr *s) { uint type = s->publ.s.seq.type; - struct name_subscr *prev = 0; struct name_subscr *crs; struct name_seq *seq = nametbl_find_seq(type); assert(seq); + spin_lock_bh(&seq->lock); - crs = seq->subscriptions; - while ((crs != 0) && (crs != s)) { - prev = crs; - crs = crs->next; - } - if (crs){ - if (!prev) - seq->subscriptions = crs->next; - else - prev->next = crs->next; + list_for_each_entry(crs, &seq->subscriptions, nsub_list) { + if (crs == s) { + list_del_init(&s->nsub_list); + break; + } } spin_unlock_bh(&seq->lock); } @@ -1026,13 +1018,15 @@ static void nametbl_list(struct print_buf *buf, uint type, uint depth) { - struct name_seq *seq = 0; + struct hlist_head *seq_head; + struct hlist_node *seq_node; + struct name_seq *seq; + uint i; for (i = 0; i < TABLE_SIZE; i++) { - seq = table->types[i]; - while (seq) { - nameseq_list(seq,buf,type,depth,i); - seq = seq->next; + seq_head = &table->types[i]; + hlist_for_each_entry(seq, seq_node, seq_head, ns_list) { + nameseq_list(seq, buf, type, depth, i); } } } @@ -1081,11 +1075,15 @@ nametbl_stop(void) { uint i; + struct hlist_head *seq_head; + struct hlist_node *seq_node, *tmp; + struct name_seq *seq; + write_lock_bh(&nametbl_lock); for (i = 0; i < TABLE_SIZE; i++) { - struct name_seq *seq = table->types[i]; - while (seq) { - struct name_seq *next_seq = seq->next; + seq_head = &table->types[i]; + hlist_for_each_entry_safe(seq, seq_node, + tmp, seq_head, ns_list) { struct sub_seq *sseq = seq->sseqs; for(;sseq != &seq->sseqs[seq->first_free];sseq++){ @@ -1098,9 +1096,9 @@ } while(publ != sseq->zone_list); } - seq = next_seq; } } kfree(table); + table = 0; write_unlock_bh(&nametbl_lock); } Index: bcast.h =================================================================== RCS file: /cvsroot/tipc/source/unstable/net/tipc/bcast.h,v retrieving revision 1.10 diff -u -r1.10 bcast.h --- bcast.h 16 Apr 2004 04:03:46 -0000 1.10 +++ bcast.h 3 May 2004 19:48:46 -0000 @@ -165,6 +165,10 @@ void tipc_bcast_start(void); void tipc_bcast_stop(void); +void bnode_outqueue_release(int ackno); +int in_list_node(struct list_head *list, tipc_net_addr_t destnode); +int in_list(struct list_head *list, uint destport, tipc_net_addr_t destnode); + struct bcastlinkset* blink_select(int selector); -- Mark Haverkamp <ma...@os...> |