blob: 09f248ccd512ab9ccde74259eb1e3daaf28421b5 [file] [log] [blame]
bartbedfd232009-03-26 19:07:15 +00001/* -*- mode: C; c-basic-offset: 3; -*- */
sewardjaf44c822007-11-25 14:01:38 +00002/*
bart86562bd2009-02-16 19:43:56 +00003 This file is part of drd, a thread error detector.
sewardjaf44c822007-11-25 14:01:38 +00004
bart86562bd2009-02-16 19:43:56 +00005 Copyright (C) 2006-2009 Bart Van Assche <bart.vanassche@gmail.com>.
sewardjaf44c822007-11-25 14:01:38 +00006
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 __SEGMENT_H
27#define __SEGMENT_H
28
29
bart62ada3f2009-02-14 17:19:58 +000030/*
31 * Segments and segment lists. A segment represents information about
32 * a contiguous group of statements of a specific thread. There is a vector
33 * clock associated with each segment.
34 */
sewardjaf44c822007-11-25 14:01:38 +000035
36
37#include "drd_vc.h"
38#include "pub_drd_bitmap.h"
39#include "pub_tool_execontext.h" // ExeContext
40#include "pub_tool_stacktrace.h" // StackTrace
41
42
43typedef struct segment
44{
bartbedfd232009-03-26 19:07:15 +000045 /** Pointers to next and previous segments executed by the same thread. */
46 struct segment* next;
47 struct segment* prev;
bart8f822af2009-06-08 18:20:42 +000048 DrdThreadId tid;
bartbedfd232009-03-26 19:07:15 +000049 /** Reference count: number of pointers that point to this segment. */
50 int refcnt;
51 /** Stack trace of the first instruction of the segment. */
52 ExeContext* stacktrace;
53 /** Vector clock associated with the segment. */
54 VectorClock vc;
55 /**
56 * Bitmap representing the memory accesses by the instructions associated
57 * with the segment.
58 */
bart8f822af2009-06-08 18:20:42 +000059 struct bitmap bm;
sewardjaf44c822007-11-25 14:01:38 +000060} Segment;
61
barta2b6e1b2008-03-17 18:32:39 +000062
bart2adfc2a2009-03-12 18:38:00 +000063Segment* DRD_(sg_new)(const DrdThreadId creator, const DrdThreadId created);
bart8f822af2009-06-08 18:20:42 +000064static int DRD_(sg_get_refcnt)(const Segment* const sg);
bart62ada3f2009-02-14 17:19:58 +000065Segment* DRD_(sg_get)(Segment* const sg);
66void DRD_(sg_put)(Segment* const sg);
bart8f822af2009-06-08 18:20:42 +000067static struct bitmap* DRD_(sg_bm)(Segment* const sg);
68void DRD_(sg_merge)(Segment* const sg1, Segment* const sg2);
69void DRD_(sg_print)(Segment* const sg);
bart62ada3f2009-02-14 17:19:58 +000070Bool DRD_(sg_get_trace)(void);
71void DRD_(sg_set_trace)(const Bool trace_segment);
72ULong DRD_(sg_get_segments_created_count)(void);
73ULong DRD_(sg_get_segments_alive_count)(void);
74ULong DRD_(sg_get_max_segments_alive_count)(void);
bart1a3b0b32009-05-03 17:07:34 +000075ULong DRD_(sg_get_segment_merge_count)(void);
sewardjaf44c822007-11-25 14:01:38 +000076
77
bart8f822af2009-06-08 18:20:42 +000078/** Query the reference count of the specified segment. */
79static __inline__ int DRD_(sg_get_refcnt)(const Segment* const sg)
80{
81#ifdef ENABLE_DRD_CONSISTENCY_CHECKS
82 tl_assert(sg);
83#endif
84
85 return sg->refcnt;
86}
87
88/** Return the pointer to the bitmap of the segment. */
89static __inline__ struct bitmap* DRD_(sg_bm)(Segment* const sg)
90{
91#ifdef ENABLE_DRD_CONSISTENCY_CHECKS
92 tl_assert(sg);
93#endif
94
95 return &sg->bm;
96}
97
98
99
sewardjaf44c822007-11-25 14:01:38 +0000100#endif // __SEGMENT_H