blob: 3737880bf1265824f1a43d514034d07682124b5f [file] [log] [blame]
sewardjaf44c822007-11-25 14:01:38 +00001/*
2 This file is part of drd, a data race detector.
3
sewardj85642922008-01-14 11:54:56 +00004 Copyright (C) 2006-2008 Bart Van Assche
sewardjaf44c822007-11-25 14:01:38 +00005 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;
sewardj85642922008-01-14 11:54:56 +000053 UInt count;
sewardjaf44c822007-11-25 14:01:38 +000054} VCElem;
55
56typedef struct
57{
sewardj85642922008-01-14 11:54:56 +000058 unsigned capacity;
59 unsigned size;
60 VCElem* vc;
sewardjaf44c822007-11-25 14:01:38 +000061} 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);
bartc46c2322008-02-24 18:26:46 +000070void vc_assign(VectorClock* const lhs,
71 const VectorClock* const rhs);
bartf7291972008-04-06 14:57:41 +000072UInt vc_get(VectorClock* const vc, const ThreadId tid);
sewardjaf44c822007-11-25 14:01:38 +000073void vc_increment(VectorClock* const vc, ThreadId const threadid);
74Bool vc_lte(const VectorClock* const vc1,
75 const VectorClock* const vc2);
76Bool vc_ordered(const VectorClock* const vc1,
77 const VectorClock* const vc2);
78void vc_min(VectorClock* const result,
79 const VectorClock* const rhs);
80void vc_combine(VectorClock* const result,
81 const VectorClock* const rhs);
bartf7291972008-04-06 14:57:41 +000082Bool vc_combine2(VectorClock* const result,
83 const VectorClock* const rhs,
84 const ThreadId tid);
sewardjaf44c822007-11-25 14:01:38 +000085void vc_print(const VectorClock* const vc);
86void vc_snprint(Char* const str, Int const size,
87 const VectorClock* const vc);
88void vc_check(const VectorClock* const vc);
89void vc_test(void);
90
91
92#endif /* __DRD_VC_H */