~bkerensa/ubuntu/raring/valgrind/merge-from-deb

« back to all changes in this revision

Viewing changes to exp-drd/drd_vc.h

  • Committer: Bazaar Package Importer
  • Author(s): Andrés Roldán
  • Date: 2008-06-13 02:31:40 UTC
  • mto: (1.4.1 upstream) (2.2.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: james.westby@ubuntu.com-20080613023140-iwk33rz9rhvfkr96
Import upstream version 3.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  This file is part of drd, a data race detector.
 
3
 
 
4
  Copyright (C) 2006-2007 Bart Van Assche
 
5
  bart.vanassche@gmail.com
 
6
 
 
7
  This program is free software; you can redistribute it and/or
 
8
  modify it under the terms of the GNU General Public License as
 
9
  published by the Free Software Foundation; either version 2 of the
 
10
  License, or (at your option) any later version.
 
11
 
 
12
  This program is distributed in the hope that it will be useful, but
 
13
  WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
  General Public License for more details.
 
16
 
 
17
  You should have received a copy of the GNU General Public License
 
18
  along with this program; if not, write to the Free Software
 
19
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 
20
  02111-1307, USA.
 
21
 
 
22
  The GNU General Public License is contained in the file COPYING.
 
23
*/
 
24
 
 
25
 
 
26
#ifndef __DRD_VC_H
 
27
#define __DRD_VC_H
 
28
 
 
29
 
 
30
// DRD vector clock implementation:
 
31
// - One counter per thread.
 
32
// - A vector clock is implemented as multiple pairs of (thread id, counter).
 
33
// - Pairs are stored in an array sorted by thread id.
 
34
// Semantics:
 
35
// - Each time a thread performs an action that implies an ordering between
 
36
//   intra-thread events, the counter of that thread is incremented.
 
37
// - Vector clocks are compared by comparing all counters of all threads.
 
38
// - When a thread synchronization action is performed that guarantees that
 
39
//   new actions of the current thread are executed after the actions of the
 
40
//   other thread, the vector clock of the synchronization object and the 
 
41
//   current thread are combined (by taking the component-wise maximum).
 
42
// - A vector clock is incremented during actions such as
 
43
//   pthread_create(), pthread_mutex_unlock(), sem_post(). (Actions where
 
44
//   an inter-thread ordering "arrow" starts).
 
45
 
 
46
 
 
47
#include "pub_tool_basics.h"    // Addr, SizeT
 
48
 
 
49
 
 
50
typedef struct
 
51
{
 
52
  ThreadId threadid;
 
53
  UInt count;
 
54
} VCElem;
 
55
 
 
56
typedef struct
 
57
{
 
58
  unsigned       capacity;
 
59
  unsigned       size;
 
60
  VCElem* vc;
 
61
} VectorClock;
 
62
 
 
63
 
 
64
void vc_init(VectorClock* const vc,
 
65
             const VCElem* const vcelem,
 
66
             const unsigned size);
 
67
void vc_cleanup(VectorClock* const vc);
 
68
void vc_copy(VectorClock* const new,
 
69
             const VectorClock* const rhs);
 
70
void vc_increment(VectorClock* const vc, ThreadId const threadid);
 
71
Bool vc_lte(const VectorClock* const vc1,
 
72
            const VectorClock* const vc2);
 
73
Bool vc_ordered(const VectorClock* const vc1,
 
74
                const VectorClock* const vc2);
 
75
void vc_min(VectorClock* const result,
 
76
            const VectorClock* const rhs);
 
77
void vc_combine(VectorClock* const result,
 
78
                const VectorClock* const rhs);
 
79
void vc_print(const VectorClock* const vc);
 
80
void vc_snprint(Char* const str, Int const size,
 
81
                const VectorClock* const vc);
 
82
void vc_check(const VectorClock* const vc);
 
83
void vc_test(void);
 
84
 
 
85
 
 
86
#endif /* __DRD_VC_H */