File: sge_sl.h

package info (click to toggle)
gridengine 8.1.9%2Bdfsg-9
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 56,756 kB
  • sloc: ansic: 432,689; java: 87,068; cpp: 31,958; sh: 29,429; jsp: 7,757; perl: 6,336; xml: 5,828; makefile: 4,701; csh: 3,934; ruby: 2,221; tcl: 1,676; lisp: 669; yacc: 519; python: 503; lex: 361
file content (231 lines) | stat: -rw-r--r-- 7,049 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#ifndef __SGE_SL_H
#define __SGE_SL_H

/*___INFO__MARK_BEGIN__*/
/*************************************************************************
 * 
 *  The Contents of this file are made available subject to the terms of
 *  the Sun Industry Standards Source License Version 1.2
 * 
 *  Sun Microsystems Inc., March, 2001
 * 
 * 
 *  Sun Industry Standards Source License Version 1.2
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.2 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 * 
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 * 
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 * 
 *   Copyright: 2001 by Sun Microsystems, Inc.
 * 
 *   All Rights Reserved.
 * 
 ************************************************************************/
/*___INFO__MARK_END__*/

#include <pthread.h>

/****** uti/sl/--SimpleList() **********************************************
*
*  NAME
*     sl - A Simple List Implementation for Grid Engine
*
*  SYNOPSIS
*
*  FUNCTION
*     This module provides a simple and thread safe list
*     implementation for Grid Engine. Lists can be created, destroyed
*     and the number of the contained nodes can be retrieved. 
*
*        sge_sl_create()
*        sge_sl_destroy()
*        sge_sl_get_elements()
*
*     The list is implemented as double links list so that data
*     can be accessed forward and backward easily. Function arguments
*     decide if the first or last element should be addressed.
*
*        sge_sl_insert()
*        sge_sl_delete()
*        sge_sl_data()
*
*     Elements can also be inserted into a sorted list or they can
*     be searched using a user defined compare function.
*
*        sge_sl_insert_search()
*        sge_sl_delete_search()
*        sge_sl_data_search()
*        sge_sl_sort()
*
*     The underlaying list data structure is thread safe so that one list
*     can be accessed without additional synchronisation between the
*     threads. 
*
*     Node data structures are NOT thread safe for that reason
*     following functions need additional synchronisation because they
*     provide access to node data structures.
*
*        sge_sl_elem_create()
*        sge_sl_elem_destroy()
*        sge_sl_elem_data()
*        sge_sl_elem_next()
*        sge_sl_elem_search()
*        sge_sl_dechain()
*        sge_sl_insert_before()
*        sge_sl_append_after()
*
*     The list implementation provides locking functions that provide a way
*     to synchronize access with a list object. Therefore it is easily
*     possible to secure the above node based functions and execute them in
*     an atomic block.
*
*        sge_sl_lock()
*        sge_sl_unlock()
*
*     Please be cautious when you need other locks in a code block between
*     the lock and unlock function. If the sequence in demanding the locks
*     is not correct this might cause a deadlock.
*
*  SEE ALSO
*     uti/sl/sge_sl_elem_create()
*     uti/sl/sge_sl_elem_destroy()
*     uti/sl/sge_sl_elem_data()
*     uti/sl/sge_sl_elem_next()
*     uti/sl/sge_sl_elem_search()
*     uti/sl/sge_sl_dechain()
*     uti/sl/sge_sl_insert_before()
*     uti/sl/sge_sl_append_after()
*     uti/sl/sge_sl_create()
*     uti/sl/sge_sl_destroy()
*     uti/sl/sge_sl_lock()
*     uti/sl/sge_sl_unlock()
*     uti/sl/sge_sl_insert()
*     uti/sl/sge_sl_insert_search()
*     uti/sl/sge_sl_data()
*     uti/sl/sge_sl_data_search()
*     uti/sl/sge_sl_delete()
*     uti/sl/sge_sl_delete_search()
*     uti/sl/sge_sl_get_elements()
*     uti/sl/sge_sl_sort()
****************************************************************************/

#define for_each_sl_locked(elem, list) \
   for(sge_sl_lock(list), elem = NULL, sge_sl_elem_next(list, &elem, SGE_SL_FORWARD); \
       elem != NULL || (sge_sl_unlock(list), false); \
       sge_sl_elem_next(list, &elem, SGE_SL_FORWARD))

#define for_each_sl(elem, list) \
   for(elem = NULL, sge_sl_elem_next(list, &elem, SGE_SL_FORWARD); \
       elem != NULL; \
       sge_sl_elem_next(list, &elem, SGE_SL_FORWARD))

typedef int (*sge_sl_compare_f)(const void *data1, const void *data2);

typedef bool (*sge_sl_destroy_f)(void **data);

typedef struct _sge_sl_elem_t sge_sl_elem_t;
typedef struct _sge_sl_list_t sge_sl_list_t;

enum _sge_sl_direction_t {
   SGE_SL_FORWARD,
   SGE_SL_BACKWARD
};

typedef enum _sge_sl_direction_t sge_sl_direction_t;

struct _sge_sl_elem_t {
   sge_sl_elem_t *prev;
   sge_sl_elem_t *next;
   void *data;
};

struct _sge_sl_list_t {
   /* mutex to secure other elements in the struct */
   pthread_mutex_t mutex; 

   /* fist last element pointer and number of elements */
   sge_sl_elem_t *first;
   sge_sl_elem_t *last;
   u_long32 elements;
};

bool
sge_sl_elem_create(sge_sl_elem_t **elem, void *data);

bool
sge_sl_elem_destroy(sge_sl_elem_t **elem, sge_sl_destroy_f destroy);

void * 
sge_sl_elem_data(sge_sl_elem_t *elem);

bool
sge_sl_elem_next(sge_sl_list_t *list, 
                 sge_sl_elem_t **elem, sge_sl_direction_t direction);


bool
sge_sl_elem_search(sge_sl_list_t *list, sge_sl_elem_t **elem, void *data, 
                   sge_sl_compare_f compare, sge_sl_direction_t direction);

bool
sge_sl_create(sge_sl_list_t **list);

bool
sge_sl_destroy(sge_sl_list_t **list, sge_sl_destroy_f destroy);

bool
sge_sl_dechain(sge_sl_list_t *list, sge_sl_elem_t *elem);

bool
sge_sl_insert_before(sge_sl_list_t *list, sge_sl_elem_t *new_elem, sge_sl_elem_t *elem);

bool
sge_sl_append_after(sge_sl_list_t *list, sge_sl_elem_t *new_elem, sge_sl_elem_t *elem);

bool
sge_sl_lock(sge_sl_list_t *list);

bool
sge_sl_unlock(sge_sl_list_t *list);

bool
sge_sl_insert(sge_sl_list_t *list, void *data, sge_sl_direction_t direction);

bool
sge_sl_insert_search(sge_sl_list_t *list, void *data, sge_sl_compare_f compare);

bool
sge_sl_data(sge_sl_list_t *list, void **data, sge_sl_direction_t direction);

bool
sge_sl_data_search(sge_sl_list_t *list, void *key, void **data, 
                   sge_sl_compare_f compare, sge_sl_direction_t direction);

bool
sge_sl_delete(sge_sl_list_t *list, 
              sge_sl_destroy_f destroy, sge_sl_direction_t direction);
  
bool
sge_sl_delete_search(sge_sl_list_t *list, void *key, sge_sl_destroy_f destroy, 
                     sge_sl_compare_f compare, sge_sl_direction_t direction);

u_long32
sge_sl_get_elem_count(sge_sl_list_t *list);

pthread_mutex_t *
sge_sl_get_mutex(sge_sl_list_t *list);

bool
sge_sl_sort(sge_sl_list_t *list, sge_sl_compare_f compare);

#endif