#include <list.h>
Public Types | |
typedef __list_iterator< KeyType > | iterator |
typedef __list_const_iterator < KeyType > | const_iterator |
Public Member Functions | |
List () | |
constructor. constructs a empty with head is dummy | |
~List () | |
Destructor, supposed to be called when its associated data structure is to be deleted. | |
bool | front (KeyType &ret) |
Get the first element in the list. If the list is empty, it will return false. else return true and assign the first element to the parameter. | |
bool | insert (int index, const KeyType &e) |
Add the specified element into the list. | |
iterator | begin () |
iterator | end () |
const_iterator | begin () const |
const_iterator | end () const |
int | size () |
Get the size of list. | |
bool | push_front (const KeyType &e) |
Add a specified element in to the list's first position. | |
bool | empty () |
Judge if the list is empty. | |
bool | remove (const KeyType &e) |
Remove a specified element by value. | |
bool | search (const KeyType &e) |
Judge if the element is in the list. | |
Protected Types | |
typedef SMR< NodeType< KeyType > , NHPOINTER >::HP_Rec | HazardP |
Protected Member Functions | |
List (const List &s) | |
List & | operator= (const List &st) |
Protected Attributes | |
atomic< NodeType< KeyType > * > | head |
NodeType< KeyType > * | dummy |
SMR< NodeType< KeyType > , NHPOINTER > * | mm |
This lock-free linked list is an unbounded thread-safe linked list. A LockFreeList
is an appropriate choice when many threads will share access to a common collection. This list does not permit null
elements.
This is a lock-free implementation intended for highly scalable add, remove and contains which is thread safe. Add() will add the element to the head of the list which is different with the normal list.
Iterator is not thread-safe and only used when debugging.
ABA prevention method is based on Maged M. Michael's: Hazard Pointers: Safe Memory Reclamation for Lock-Free Objects
KeyType | The type of the element which is stored in the list |
typedef __list_iterator<KeyType> amino::List< KeyType >::iterator |
typedef __list_const_iterator<KeyType> amino::List< KeyType >::const_iterator |
typedef SMR<NodeType<KeyType>, NHPOINTER>::HP_Rec amino::List< KeyType >::HazardP [protected] |
amino::List< KeyType >::List | ( | const List< KeyType > & | s | ) | [inline, protected] |
amino::List< KeyType >::List | ( | ) | [inline] |
constructor. constructs a empty with head is dummy
amino::List< KeyType >::~List | ( | ) | [inline] |
Destructor, supposed to be called when its associated data structure is to be deleted.
List& amino::List< KeyType >::operator= | ( | const List< KeyType > & | st | ) | [inline, protected] |
bool amino::List< KeyType >::front | ( | KeyType & | ret | ) | [inline] |
Get the first element in the list. If the list is empty, it will return false. else return true and assign the first element to the parameter.
ret | The first element in the list. It is valid if the return value is true. |
bool amino::List< KeyType >::insert | ( | int | index, | |
const KeyType & | e | |||
) | [inline] |
Add the specified element into the list.
index | Not work in this function now. | |
e | The element to be added |
iterator amino::List< KeyType >::begin | ( | ) | [inline] |
iterator amino::List< KeyType >::end | ( | ) | [inline] |
const_iterator amino::List< KeyType >::begin | ( | ) | const [inline] |
const_iterator amino::List< KeyType >::end | ( | ) | const [inline] |
int amino::List< KeyType >::size | ( | ) | [inline] |
Get the size of list.
bool amino::List< KeyType >::push_front | ( | const KeyType & | e | ) | [inline] |
Add a specified element in to the list's first position.
e | The element to be added |
bool amino::List< KeyType >::empty | ( | ) | [inline] |
Judge if the list is empty.
bool amino::List< KeyType >::remove | ( | const KeyType & | e | ) | [inline] |
bool amino::List< KeyType >::search | ( | const KeyType & | e | ) | [inline] |
Judge if the element is in the list.
e | The element to be searched |
atomic<NodeType<KeyType>*> amino::List< KeyType >::head [protected] |
NodeType<KeyType>* amino::List< KeyType >::dummy [protected] |
a pointer created for initializing of head pointer, for the performance reason
SMR<NodeType<KeyType>, NHPOINTER>* amino::List< KeyType >::mm [protected] |
for memory management