Emulex Logo
OneCoreā„¢ Storage SDK Release 11.2
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ocs_list.h File Reference

Go to the source code of this file.

Detailed Description

OCS linked list API

Definition in file ocs_list.h.

Data Structures

struct  ocs_list_t
 list/link structure More...
 

Macros

#define OCS_LIST_DEBUG
 
#define ocs_list_magic_decl   uint32_t magic;
 
#define OCS_LIST_LIST_MAGIC   0xcafe0000
 
#define OCS_LIST_LINK_MAGIC   0xcafe0001
 
#define ocs_list_set_list_magic   list->magic = OCS_LIST_LIST_MAGIC
 
#define ocs_list_set_link_magic   list->magic = OCS_LIST_LINK_MAGIC
 
#define ocs_list_assert(cond,...)
 
#define item2link(list, item)   ((ocs_list_t*) (((uint8_t*)(item)) + (list)->offset))
 
#define link2item(list, link)   ((void*) (((uint8_t*)(link)) - (list)->offset))
 
#define ocs_list_init(head, type, link)   _ocs_list_init(head, offsetof(type, link))
 
#define ocs_list_remove_head(list)   ocs_list_remove(list, ocs_list_get_head(list))
 Remove and return an item from the head of the list. More...
 
#define ocs_list_foreach(list, item)   for (item = ocs_list_get_head((list)); item; item = ocs_list_next((list), item) )
 Iterate a linked list. More...
 
#define ocs_list_foreach_safe(list, item, nxt)
 Iterate a linked list safely. More...
 

Typedefs

typedef ocs_list_t ocs_list_link_t
 

Functions

void _ocs_list_assertmsg (const char *label, const char *filename, int linenum)
 
static void _ocs_list_init (ocs_list_t *list, uint32_t offset)
 Initialize a list. More...
 
static int32_t ocs_list_empty (ocs_list_t *list)
 Test if a list is empty. More...
 
static int32_t ocs_list_is_singular (ocs_list_t *list)
 Test if a list has single entry. More...
 
static int ocs_list_valid (ocs_list_t *list)
 Test if a list is valid (ready for use) More...
 
static void _ocs_list_insert_link (ocs_list_t *a, ocs_list_t *b, ocs_list_t *c)
 Insert link between two other links. More...
 
static void ocs_list_init_link (ocs_list_t *list, ocs_list_t *link)
 Initialize a list link for debug purposes. More...
 
static void ocs_list_add_head (ocs_list_t *list, void *item)
 Add an item to the head of the list. More...
 
static void ocs_list_add_tail (ocs_list_t *list, void *item)
 Add an item to the tail of the list. More...
 
static void * ocs_list_get_head (ocs_list_t *list)
 Return the first item in the list. More...
 
static void * ocs_list_get_tail (ocs_list_t *list)
 Return the first item in the list. More...
 
static void * ocs_list_tail (ocs_list_t *list)
 Return the last item in the list. More...
 
static void * ocs_list_next (ocs_list_t *list, void *item)
 Get the next item on the list. More...
 
static void * ocs_list_remove (ocs_list_t *list, void *item)
 Remove an item from the list. More...
 
static int32_t ocs_list_on_list (ocs_list_link_t *link)
 Test if object is on a list. More...
 

Macro Details

#define item2link (   list,
  item 
)    ((ocs_list_t*) (((uint8_t*)(item)) + (list)->offset))

Definition at line 87 of file ocs_list.h.

#define link2item (   list,
  link 
)    ((void*) (((uint8_t*)(link)) - (list)->offset))

Definition at line 90 of file ocs_list.h.

#define ocs_list_assert (   cond,
  ... 
)
Value:
if (!(cond)) { \
_ocs_list_assertmsg(#cond, __FILE__, __LINE__); \
return __VA_ARGS__; \
}
void _ocs_list_assertmsg(const char *label, const char *filename, int linenum)
Definition: ocs_list.c:35

Definition at line 55 of file ocs_list.h.

#define OCS_LIST_DEBUG

Definition at line 43 of file ocs_list.h.

#define ocs_list_foreach (   list,
  item 
)    for (item = ocs_list_get_head((list)); item; item = ocs_list_next((list), item) )

Iterate a linked list.

Iterate a linked list.

Parameters
listPointer to list
itemPointer to iterated item

note, item is NULL after full list is traversed.

Returns
none

Definition at line 428 of file ocs_list.h.

#define ocs_list_foreach_safe (   list,
  item,
  nxt 
)
Value:
for (item = ocs_list_get_head(list), nxt = item ? ocs_list_next(list, item) : NULL; item; \
item = nxt, nxt = ocs_list_next(list, item))
static void * ocs_list_get_head(ocs_list_t *list)
Return the first item in the list.
Definition: ocs_list.h:292
static void * ocs_list_next(ocs_list_t *list, void *item)
Get the next item on the list.
Definition: ocs_list.h:339

Iterate a linked list safely.

Iterate a linked list safely, meaning that the iterated item may be safely removed from the list.

Parameters
listPointer to list
itemPointer to iterated item
nxtPointer to saveed iterated item

note, item is NULL after full list is traversed.

Returns
none

Definition at line 446 of file ocs_list.h.

#define ocs_list_init (   head,
  type,
  link 
)    _ocs_list_init(head, offsetof(type, link))

Definition at line 113 of file ocs_list.h.

#define OCS_LIST_LINK_MAGIC   0xcafe0001

Definition at line 51 of file ocs_list.h.

#define OCS_LIST_LIST_MAGIC   0xcafe0000

Definition at line 50 of file ocs_list.h.

#define ocs_list_magic_decl   uint32_t magic;

Definition at line 49 of file ocs_list.h.

#define ocs_list_set_link_magic   list->magic = OCS_LIST_LINK_MAGIC

Definition at line 53 of file ocs_list.h.

#define ocs_list_set_list_magic   list->magic = OCS_LIST_LIST_MAGIC

Definition at line 52 of file ocs_list.h.

Type Details

typedef ocs_list_t ocs_list_link_t

Definition at line 84 of file ocs_list.h.

Function Details

void _ocs_list_assertmsg ( const char *  label,
const char *  filename,
int  linenum 
)

Definition at line 35 of file ocs_list.c.

static void _ocs_list_init ( ocs_list_t *  list,
uint32_t  offset 
)
inlinestatic

Initialize a list.

A list object is initialized. Helper define is used to call _ocs_list_init() with offsetof(type, link)

Parameters
listPointer to list
offsetOffset in bytes in item to the link element
Returns
none

Definition at line 104 of file ocs_list.h.

static void _ocs_list_insert_link ( ocs_list_t *  a,
ocs_list_t *  b,
ocs_list_t *  c 
)
inlinestatic

Insert link between two other links.

Inserts a link in between two other links

Parameters
aPointer to first link
bPointer to next link
cPointer to link to insert between a and b
Returns
none

Definition at line 172 of file ocs_list.h.

static void ocs_list_init_link ( ocs_list_t *  list,
ocs_list_t *  link 
)
inlinestatic

Initialize a list link for debug purposes.

For debugging a linked list link element has a magic number that is initialized, and the offset value initialzied and used for subsequent assertions.

Parameters
listPointer to list head
linkPointer to link to be initialized
Returns
none

Definition at line 210 of file ocs_list.h.

static int32_t ocs_list_on_list ( ocs_list_link_t *  link)
inlinestatic

Test if object is on a list.

Returns True if object is on a list

Parameters
linkPointer to list link
Returns
returns True if object is on a list

Definition at line 460 of file ocs_list.h.