blob: dd2b6db6659f74332cb460dff050e961c70bf883 [file] [log] [blame]
sewardjaf44c822007-11-25 14:01:38 +00001/*
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
50typedef struct
51{
52 ThreadId threadid;
53 UInt count;
54} VCElem;
55
56typedef struct
57{
58 unsigned capacity;
59 unsigned size;
60 VCElem* vc;
61} VectorClock;
62
63
64void vc_init(VectorClock* const vc,
65 const VCElem* const vcelem,
66 const unsigned size);
67void vc_cleanup(VectorClock* const vc);
68void vc_copy(VectorClock* const new,
69 const VectorClock* const rhs);
70void vc_increment(VectorClock* const vc, ThreadId const threadid);
71Bool vc_lte(const VectorClock* const vc1,
72 const VectorClock* const vc2);
73Bool vc_ordered(const VectorClock* const vc1,
74 const VectorClock* const vc2);
75void vc_min(VectorClock* const result,
76 const VectorClock* const rhs);
77void vc_combine(VectorClock* const result,
78 const VectorClock* const rhs);
79void vc_print(const VectorClock* const vc);
80void vc_snprint(Char* const str, Int const size,
81 const VectorClock* const vc);
82void vc_check(const VectorClock* const vc);
83void vc_test(void);
84
85
86#endif /* __DRD_VC_H */