blob: b91caa9249df0ea58b131b9b0e55212a99d5e37b [file] [log] [blame]
sewardjaf44c822007-11-25 14:01:38 +00001/*
bart86562bd2009-02-16 19:43:56 +00002 This file is part of drd, a thread error detector.
sewardjaf44c822007-11-25 14:01:38 +00003
Elliott Hughesed398002017-06-21 14:41:24 -07004 Copyright (C) 2006-2017 Bart Van Assche <bvanassche@acm.org>.
sewardjaf44c822007-11-25 14:01:38 +00005
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.
10
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.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307, USA.
20
21 The GNU General Public License is contained in the file COPYING.
22*/
23
24
25#ifndef __THREAD_H
26#define __THREAD_H
27
28
bart324a23b2009-02-15 12:14:52 +000029/* Include directives. */
sewardjaf44c822007-11-25 14:01:38 +000030
bart09dc13f2009-02-14 15:13:31 +000031#include "drd_basics.h"
bartf00a85b2008-03-13 18:49:23 +000032#include "drd_segment.h"
bartd59bb0f2008-06-08 08:08:31 +000033#include "pub_drd_bitmap.h"
bart86a87df2009-03-04 19:26:47 +000034#include "pub_tool_libcassert.h" /* tl_assert() */
35#include "pub_tool_stacktrace.h" /* typedef StackTrace */
36#include "pub_tool_threadstate.h" /* VG_N_THREADS */
bartf00a85b2008-03-13 18:49:23 +000037
38
bart324a23b2009-02-15 12:14:52 +000039/* Defines. */
bartf00a85b2008-03-13 18:49:23 +000040
bart86a87df2009-03-04 19:26:47 +000041/** Maximum number of threads DRD keeps information about. */
bartf00a85b2008-03-13 18:49:23 +000042#define DRD_N_THREADS VG_N_THREADS
sewardjaf44c822007-11-25 14:01:38 +000043
bart86a87df2009-03-04 19:26:47 +000044/** A number different from any valid DRD thread ID. */
sewardjaf44c822007-11-25 14:01:38 +000045#define DRD_INVALID_THREADID 0
46
bart86a87df2009-03-04 19:26:47 +000047/**
48 * A number different from any valid POSIX thread ID.
49 *
50 * @note The PThreadId typedef and the INVALID_POSIX_THREADID depend on the
51 * operating system and threading library in use. PThreadId must contain at
52 * least as many bits as pthread_t, and INVALID_POSIX_THREADID
53 * must be a value that will never be returned by pthread_self().
54 */
sewardjaf44c822007-11-25 14:01:38 +000055#define INVALID_POSIX_THREADID ((PThreadId)0)
56
57
bart324a23b2009-02-15 12:14:52 +000058/* Type definitions. */
bartf00a85b2008-03-13 18:49:23 +000059
bart86a87df2009-03-04 19:26:47 +000060/**
61 * POSIX thread ID. The type PThreadId must be at least as wide as
62 * pthread_t.
63 */
sewardjaf44c822007-11-25 14:01:38 +000064typedef UWord PThreadId;
65
bart86a87df2009-03-04 19:26:47 +000066/** Per-thread information managed by DRD. */
bartf00a85b2008-03-13 18:49:23 +000067typedef struct
68{
bart91b7ec32012-01-25 20:36:27 +000069 struct segment* sg_first;/**< Segment list. */
70 struct segment* sg_last;
bartbedfd232009-03-26 19:07:15 +000071 ThreadId vg_threadid; /**< Valgrind thread ID. */
72 PThreadId pt_threadid; /**< POSIX thread ID. */
73 Addr stack_min_min; /**< Lowest value stack pointer ever had. */
74 Addr stack_min; /**< Current stack pointer. */
75 Addr stack_startup; /**<Stack pointer after pthread_create() finished.*/
76 Addr stack_max; /**< Top of stack. */
77 SizeT stack_size; /**< Maximum size of stack. */
florian19f91bb2012-11-10 22:29:54 +000078 HChar name[64]; /**< User-assigned thread name. */
bart383d6132010-09-02 14:43:18 +000079 Bool on_alt_stack;
bart6d956dc2011-07-28 09:54:37 +000080 /** Whether this structure contains valid information. */
81 Bool valid;
bartbedfd232009-03-26 19:07:15 +000082 /** Indicates whether the Valgrind core knows about this thread. */
83 Bool vg_thread_exists;
84 /** Indicates whether there is an associated POSIX thread ID. */
85 Bool posix_thread_exists;
86 /**
87 * If true, indicates that there is a corresponding POSIX thread ID and
88 * a corresponding OS thread that is detached.
89 */
90 Bool detached_posix_thread;
Elliott Hughesed398002017-06-21 14:41:24 -070091 /** Whether recording of memory load accesses is currently enabled. */
bartd45d9952009-05-31 18:53:54 +000092 Bool is_recording_loads;
Elliott Hughesed398002017-06-21 14:41:24 -070093 /** Whether recording of memory load accesses is currently enabled. */
bartd45d9952009-05-31 18:53:54 +000094 Bool is_recording_stores;
bartdd75cdf2009-07-24 08:20:10 +000095 /** pthread_create() nesting level. */
96 Int pthread_create_nesting_level;
bartbedfd232009-03-26 19:07:15 +000097 /** Nesting level of synchronization functions called by the client. */
98 Int synchr_nesting;
bart6d956dc2011-07-28 09:54:37 +000099 /** Delayed thread deletion sequence number. */
100 unsigned deletion_seq;
sewardj8eb8bab2015-07-21 14:44:28 +0000101 /**
102 * ID of the creator thread. It can be safely accessed only until the
103 * thread is fully created. Then the creator thread lives its own life again.
104 */
105 DrdThreadId creator_thread;
106
107#if defined(VGO_solaris)
108 Int bind_guard_flag; /**< Bind flag from the runtime linker. */
109#endif /* VGO_solaris */
bartf00a85b2008-03-13 18:49:23 +0000110} ThreadInfo;
111
112
bart324a23b2009-02-15 12:14:52 +0000113/*
114 * Local variables of drd_thread.c that are declared here such that these
115 * can be accessed by inline functions.
116 */
bartf00a85b2008-03-13 18:49:23 +0000117
bart86a87df2009-03-04 19:26:47 +0000118/**
119 * DRD thread ID of the currently running thread. It is crucial for correct
120 * operation of DRD that this number is always in sync with
121 * VG_(get_running_tid)().
122 */
bart324a23b2009-02-15 12:14:52 +0000123extern DrdThreadId DRD_(g_drd_running_tid);
bart86a87df2009-03-04 19:26:47 +0000124/** Per-thread information managed by DRD. */
florian1e802b62015-02-13 19:08:26 +0000125extern ThreadInfo* DRD_(g_threadinfo);
bart86a87df2009-03-04 19:26:47 +0000126/** Conflict set for the currently running thread. */
bart324a23b2009-02-15 12:14:52 +0000127extern struct bitmap* DRD_(g_conflict_set);
bart9cdc0832014-08-09 12:58:17 +0000128extern Bool DRD_(verify_conflict_set);
sewardj8eb8bab2015-07-21 14:44:28 +0000129/** Whether activities during thread creation should be ignored. */
130extern Bool DRD_(ignore_thread_creation);
bartf00a85b2008-03-13 18:49:23 +0000131
132
bart324a23b2009-02-15 12:14:52 +0000133/* Function declarations. */
sewardjaf44c822007-11-25 14:01:38 +0000134
bart62a784c2009-02-15 13:11:14 +0000135void DRD_(thread_trace_context_switches)(const Bool t);
136void DRD_(thread_trace_conflict_set)(const Bool t);
bart8f822af2009-06-08 18:20:42 +0000137void DRD_(thread_trace_conflict_set_bm)(const Bool t);
bart09dc13f2009-02-14 15:13:31 +0000138Bool DRD_(thread_get_trace_fork_join)(void);
139void DRD_(thread_set_trace_fork_join)(const Bool t);
bart62a784c2009-02-15 13:11:14 +0000140void DRD_(thread_set_segment_merging)(const Bool m);
bart8f822af2009-06-08 18:20:42 +0000141int DRD_(thread_get_segment_merge_interval)(void);
142void DRD_(thread_set_segment_merge_interval)(const int i);
bart6d956dc2011-07-28 09:54:37 +0000143void DRD_(thread_set_join_list_vol)(const int jlv);
sewardjaf44c822007-11-25 14:01:38 +0000144
barte278ab52012-01-24 18:28:55 +0000145void DRD_(thread_init)(void);
bart62a784c2009-02-15 13:11:14 +0000146DrdThreadId DRD_(VgThreadIdToDrdThreadId)(const ThreadId tid);
147DrdThreadId DRD_(NewVgThreadIdToDrdThreadId)(const ThreadId tid);
148DrdThreadId DRD_(PtThreadIdToDrdThreadId)(const PThreadId tid);
149ThreadId DRD_(DrdThreadIdToVgThreadId)(const DrdThreadId tid);
150DrdThreadId DRD_(thread_pre_create)(const DrdThreadId creator,
bartbedfd232009-03-26 19:07:15 +0000151 const ThreadId vg_created);
bart62a784c2009-02-15 13:11:14 +0000152DrdThreadId DRD_(thread_post_create)(const ThreadId vg_created);
bart09dc13f2009-02-14 15:13:31 +0000153void DRD_(thread_post_join)(DrdThreadId drd_joiner, DrdThreadId drd_joinee);
bart9194e932011-02-09 11:55:12 +0000154void DRD_(thread_delete)(const DrdThreadId tid, Bool detached);
bart62a784c2009-02-15 13:11:14 +0000155void DRD_(thread_finished)(const DrdThreadId tid);
bart5c7e6b62011-02-03 17:47:50 +0000156void DRD_(drd_thread_atfork_child)(const DrdThreadId tid);
bart62a784c2009-02-15 13:11:14 +0000157void DRD_(thread_pre_cancel)(const DrdThreadId tid);
bartbedfd232009-03-26 19:07:15 +0000158void DRD_(thread_set_stack_startup)(const DrdThreadId tid,
159 const Addr stack_startup);
bart62a784c2009-02-15 13:11:14 +0000160Addr DRD_(thread_get_stack_min)(const DrdThreadId tid);
161Addr DRD_(thread_get_stack_min_min)(const DrdThreadId tid);
162Addr DRD_(thread_get_stack_max)(const DrdThreadId tid);
163SizeT DRD_(thread_get_stack_size)(const DrdThreadId tid);
bart383d6132010-09-02 14:43:18 +0000164Bool DRD_(thread_get_on_alt_stack)(const DrdThreadId tid);
165void DRD_(thread_set_on_alt_stack)(const DrdThreadId tid,
166 const Bool on_alt_stack);
167Int DRD_(thread_get_threads_on_alt_stack)(void);
bart62a784c2009-02-15 13:11:14 +0000168void DRD_(thread_set_pthreadid)(const DrdThreadId tid, const PThreadId ptid);
169Bool DRD_(thread_get_joinable)(const DrdThreadId tid);
170void DRD_(thread_set_joinable)(const DrdThreadId tid, const Bool joinable);
bartdd75cdf2009-07-24 08:20:10 +0000171void DRD_(thread_entering_pthread_create)(const DrdThreadId tid);
172void DRD_(thread_left_pthread_create)(const DrdThreadId tid);
sewardj8eb8bab2015-07-21 14:44:28 +0000173#if defined(VGO_solaris)
174void DRD_(thread_entering_rtld_bind_guard)(const DrdThreadId tid, int flags);
175void DRD_(thread_leaving_rtld_bind_clear)(const DrdThreadId tid, int flags);
176#endif /* VGO_solaris */
florian19f91bb2012-11-10 22:29:54 +0000177const HChar* DRD_(thread_get_name)(const DrdThreadId tid);
178void DRD_(thread_set_name)(const DrdThreadId tid, const HChar* const name);
bart62a784c2009-02-15 13:11:14 +0000179void DRD_(thread_set_vg_running_tid)(const ThreadId vg_tid);
180void DRD_(thread_set_running_tid)(const ThreadId vg_tid,
bartbedfd232009-03-26 19:07:15 +0000181 const DrdThreadId drd_tid);
bart62a784c2009-02-15 13:11:14 +0000182int DRD_(thread_enter_synchr)(const DrdThreadId tid);
183int DRD_(thread_leave_synchr)(const DrdThreadId tid);
184int DRD_(thread_get_synchr_nesting_count)(const DrdThreadId tid);
185void DRD_(thread_new_segment)(const DrdThreadId tid);
186VectorClock* DRD_(thread_get_vc)(const DrdThreadId tid);
187void DRD_(thread_get_latest_segment)(Segment** sg, const DrdThreadId tid);
bart8f822af2009-06-08 18:20:42 +0000188void DRD_(thread_combine_vc_join)(const DrdThreadId joiner,
189 const DrdThreadId joinee);
bartf6ec1fe2009-06-21 18:07:35 +0000190void DRD_(thread_new_segment_and_combine_vc)(DrdThreadId tid,
191 const Segment* sg);
bart8f822af2009-06-08 18:20:42 +0000192void DRD_(thread_update_conflict_set)(const DrdThreadId tid,
193 const VectorClock* const old_vc);
bartdfbae6e2008-06-05 08:29:53 +0000194
bart23ef19d2011-03-12 12:34:44 +0000195void DRD_(thread_stop_using_mem)(const Addr a1, const Addr a2);
bartd45d9952009-05-31 18:53:54 +0000196void DRD_(thread_set_record_loads)(const DrdThreadId tid, const Bool enabled);
197void DRD_(thread_set_record_stores)(const DrdThreadId tid, const Bool enabled);
bart62a784c2009-02-15 13:11:14 +0000198void DRD_(thread_print_all)(void);
199void DRD_(thread_report_races)(const DrdThreadId tid);
200void DRD_(thread_report_races_segment)(const DrdThreadId tid,
bartbedfd232009-03-26 19:07:15 +0000201 const Segment* const p);
bart62a784c2009-02-15 13:11:14 +0000202void DRD_(thread_report_all_races)(void);
203void DRD_(thread_report_conflicting_segments)(const DrdThreadId tid,
bartbedfd232009-03-26 19:07:15 +0000204 const Addr addr,
205 const SizeT size,
206 const BmAccessTypeT access_type);
bart62a784c2009-02-15 13:11:14 +0000207ULong DRD_(thread_get_context_switch_count)(void);
208ULong DRD_(thread_get_report_races_count)(void);
209ULong DRD_(thread_get_discard_ordered_segments_count)(void);
bart54803fe2009-06-21 09:26:27 +0000210ULong DRD_(thread_get_compute_conflict_set_count)(void);
211ULong DRD_(thread_get_update_conflict_set_count)(void);
barte5214662009-06-21 11:51:23 +0000212ULong DRD_(thread_get_update_conflict_set_new_sg_count)(void);
213ULong DRD_(thread_get_update_conflict_set_sync_count)(void);
214ULong DRD_(thread_get_update_conflict_set_join_count)(void);
bart62a784c2009-02-15 13:11:14 +0000215ULong DRD_(thread_get_conflict_set_bitmap_creation_count)(void);
216ULong DRD_(thread_get_conflict_set_bitmap2_creation_count)(void);
sewardjaf44c822007-11-25 14:01:38 +0000217
218
bart324a23b2009-02-15 12:14:52 +0000219/* Inline function definitions. */
220
bart86a87df2009-03-04 19:26:47 +0000221/**
222 * Whether or not the specified DRD thread ID is valid.
223 *
224 * A DRD thread ID is valid if and only if the following conditions are met:
225 * - The ID is a valid index of the DRD_(g_threadinfo)[] array.
226 * - The ID is not equal to DRD_INVALID_THREADID.
227 * - The ID refers either to a thread known by the Valgrind core, a joinable
228 * thread that has not yet been joined or a detached thread.
229 */
bartbf80e122008-06-06 10:18:24 +0000230static __inline__
bart62a784c2009-02-15 13:11:14 +0000231Bool DRD_(IsValidDrdThreadId)(const DrdThreadId tid)
bartbf80e122008-06-06 10:18:24 +0000232{
bartbedfd232009-03-26 19:07:15 +0000233 return (0 <= (int)tid && tid < DRD_N_THREADS && tid != DRD_INVALID_THREADID
bart6d956dc2011-07-28 09:54:37 +0000234 && (DRD_(g_threadinfo)[tid].valid));
bartbf80e122008-06-06 10:18:24 +0000235}
236
bart86a87df2009-03-04 19:26:47 +0000237/** Returns the DRD thread ID of the currently running thread. */
bart08865622008-06-06 14:31:36 +0000238static __inline__
bart62a784c2009-02-15 13:11:14 +0000239DrdThreadId DRD_(thread_get_running_tid)(void)
bart1ea5fff2008-03-16 08:36:23 +0000240{
bartdd75cdf2009-07-24 08:20:10 +0000241#ifdef ENABLE_DRD_CONSISTENCY_CHECKS
bartbedfd232009-03-26 19:07:15 +0000242 tl_assert(DRD_(g_drd_running_tid) != DRD_INVALID_THREADID);
bartdd75cdf2009-07-24 08:20:10 +0000243#endif
bartbedfd232009-03-26 19:07:15 +0000244 return DRD_(g_drd_running_tid);
bart1ea5fff2008-03-16 08:36:23 +0000245}
246
bart86a87df2009-03-04 19:26:47 +0000247/** Returns a pointer to the conflict set for the currently running thread. */
bart08865622008-06-06 14:31:36 +0000248static __inline__
bart62a784c2009-02-15 13:11:14 +0000249struct bitmap* DRD_(thread_get_conflict_set)(void)
bart1a473c72008-03-13 19:03:38 +0000250{
bartbedfd232009-03-26 19:07:15 +0000251 return DRD_(g_conflict_set);
bart1a473c72008-03-13 19:03:38 +0000252}
253
bart86a87df2009-03-04 19:26:47 +0000254/**
bartdd75cdf2009-07-24 08:20:10 +0000255 * Reports whether or not the currently running client thread is executing code
256 * inside the pthread_create() function.
257 */
258static __inline__
259Bool DRD_(running_thread_inside_pthread_create)(void)
260{
261 return (DRD_(g_threadinfo)[DRD_(g_drd_running_tid)]
262 .pthread_create_nesting_level > 0);
263}
264
265/**
bart31b983d2010-02-21 14:52:59 +0000266 * Reports whether or not recording of memory loads is enabled for the
bartdd75cdf2009-07-24 08:20:10 +0000267 * currently running client thread.
bart86a87df2009-03-04 19:26:47 +0000268 */
bart08865622008-06-06 14:31:36 +0000269static __inline__
bartd45d9952009-05-31 18:53:54 +0000270Bool DRD_(running_thread_is_recording_loads)(void)
bartf00a85b2008-03-13 18:49:23 +0000271{
bart8b4b2ee2008-06-11 13:17:56 +0000272#ifdef ENABLE_DRD_CONSISTENCY_CHECKS
bartbedfd232009-03-26 19:07:15 +0000273 tl_assert(0 <= (int)DRD_(g_drd_running_tid)
274 && DRD_(g_drd_running_tid) < DRD_N_THREADS
275 && DRD_(g_drd_running_tid) != DRD_INVALID_THREADID);
bart589f9482008-06-09 15:08:22 +0000276#endif
bartbedfd232009-03-26 19:07:15 +0000277 return (DRD_(g_threadinfo)[DRD_(g_drd_running_tid)].synchr_nesting == 0
bartd45d9952009-05-31 18:53:54 +0000278 && DRD_(g_threadinfo)[DRD_(g_drd_running_tid)].is_recording_loads);
279}
280
bartdd75cdf2009-07-24 08:20:10 +0000281/**
bart31b983d2010-02-21 14:52:59 +0000282 * Reports whether or not recording memory stores is enabled for the
bartdd75cdf2009-07-24 08:20:10 +0000283 * currently running client thread.
284 */
bartd45d9952009-05-31 18:53:54 +0000285static __inline__
286Bool DRD_(running_thread_is_recording_stores)(void)
287{
288#ifdef ENABLE_DRD_CONSISTENCY_CHECKS
289 tl_assert(0 <= (int)DRD_(g_drd_running_tid)
290 && DRD_(g_drd_running_tid) < DRD_N_THREADS
291 && DRD_(g_drd_running_tid) != DRD_INVALID_THREADID);
292#endif
293 return (DRD_(g_threadinfo)[DRD_(g_drd_running_tid)].synchr_nesting == 0
294 && DRD_(g_threadinfo)[DRD_(g_drd_running_tid)].is_recording_stores);
bart1a473c72008-03-13 19:03:38 +0000295}
296
bart86a87df2009-03-04 19:26:47 +0000297/**
298 * Update the information about the lowest stack address that has ever been
299 * accessed by a thread.
300 */
bart08865622008-06-06 14:31:36 +0000301static __inline__
bart62a784c2009-02-15 13:11:14 +0000302void DRD_(thread_set_stack_min)(const DrdThreadId tid, const Addr stack_min)
bart1ea5fff2008-03-16 08:36:23 +0000303{
bart8b4b2ee2008-06-11 13:17:56 +0000304#ifdef ENABLE_DRD_CONSISTENCY_CHECKS
bartbedfd232009-03-26 19:07:15 +0000305 tl_assert(0 <= (int)tid
306 && tid < DRD_N_THREADS
307 && tid != DRD_INVALID_THREADID);
bart1ea5fff2008-03-16 08:36:23 +0000308#endif
bartbedfd232009-03-26 19:07:15 +0000309 DRD_(g_threadinfo)[tid].stack_min = stack_min;
bart8b4b2ee2008-06-11 13:17:56 +0000310#ifdef ENABLE_DRD_CONSISTENCY_CHECKS
bartbedfd232009-03-26 19:07:15 +0000311 /* This function can be called after the thread has been created but */
312 /* before drd_post_thread_create() has filled in stack_max. */
313 tl_assert(DRD_(g_threadinfo)[tid].stack_min
bartcaefb282014-03-12 14:27:49 +0000314 <= DRD_(g_threadinfo)[tid].stack_max
bartbedfd232009-03-26 19:07:15 +0000315 || DRD_(g_threadinfo)[tid].stack_max == 0);
bart1ea5fff2008-03-16 08:36:23 +0000316#endif
bartbedfd232009-03-26 19:07:15 +0000317 if (UNLIKELY(stack_min < DRD_(g_threadinfo)[tid].stack_min_min))
318 {
319 DRD_(g_threadinfo)[tid].stack_min_min = stack_min;
320 }
bart1ea5fff2008-03-16 08:36:23 +0000321}
322
bart324a23b2009-02-15 12:14:52 +0000323/**
324 * Return true if and only if the specified address is on the stack of the
325 * currently scheduled thread.
bart08865622008-06-06 14:31:36 +0000326 */
327static __inline__
bart62a784c2009-02-15 13:11:14 +0000328Bool DRD_(thread_address_on_stack)(const Addr a)
bart08865622008-06-06 14:31:36 +0000329{
bartbedfd232009-03-26 19:07:15 +0000330 return (DRD_(g_threadinfo)[DRD_(g_drd_running_tid)].stack_min <= a
331 && a < DRD_(g_threadinfo)[DRD_(g_drd_running_tid)].stack_max);
bart08865622008-06-06 14:31:36 +0000332}
333
bart0d6d5c52009-03-10 09:22:13 +0000334/**
335 * Return true if and only if the specified address is on the stack of any
336 * thread.
337 */
338static __inline__
339Bool DRD_(thread_address_on_any_stack)(const Addr a)
340{
florian1e802b62015-02-13 19:08:26 +0000341 UInt i;
bart0d6d5c52009-03-10 09:22:13 +0000342
bartbedfd232009-03-26 19:07:15 +0000343 for (i = 1; i < DRD_N_THREADS; i++)
344 {
345 if (DRD_(g_threadinfo)[i].vg_thread_exists
346 && DRD_(g_threadinfo)[i].stack_min <= a
347 && a < DRD_(g_threadinfo)[i].stack_max)
348 {
349 return True;
350 }
351 }
352 return False;
bart0d6d5c52009-03-10 09:22:13 +0000353}
354
bart1a473c72008-03-13 19:03:38 +0000355/** Return a pointer to the latest segment for the specified thread. */
bart08865622008-06-06 14:31:36 +0000356static __inline__
bart62a784c2009-02-15 13:11:14 +0000357Segment* DRD_(thread_get_segment)(const DrdThreadId tid)
bart1a473c72008-03-13 19:03:38 +0000358{
bart8b4b2ee2008-06-11 13:17:56 +0000359#ifdef ENABLE_DRD_CONSISTENCY_CHECKS
bartbedfd232009-03-26 19:07:15 +0000360 tl_assert(0 <= (int)tid && tid < DRD_N_THREADS
361 && tid != DRD_INVALID_THREADID);
bart91b7ec32012-01-25 20:36:27 +0000362 tl_assert(DRD_(g_threadinfo)[tid].sg_last);
bart589f9482008-06-09 15:08:22 +0000363#endif
bart91b7ec32012-01-25 20:36:27 +0000364 return DRD_(g_threadinfo)[tid].sg_last;
bartf00a85b2008-03-13 18:49:23 +0000365}
366
barta79df6e2008-03-14 17:07:51 +0000367/** Return a pointer to the latest segment for the running thread. */
bart08865622008-06-06 14:31:36 +0000368static __inline__
bart62a784c2009-02-15 13:11:14 +0000369Segment* DRD_(running_thread_get_segment)(void)
barta79df6e2008-03-14 17:07:51 +0000370{
bartbedfd232009-03-26 19:07:15 +0000371 return DRD_(thread_get_segment)(DRD_(g_drd_running_tid));
barta79df6e2008-03-14 17:07:51 +0000372}
bartf00a85b2008-03-13 18:49:23 +0000373
bart86a87df2009-03-04 19:26:47 +0000374#endif /* __THREAD_H */