sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1 | /* |
| 2 | This file is part of drd, a data race detector. |
| 3 | |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 4 | Copyright (C) 2006-2008 Bart Van Assche |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 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; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 53 | UInt count; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 54 | } VCElem; |
| 55 | |
| 56 | typedef struct |
| 57 | { |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 58 | unsigned capacity; |
| 59 | unsigned size; |
| 60 | VCElem* vc; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 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); |
bart | c46c232 | 2008-02-24 18:26:46 +0000 | [diff] [blame] | 70 | void vc_assign(VectorClock* const lhs, |
| 71 | const VectorClock* const rhs); |
bart | f729197 | 2008-04-06 14:57:41 +0000 | [diff] [blame] | 72 | UInt vc_get(VectorClock* const vc, const ThreadId tid); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 73 | void vc_increment(VectorClock* const vc, ThreadId const threadid); |
| 74 | Bool vc_lte(const VectorClock* const vc1, |
| 75 | const VectorClock* const vc2); |
| 76 | Bool vc_ordered(const VectorClock* const vc1, |
| 77 | const VectorClock* const vc2); |
| 78 | void vc_min(VectorClock* const result, |
| 79 | const VectorClock* const rhs); |
| 80 | void vc_combine(VectorClock* const result, |
| 81 | const VectorClock* const rhs); |
bart | f729197 | 2008-04-06 14:57:41 +0000 | [diff] [blame] | 82 | Bool vc_combine2(VectorClock* const result, |
| 83 | const VectorClock* const rhs, |
| 84 | const ThreadId tid); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 85 | void vc_print(const VectorClock* const vc); |
| 86 | void vc_snprint(Char* const str, Int const size, |
| 87 | const VectorClock* const vc); |
| 88 | void vc_check(const VectorClock* const vc); |
| 89 | void vc_test(void); |
| 90 | |
| 91 | |
| 92 | #endif /* __DRD_VC_H */ |