drd/tests/swapcontext: Improve the portability of this test further
[valgrind.git] / drd / drd_segment.h
blob377b1bab86248c127b24332580947d83427f21a8
1 /*
2 This file is part of drd, a thread error detector.
4 Copyright (C) 2006-2020 Bart Van Assche <bvanassche@acm.org>.
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>.
19 The GNU General Public License is contained in the file COPYING.
23 #ifndef __SEGMENT_H
24 #define __SEGMENT_H
28 * Segments and segment lists. A segment represents information about
29 * a contiguous group of statements of a specific thread. There is a vector
30 * clock associated with each segment.
34 #include "drd_vc.h"
35 #include "pub_drd_bitmap.h"
36 #include "pub_tool_execontext.h" // ExeContext
37 #include "pub_tool_stacktrace.h" // StackTrace
40 typedef struct segment
42 struct segment* g_next;
43 struct segment* g_prev;
44 /** Pointers to next and previous segments executed by the same thread. */
45 struct segment* thr_next;
46 struct segment* thr_prev;
47 DrdThreadId tid;
48 /** Reference count: number of pointers that point to this segment. */
49 int refcnt;
50 /** Stack trace of the first instruction of the segment. */
51 ExeContext* stacktrace;
52 /** Vector clock associated with the segment. */
53 VectorClock vc;
54 /**
55 * Bitmap representing the memory accesses by the instructions associated
56 * with the segment.
58 struct bitmap bm;
59 } Segment;
61 extern Segment* DRD_(g_sg_list);
63 Segment* DRD_(sg_new)(const DrdThreadId creator, const DrdThreadId created);
64 static int DRD_(sg_get_refcnt)(const Segment* const sg);
65 Segment* DRD_(sg_get)(Segment* const sg);
66 void DRD_(sg_put)(Segment* const sg);
67 static struct bitmap* DRD_(sg_bm)(Segment* const sg);
68 void DRD_(sg_merge)(Segment* const sg1, Segment* const sg2);
69 void DRD_(sg_print)(Segment* const sg);
70 Bool DRD_(sg_get_trace)(void);
71 void DRD_(sg_set_trace)(const Bool trace_segment);
72 ULong DRD_(sg_get_segments_created_count)(void);
73 ULong DRD_(sg_get_segments_alive_count)(void);
74 ULong DRD_(sg_get_max_segments_alive_count)(void);
75 ULong DRD_(sg_get_segment_merge_count)(void);
78 /** Query the reference count of the specified segment. */
79 static __inline__ int DRD_(sg_get_refcnt)(const Segment* const sg)
81 #ifdef ENABLE_DRD_CONSISTENCY_CHECKS
82 tl_assert(sg);
83 #endif
85 return sg->refcnt;
88 /** Return the pointer to the bitmap of the segment. */
89 static __inline__ struct bitmap* DRD_(sg_bm)(Segment* const sg)
91 #ifdef ENABLE_DRD_CONSISTENCY_CHECKS
92 tl_assert(sg);
93 #endif
95 return &sg->bm;
100 #endif // __SEGMENT_H