[patch] next/pprev list #2

Jan Bobrowski (jb@wizard.ae.krakow.pl)
Thu, 3 Jun 1999 23:43:23 +0200 (MET DST)


Patches against 2.3.4 available at:
http://wizard.ae.krakow.pl/~jb/patches/elist-def.diff.gz
http://wizard.ae.krakow.pl/~jb/patches/elist-struc.diff.gz
http://wizard.ae.krakow.pl/~jb/patches/elist-fs.diff.gz

This is newer version of "next/pprev list" patch. First patch adds elist
definitions. Second changes some structures where such lists were previously
used (but not explicitly). Third replaces list_head lists in inode and dentry
structures to reduce size (50% hashtable size).
Definitions slightly changed from previous version.

About elist
~~~~~~~~~~~
Each list built using elist structures is anchored by elist_anchor_t type
variable (it is pointer to the first element). Standard lists built around
list_head structure use for that purpose head of the list (two pointers).

'elist' is terminated by ELIST_END constant (not NULL!) while using list_head
lists you have to check if you got list head again (these are circular lists).
Anchor of 'elist' should be initialized with ELIST_END.

ELIST_END is pointer to a dummy tail (shared by all elists). This trick makes
p->next->pprev field always accessbile and avoids special checking during list
manipulation.

Basic operations:

void elist_add (struct elist *new, elist_anchor_t *list)
void elist_clear (struct elist *entry)
struct elist* elist_del (struct elist *entry)
struct elist* elist_del_and_clear (struct elist *entry)

elist_add adds 'new' at the beginning of 'list'

elist_clear initializes 'entry' so that it can be tested for presence
on a list. Further 'list_del's will not change it's state.
You may use ELIST_CLEAR constant in struct initialization
instead.

elist_del removes 'entry' from elist. Pointer to the next element is
returned. 'entry' itself remains in unknown state.

elist_del_and_clear
'elist_del' and 'elist_clear' at once. Optimized.

on_elist(entry) false if entry was cleared.
elist_empty(list) tells if 'list' is empty (is equal to ELIST_END).
list_entry(pointer,type,member)
this macro can be used with elists. Given 'pointer'
to 'member' returns address to whole structure.
elist_add_after(new,entry)
elist_add_before(new,entry)

To help elist scanning there are useful macros:

elist_start (ptr, list, member)
Initializes 'ptr' so that ptr->member is first element
of 'list'; ptr->member should be of type 'struct elist';

elist_next (ptr, member)
Returns next element of list.

elist_finished (ptr, member)
Tells if we reached end of a list. If so, 'ptr' doesn't point
any structure (&ptr->member==ELIST_END).

forall_elist (ptr, list, member) {}
You can walk through 'list' (elist_anchor_t) using 'member'
fields. 'ptr' variable is initialized by elist_start.

forall_elist_ne (ptr, list, member) {}
You may use it if you guarantee that 'list' is not empty.

Jan Bobrowski
jb@wizard.ae.krakow.pl

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/