The ROme OpTimistic Simulator  2.0.0
A General-Purpose Multithreaded Parallel/Distributed Simulation Platform
list.h File Reference

Generic Lists. More...

#include <stddef.h>
#include <string.h>
#include <assert.h>
#include <arch/atomic.h>
+ Include dependency graph for list.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  rootsim_list
 This structure defines a generic list. More...
 

Macros

#define my_offsetof(st, m)   ((size_t)( (unsigned char *)&((st)->m ) - (unsigned char *)(st)))
 This macro is a slightly-different implementation of the standard offsetof macro.
 
#define list(type)   type *
 Declare a "typed" list. This is a pointer to type, but the variable will instead reference a struct rootsim_list!
 
#define new_list(type)
 
#define list_sizeof(list)   ((struct rootsim_list *)list)->size
 
#define list_head(list)   ((__typeof__ (list))(((rootsim_list *)(list))->head))
 
#define list_tail(list)   ((__typeof__ (list))(((rootsim_list *)(list))->tail))
 
#define list_next(ptr)   ((ptr)->next)
 
#define list_prev(ptr)   ((ptr)->prev)
 
#define get_key(data)
 This macro retrieves the key of a payload data structure given its offset, and casts the value to double. More...
 
#define list_empty(list)   (((rootsim_list *)list)->size == 0)
 
#define list_insert_tail(li, data)
 
#define list_insert_head(li, data)
 
#define list_insert(li, key_name, data)
 Insert a new node in the list.
 
#define list_delete_by_content(li, node)
 
#define list_pop(list)
 
#define list_trunc(list, key_name, key_value, release_fn)
 Truncate a list up to a certain point, starting from the head. More...
 
#define list_size(list)   ((rootsim_list *)(list))->size
 

Typedefs

typedef struct rootsim_list rootsim_list
 This structure defines a generic list.
 

Detailed Description

Generic Lists.

This header defines macros to access lists of generic objects.

This file is part of ROOT-Sim (ROme OpTimistic Simulator).

ROOT-Sim is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; only version 3 of the License applies.

ROOT-Sim is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with ROOT-Sim; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

Author
Alessandro Pellegrini
Date
November 5, 2013

Definition in file list.h.

Macro Definition Documentation

#define get_key (   data)
Value:
({\
char *__key_ptr = ((char *)(data) + __key_position);\
double *__key_double_ptr = (double *)__key_ptr;\
*__key_double_ptr;\
})

This macro retrieves the key of a payload data structure given its offset, and casts the value to double.

Definition at line 98 of file list.h.

#define list_empty (   list)    (((rootsim_list *)list)->size == 0)

Given a pointer to a list, this macro evaluates to a boolean telling whether the list is empty or not.

Parameters
lista pointer to a list created using the new_list() macro.

Definition at line 110 of file list.h.

#define list_head (   list)    ((__typeof__ (list))(((rootsim_list *)(list))->head))

This macro retrieves a pointer to the payload of the head node of a list.

Parameters
lista pointer to a list created using the new_list() macro.

Definition at line 74 of file list.h.

#define list_insert_head (   li,
  data 
)
Value:
do { \
__typeof__(data) __new_n = (data); /* in-block scope variable */\
size_t __size_before;\
rootsim_list *__l;\
__new_n->next = NULL;\
__new_n->prev = NULL;\
do {\
__l = (rootsim_list *)(li);\
assert(__l);\
__size_before = __l->size;\
if(__l->size == 0) { /* is the list empty? */\
__l->head = __new_n;\
__l->tail = __new_n;\
break; /* leave the inner do-while */\
}\
__new_n->prev = NULL; /* Otherwise add at the beginning */\
__new_n->next = __l->head;\
((__typeof(data))__l->head)->prev = __new_n;\
__l->head = __new_n;\
} while(0);\
__l->size++;\
assert(__l->size == (__size_before + 1));\
} while(0)
This structure defines a generic list.
Definition: list.h:40

Definition at line 137 of file list.h.

#define list_insert_tail (   li,
  data 
)
Value:
do { \
__typeof__(data) __new_n = (data); /* in-block scope variable */\
size_t __size_before;\
rootsim_list *__l;\
__new_n->next = NULL;\
__new_n->prev = NULL;\
do {\
__l = (rootsim_list *)(li);\
assert(__l);\
__size_before = __l->size;\
if(__l->size == 0) { /* is the list empty? */\
__l->head = __new_n;\
__l->tail = __new_n;\
break; /* leave the inner do-while */\
}\
__new_n->next = NULL; /* Otherwise add at the end */\
__new_n->prev = __l->tail;\
((__typeof__(data))(__l->tail))->next = __new_n;\
__l->tail = __new_n;\
} while(0);\
__l->size++;\
assert(__l->size == (__size_before + 1));\
} while(0)
This structure defines a generic list.
Definition: list.h:40

Definition at line 112 of file list.h.

#define list_next (   ptr)    ((ptr)->next)

Given a pointer to a list node's payload, this macro retrieves the next node's payload, if any.

Parameters
ptra pointer to a list created using the new_list() macro.

Definition at line 88 of file list.h.

#define list_pop (   list)
Value:
do {\
size_t __size_before;\
__typeof__ (list) __n;\
__typeof__ (list) __n_next;\
__l = (rootsim_list *)(list);\
assert(__l);\
__size_before = __l->size;\
__n = __l->head;\
if(__n != NULL) {\
__l->head = __n->next;\
if(__n->next != NULL) {\
__n->next->prev = NULL;\
}\
__n_next = __n->next;\
__n->next = (void *)0xDEFEC8ED;\
__n->prev = (void *)0xDEFEC8ED;\
__n = __n_next;\
__l->size--;\
assert(__l->size == (__size_before - 1));\
}\
} while(0)
struct rootsim_list rootsim_list
This structure defines a generic list.
#define list(type)
Declare a "typed" list. This is a pointer to type, but the variable will instead reference a struct r...
Definition: list.h:51
This structure defines a generic list.
Definition: list.h:40

Definition at line 243 of file list.h.

#define list_prev (   ptr)    ((ptr)->prev)

Given a pointer to a list node's payload, this macro retrieves the prev node's payload, if any.

Parameters
ptra pointer to a list created using the new_list() macro.

Definition at line 95 of file list.h.

#define list_tail (   list)    ((__typeof__ (list))(((rootsim_list *)(list))->tail))

This macro retrieves a pointer to the payload of the tail node of a list.

Parameters
lista pointer to a list created using the new_list() macro.

Definition at line 81 of file list.h.

#define list_trunc (   list,
  key_name,
  key_value,
  release_fn 
)
Value:
({\
__typeof__(list) __n;\
__typeof__(list) __n_adjacent;\
unsigned int __deleted = 0;\
size_t __key_position = my_offsetof((list), key_name);\
assert(__l);\
size_t __size_before = __l->size;\
/* Attempting to truncate an empty list? */\
if(__l->size > 0) {\
__n = __l->head;\
while(__n != NULL && get_key(__n) < (key_value)) {\
__deleted++;\
__n_adjacent = __n->next;\
__n->next = (void *)0xBAADF00D;\
__n->prev = (void *)0xBAADF00D;\
release_fn(__n);\
__n = __n_adjacent;\
}\
__l->head = __n;\
if(__l->head != NULL)\
((__typeof__(list))__l->head)->prev = NULL;\
}\
__l->size -= __deleted;\
assert(__l->size == (__size_before - __deleted));\
__deleted;\
})
struct rootsim_list rootsim_list
This structure defines a generic list.
#define list(type)
Declare a "typed" list. This is a pointer to type, but the variable will instead reference a struct r...
Definition: list.h:51
#define my_offsetof(st, m)
This macro is a slightly-different implementation of the standard offsetof macro. ...
Definition: list.h:48
This structure defines a generic list.
Definition: list.h:40
#define get_key(data)
This macro retrieves the key of a payload data structure given its offset, and casts the value to dou...
Definition: list.h:98

Truncate a list up to a certain point, starting from the head.

Definition at line 268 of file list.h.

#define new_list (   type)
Value:
(type *)({ \
void *__lmptr; \
__lmptr = (void *)rsalloc(sizeof(struct rootsim_list)); \
bzero(__lmptr, sizeof(struct rootsim_list));\
__lmptr;\
})
This structure defines a generic list.
Definition: list.h:40

This macro allocates a struct rootsim_list object and cast it to the type pointer. It can be used to mimic the C++ syntax of templated lists, like:

1 list(int) = new_list(int);

Definition at line 59 of file list.h.