LogService
libdadi: utility tools for distributed applications
Main Page
Classes
Files
File List
All
Classes
Functions
Variables
src
utils
FullLinkedList.hh
1
/****************************************************************************/
2
/* Thread safe generic Double linked list with full access */
3
/* */
4
/* Author(s): */
5
/* - Georg Hoesch (hoesch@in.tum.de) */
6
/* - Cyrille Pontvieux (cyrille.pontvieux@edu.univ-fcomte.fr) */
7
/* */
8
/* This file is part of DIET . */
9
/* */
10
/* Copyright (C) 2000-2003 ENS Lyon, LIFC, INSA, INRIA and SysFera (2000) */
11
/* */
12
/* - Frederic.Desprez@ens-lyon.fr (Project Manager) */
13
/* - Eddy.Caron@ens-lyon.fr (Technical Manager) */
14
/* - Tech@sysfera.com (Maintainer and Technical Support) */
15
/* */
16
/* This software is a computer program whose purpose is to provide an */
17
/* distributed logging services. */
18
/* */
19
/* */
20
/* This software is governed by the CeCILL license under French law and */
21
/* abiding by the rules of distribution of free software. You can use, */
22
/* modify and/ or redistribute the software under the terms of the CeCILL */
23
/* license as circulated by CEA, CNRS and INRIA at the following URL */
24
/* "http://www.cecill.info". */
25
/* */
26
/* As a counterpart to the access to the source code and rights to copy, */
27
/* modify and redistribute granted by the license, users are provided */
28
/* only with a limited warranty and the software's author, the holder */
29
/* of the economic rights, and the successive licensors have only */
30
/* limited liability. */
31
/* */
32
/* In this respect, the user's attention is drawn to the risks */
33
/* associated with loading, using, modifying and/or developing or */
34
/* reproducing the software by the user in light of its specific status */
35
/* of free software, that may mean that it is complicated to */
36
/* manipulate, and that also therefore means that it is reserved for */
37
/* developers and experienced professionals having in-depth computer */
38
/* knowledge. Users are therefore encouraged to load and test the */
39
/* software's suitability as regards their requirements in conditions */
40
/* enabling the security of their systems and/or data to be ensured and, */
41
/* more generally, to use and operate it in the same conditions as */
42
/* regards security. */
43
/* */
44
/* The fact that you are presently reading this means that you have had */
45
/* knowledge of the CeCILL license and that you accept its terms. */
46
/* */
47
/****************************************************************************/
48
/* $Id$
49
* $Log$
50
* Revision 1.2 2006/06/01 16:13:47 rbolze
51
* change to be able to compile with gcc-4
52
* Thanks to Abdelkader Amar who has done the work.
53
*
54
* Revision 1.1 2004/01/09 11:07:12 ghoesch
55
* Restructured the whole LogService source tree.
56
* Added autotools make process. Cleaned up code.
57
* Removed some testers. Ready to release.
58
*
59
****************************************************************************/
60
61
#ifndef _FULLLINKEDLIST_HH_
62
#define _FULLLINKEDLIST_HH_
63
64
#include <omnithread.h>
65
#include <sys/types.h>
66
#include <assert.h>
67
68
69
class
Node;
70
/****************************************************************************
71
* This is a thread safe generic double linked list. It offers ReadWrite
72
* and Readonly access to the list with the two iterators Iterator and
73
* ReadIterator. Several Readers can exist at a time, while writers have
74
* exclusive access to the list. Other iterators created in this time
75
* will be blocked until the active iterator is deleted, so don't keep
76
* your iterators to long. Write iterators have the possibility to
77
* release their write-rights and become a read iterator without
78
* releasing their read lock.
79
*
80
* The current implementation of this list does not distinguish between
81
* readers and writers, but the behaviour can be implemented by changing
82
* the functions lockReadWrite, lockRead, unlockRead and unlockWrite.
83
*
84
* This list deals with a copy of all the elements (T) but you can also use
85
* some special functions to deal with references, but use them carrefully.
86
*/
87
template
<
class
T>
88
class
FullLinkedList
{
89
// FIXME: relocate this
93
struct
Node {
97
Node* next;
101
Node* previous;
105
T* element;
106
};
107
108
public
:
109
/*****************************************************************************
110
* PUBLIC METHODS
111
****************************************************************************/
112
class
ReadIterator
;
113
class
Iterator
;
114
118
FullLinkedList
();
119
124
explicit
FullLinkedList
(
FullLinkedList<T>
& newFLL);
125
130
~FullLinkedList
();
131
135
FullLinkedList<T>
&
136
operator =
(
FullLinkedList<T>
& newFLL);
137
143
void
144
emptyIt
();
145
153
void
154
push
(T* element);
155
164
void
165
pushRef
(T* element);
166
174
void
175
shift
(T* element);
176
185
void
186
shiftRef
(T* element);
187
195
T*
196
pop
();
197
205
T*
206
unshift
();
207
216
void
217
appendList
(
FullLinkedList<T>
* list);
218
227
Iterator
*
228
getIterator
();
229
238
ReadIterator
*
239
getReadIterator
();
240
250
ReadIterator
*
251
reduceWriteIterator
(
Iterator
* rwIterator);
252
253
/*****************************************************************************
254
* ITERATOR SECTION - INNER CLASSES
255
****************************************************************************/
256
public
:
263
class
ReadIterator
{
264
// these two are necessary for the private constructors
265
friend
class
FullLinkedList
;
266
/***************************************************************************
267
* PUBLIC METHODS
268
**************************************************************************/
269
public
:
277
virtual
278
~ReadIterator
();
279
284
inline
void
285
reset
();
286
291
inline
void
292
resetToLast
();
293
297
inline
bool
298
hasCurrent
();
299
304
inline
bool
305
hasNext
();
306
311
inline
bool
312
hasPrevious
();
313
319
inline
T*
320
getCurrent
();
321
329
inline
T*
330
getCurrentRef
();
331
336
inline
T*
337
next
();
338
344
inline
T*
345
nextRef
();
346
351
inline
T*
352
previous
();
353
359
inline
T*
360
previousRef
();
361
365
inline
unsigned
int
366
length
();
367
368
/***************************************************************************
369
* PROTECTED METHODS
370
**************************************************************************/
371
protected
:
377
explicit
ReadIterator
(
FullLinkedList
* controlledList);
378
379
/***************************************************************************
380
* PROTECTED FIELDS
381
**************************************************************************/
385
FullLinkedList
*
linkedList
;
386
390
// FullLinkedList::Node* currentNode;
391
Node*
currentNode
;
392
401
bool
noReadRelease
;
402
};
403
404
412
class
Iterator
:
public
FullLinkedList::ReadIterator
{
413
friend
class
FullLinkedList
;
414
/***************************************************************************
415
* PUBLIC METHODS
416
**************************************************************************/
417
public
:
424
virtual
425
~Iterator
();
426
434
void
435
removeCurrent
();
436
447
T*
448
removeAndGetCurrent
();
449
461
void
462
insertAfter
(T* element);
463
474
void
475
insertAfterRef
(T* element);
476
488
void
489
insertBefore
(T* element);
490
501
void
502
insertBeforeRef
(T* element);
503
504
/***************************************************************************
505
* PRIVATE METHODS
506
**************************************************************************/
507
private
:
513
explicit
Iterator
(
FullLinkedList
* controlledList);
514
};
// end of inner class Iterator
515
516
/*****************************************************************************
517
* PRIVATE METHODS
518
****************************************************************************/
519
private
:
520
void
521
operatorEqualPrivate(
FullLinkedList<T>
& newFLL);
522
523
void
524
emptyItPrivate();
525
526
void
527
appendListPrivate(
FullLinkedList<T>
* list);
528
534
void
535
lockReadWrite();
536
541
void
542
lockRead();
543
548
void
549
unlockWrite();
550
555
void
556
unlockRead();
557
562
void
563
unlockReadWrite();
564
565
/*****************************************************************************
566
* PRIVATE FIELDS
567
****************************************************************************/
571
long
counter;
572
576
Node* first;
577
582
Node* last;
583
588
mutable
omni_mutex writerMutex;
589
594
int
readerCount;
595
599
mutable
omni_mutex readerCountMutex;
600
605
mutable
omni_mutex readersExistMutex;
606
};
607
612
#include "FullLinkedList.cc"
613
614
#endif // _FULLLINKEDLIST_HH_
Generated on Mon Aug 19 2013 21:50:34 for LogService by
1.8.4