Code beautification with uncrustify
[alexxy/gromacs.git] / src / gromacs / legacyheaders / thread_mpi / list.h
1 /*
2    This source code file is part of thread_mpi.
3    Written by Sander Pronk, Erik Lindahl, and possibly others.
4
5    Copyright (c) 2009, Sander Pronk, Erik Lindahl.
6    All rights reserved.
7
8    Redistribution and use in source and binary forms, with or without
9    modification, are permitted provided that the following conditions are met:
10    1) Redistributions of source code must retain the above copyright
11    notice, this list of conditions and the following disclaimer.
12    2) Redistributions in binary form must reproduce the above copyright
13    notice, this list of conditions and the following disclaimer in the
14    documentation and/or other materials provided with the distribution.
15    3) Neither the name of the copyright holders nor the
16    names of its contributors may be used to endorse or promote products
17    derived from this software without specific prior written permission.
18
19    THIS SOFTWARE IS PROVIDED BY US ''AS IS'' AND ANY
20    EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22    DISCLAIMED. IN NO EVENT SHALL WE BE LIABLE FOR ANY
23    DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26    ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30    If you want to redistribute modifications, please consider that
31    scientific software is very special. Version control is crucial -
32    bugs must be traceable. We will be happy to consider code for
33    inclusion in the official distribution, but derived work should not
34    be called official thread_mpi. Details are found in the README & COPYING
35    files.
36  */
37
38 #ifndef TMPI_LIST_H_
39 #define TMPI_LIST_H_
40
41 #include "atomic.h"
42
43
44 /** \file
45  *
46  * \brief Lock-free list data structures.
47  *
48  */
49
50
51 #ifdef __cplusplus
52 extern "C"
53 {
54 #endif
55 #if 0
56 } /* Avoids screwing up auto-indentation */
57 #endif
58
59
60 /**  Lock-free single-ended stack (FIFO)
61
62    Is a list with push, pop and detach operations */
63 typedef struct
64 {
65     tMPI_Atomic_ptr_t head;          /**< Pointer to the top stack element. */
66 } tMPI_Stack;
67
68 /**  A single element in stack */
69 typedef struct tMPI_Stack_element
70 {
71     struct tMPI_Stack_element *next; /**< Pointer to the next stack element. */
72     void                      *data; /**< Pointer to data. */
73 } tMPI_Stack_element;
74
75
76 /**  Initialize a stack */
77 TMPI_EXPORT
78 void tMPI_Stack_init(tMPI_Stack *st);
79
80 /**  Deallocates a stack */
81 TMPI_EXPORT
82 void tMPI_Stack_destroy(tMPI_Stack *st);
83
84 /**  Pushes a stack element onto a stack */
85 TMPI_EXPORT
86 void tMPI_Stack_push(tMPI_Stack *st, tMPI_Stack_element *el);
87
88 /**  Pops a stack element from  a stack */
89 TMPI_EXPORT
90 tMPI_Stack_element *tMPI_Stack_pop(tMPI_Stack *st);
91
92 /**  Detaches entire stack for use by a single thread */
93 TMPI_EXPORT
94 tMPI_Stack_element *tMPI_Stack_detach(tMPI_Stack *st);
95
96
97
98 #if 0
99 /**  Lock-free double-ended queue (FIFO)
100
101    Is a list with enqueue and dequeue operations */
102 typedef struct
103 {
104     tMPI_Atomic_ptr_t head, tail;
105 } tMPI_Queue;
106
107 /**  A single element in a queue */
108 typedef struct tMPI_Queue_element
109 {
110     struct tMPI_Queue_element *next; /**< Pointer to the next queue element. */
111     struct tMPI_Queue_element *prev; /**< Pointer to the prev queue element. */
112     void                      *data; /**< Pointer to data. */
113 } tMPI_Queue_element;
114
115 /**  Initialize a queue */
116 void tMPI_Queue_init(tMPI_Queue *q);
117
118 /**  Deallocates a queue */
119 void tMPI_Queue_destroy(tMPI_Queue *q);
120
121 /**  Enqueue an element onto the head of a queue */
122 void tMPI_Queue_enqueue(tMPI_Queue *q, tMPI_Queue_element *qe);
123
124 /**  Dequeue an element from the end a queue */
125 tMPI_Queue_element *tMPI_Queue_dequeue(tMPI_Queue *q);
126
127
128
129
130
131 /**  Lock-free circular doubly linked list */
132 typedef struct
133 {
134     tMPI_Atomic_ptr_t head;
135 } tMPI_List;
136
137 /**  Lock-free circular doubly linked list */
138 typedef struct tMPI_List_element
139 {
140     struct tMPI_List_element *next, *prev;
141     void                     *data;
142 } tMPI_List_element;
143
144 /**  Initialize a list */
145 void tMPI_List_init(tMPI_List *l);
146 /**  Deallocates a list */
147 void tMPI_List_destroy(tMPI_List *l);
148
149 tMPI_List_element* tMPI_List_first(tMPI_List *l);
150 tMPI_List_element* tMPI_List_next(tMPI_List         *l,
151                                   tMPI_List_element *le);
152 tMPI_List_element* tMPI_List_prev(tMPI_List         *l,
153                                   tMPI_List_element *le);
154
155 void tMPI_List_add(tMPI_List *l, tMPI_List_element *le);
156 void tMPI_List_insert(tMPI_List *l, tMPI_List_element *after,
157                       tMPI_List_element *le);
158 void tMPI_List_remove(tMPI_List *l, tMPI_List_element *le);
159 #endif
160
161
162 #ifdef __cplusplus
163 } /* closing extern "C" */
164 #endif
165
166 #endif /* TMPI_LIST_H_ */