drd_thread.h revision 62a784c9382fdf7184065ad76ae8d3b905605f21
1af44c8236f7a73e71b16b707bba56f33af4d01cesewardj/*
2af44c8236f7a73e71b16b707bba56f33af4d01cesewardj  This file is part of drd, a data race detector.
3af44c8236f7a73e71b16b707bba56f33af4d01cesewardj
48564292ac4b9adf51c45517cca2878732feb5bb4sewardj  Copyright (C) 2006-2008 Bart Van Assche
5af44c8236f7a73e71b16b707bba56f33af4d01cesewardj  bart.vanassche@gmail.com
6af44c8236f7a73e71b16b707bba56f33af4d01cesewardj
7af44c8236f7a73e71b16b707bba56f33af4d01cesewardj  This program is free software; you can redistribute it and/or
8af44c8236f7a73e71b16b707bba56f33af4d01cesewardj  modify it under the terms of the GNU General Public License as
9af44c8236f7a73e71b16b707bba56f33af4d01cesewardj  published by the Free Software Foundation; either version 2 of the
10af44c8236f7a73e71b16b707bba56f33af4d01cesewardj  License, or (at your option) any later version.
11af44c8236f7a73e71b16b707bba56f33af4d01cesewardj
12af44c8236f7a73e71b16b707bba56f33af4d01cesewardj  This program is distributed in the hope that it will be useful, but
13af44c8236f7a73e71b16b707bba56f33af4d01cesewardj  WITHOUT ANY WARRANTY; without even the implied warranty of
14af44c8236f7a73e71b16b707bba56f33af4d01cesewardj  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15af44c8236f7a73e71b16b707bba56f33af4d01cesewardj  General Public License for more details.
16af44c8236f7a73e71b16b707bba56f33af4d01cesewardj
17af44c8236f7a73e71b16b707bba56f33af4d01cesewardj  You should have received a copy of the GNU General Public License
18af44c8236f7a73e71b16b707bba56f33af4d01cesewardj  along with this program; if not, write to the Free Software
19af44c8236f7a73e71b16b707bba56f33af4d01cesewardj  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20af44c8236f7a73e71b16b707bba56f33af4d01cesewardj  02111-1307, USA.
21af44c8236f7a73e71b16b707bba56f33af4d01cesewardj
22af44c8236f7a73e71b16b707bba56f33af4d01cesewardj  The GNU General Public License is contained in the file COPYING.
23af44c8236f7a73e71b16b707bba56f33af4d01cesewardj*/
24af44c8236f7a73e71b16b707bba56f33af4d01cesewardj
25af44c8236f7a73e71b16b707bba56f33af4d01cesewardj
26af44c8236f7a73e71b16b707bba56f33af4d01cesewardj#ifndef __THREAD_H
27af44c8236f7a73e71b16b707bba56f33af4d01cesewardj#define __THREAD_H
28af44c8236f7a73e71b16b707bba56f33af4d01cesewardj
29af44c8236f7a73e71b16b707bba56f33af4d01cesewardj
30324a23bea57e0bfc27d9442ec00a8eee8294f01abart/* Include directives. */
31f00a85bc55a2790c31670dd21e449a335c739068bart
3209dc13f324a19f1bebf58c7f197a581dc8fb528bbart#include "drd_basics.h"
33af44c8236f7a73e71b16b707bba56f33af4d01cesewardj#include "drd_segment.h"
34d59bb0f2a79bac77cf0f01b20d3d51102d6c71e3bart#include "pub_drd_bitmap.h"
35f00a85bc55a2790c31670dd21e449a335c739068bart#include "pub_tool_libcassert.h"  // tl_assert()
36f00a85bc55a2790c31670dd21e449a335c739068bart#include "pub_tool_stacktrace.h"  // StackTrace
37f00a85bc55a2790c31670dd21e449a335c739068bart#include "pub_tool_threadstate.h" // VG_N_THREADS
38f00a85bc55a2790c31670dd21e449a335c739068bart
39f00a85bc55a2790c31670dd21e449a335c739068bart
40324a23bea57e0bfc27d9442ec00a8eee8294f01abart/* Defines. */
41af44c8236f7a73e71b16b707bba56f33af4d01cesewardj
42f00a85bc55a2790c31670dd21e449a335c739068bart#define DRD_N_THREADS VG_N_THREADS
43af44c8236f7a73e71b16b707bba56f33af4d01cesewardj
44af44c8236f7a73e71b16b707bba56f33af4d01cesewardj#define DRD_INVALID_THREADID 0
45af44c8236f7a73e71b16b707bba56f33af4d01cesewardj
46af44c8236f7a73e71b16b707bba56f33af4d01cesewardj/* Note: the PThreadId typedef and the INVALID_POSIX_THREADID depend on the */
47af44c8236f7a73e71b16b707bba56f33af4d01cesewardj/* operating system and threading library in use. PThreadId must contain at */
48af44c8236f7a73e71b16b707bba56f33af4d01cesewardj/* least the same number of bits as pthread_t, and INVALID_POSIX_THREADID   */
49af44c8236f7a73e71b16b707bba56f33af4d01cesewardj/* must be a value that will never be returned by pthread_self().           */
50af44c8236f7a73e71b16b707bba56f33af4d01cesewardj
51af44c8236f7a73e71b16b707bba56f33af4d01cesewardj#define INVALID_POSIX_THREADID ((PThreadId)0)
52af44c8236f7a73e71b16b707bba56f33af4d01cesewardj
53af44c8236f7a73e71b16b707bba56f33af4d01cesewardj
54324a23bea57e0bfc27d9442ec00a8eee8294f01abart/* Type definitions. */
55f00a85bc55a2790c31670dd21e449a335c739068bart
56af44c8236f7a73e71b16b707bba56f33af4d01cesewardjtypedef UWord PThreadId;
57af44c8236f7a73e71b16b707bba56f33af4d01cesewardj
58f00a85bc55a2790c31670dd21e449a335c739068barttypedef struct
59f00a85bc55a2790c31670dd21e449a335c739068bart{
601a473c757cae99f11477440d5473be6e5c95e0cebart  Segment*  first;
611a473c757cae99f11477440d5473be6e5c95e0cebart  Segment*  last;
621a473c757cae99f11477440d5473be6e5c95e0cebart  ThreadId  vg_threadid;
631a473c757cae99f11477440d5473be6e5c95e0cebart  PThreadId pt_threadid;
64324a23bea57e0bfc27d9442ec00a8eee8294f01abart  Addr      stack_min_min; /**< Lowest value stack pointer ever had. */
65324a23bea57e0bfc27d9442ec00a8eee8294f01abart  Addr      stack_min;     /**< Current stack pointer. */
66324a23bea57e0bfc27d9442ec00a8eee8294f01abart  Addr      stack_startup; /**<Stack pointer after pthread_create() finished.*/
67324a23bea57e0bfc27d9442ec00a8eee8294f01abart  Addr      stack_max;     /**< Top of stack. */
68324a23bea57e0bfc27d9442ec00a8eee8294f01abart  SizeT     stack_size;    /**< Maximum size of stack. */
69324a23bea57e0bfc27d9442ec00a8eee8294f01abart  /** Indicates whether the Valgrind core knows about this thread. */
701a473c757cae99f11477440d5473be6e5c95e0cebart  Bool      vg_thread_exists;
71324a23bea57e0bfc27d9442ec00a8eee8294f01abart  /** Indicates whether there is an associated POSIX thread ID. */
721a473c757cae99f11477440d5473be6e5c95e0cebart  Bool      posix_thread_exists;
73324a23bea57e0bfc27d9442ec00a8eee8294f01abart  /**
74324a23bea57e0bfc27d9442ec00a8eee8294f01abart   * If true, indicates that there is a corresponding POSIX thread ID and
75324a23bea57e0bfc27d9442ec00a8eee8294f01abart   * a corresponding OS thread that is detached.
76324a23bea57e0bfc27d9442ec00a8eee8294f01abart   */
771a473c757cae99f11477440d5473be6e5c95e0cebart  Bool      detached_posix_thread;
78324a23bea57e0bfc27d9442ec00a8eee8294f01abart  /** Wether recording of memory accesses is active. */
791a473c757cae99f11477440d5473be6e5c95e0cebart  Bool      is_recording;
80324a23bea57e0bfc27d9442ec00a8eee8294f01abart  /** Nesting level of synchronization functions called by the client. */
811a473c757cae99f11477440d5473be6e5c95e0cebart  Int       synchr_nesting;
82f00a85bc55a2790c31670dd21e449a335c739068bart} ThreadInfo;
83f00a85bc55a2790c31670dd21e449a335c739068bart
84f00a85bc55a2790c31670dd21e449a335c739068bart
85324a23bea57e0bfc27d9442ec00a8eee8294f01abart/*
86324a23bea57e0bfc27d9442ec00a8eee8294f01abart * Local variables of drd_thread.c that are declared here such that these
87324a23bea57e0bfc27d9442ec00a8eee8294f01abart * can be accessed by inline functions.
88324a23bea57e0bfc27d9442ec00a8eee8294f01abart */
89f00a85bc55a2790c31670dd21e449a335c739068bart
90324a23bea57e0bfc27d9442ec00a8eee8294f01abartextern DrdThreadId    DRD_(g_drd_running_tid);
91324a23bea57e0bfc27d9442ec00a8eee8294f01abartextern ThreadInfo     DRD_(g_threadinfo)[DRD_N_THREADS];
92324a23bea57e0bfc27d9442ec00a8eee8294f01abartextern struct bitmap* DRD_(g_conflict_set);
93f00a85bc55a2790c31670dd21e449a335c739068bart
94f00a85bc55a2790c31670dd21e449a335c739068bart
95324a23bea57e0bfc27d9442ec00a8eee8294f01abart/* Function declarations. */
96af44c8236f7a73e71b16b707bba56f33af4d01cesewardj
9762a784c9382fdf7184065ad76ae8d3b905605f21bartvoid DRD_(thread_trace_context_switches)(const Bool t);
9862a784c9382fdf7184065ad76ae8d3b905605f21bartvoid DRD_(thread_trace_conflict_set)(const Bool t);
9909dc13f324a19f1bebf58c7f197a581dc8fb528bbartBool DRD_(thread_get_trace_fork_join)(void);
10009dc13f324a19f1bebf58c7f197a581dc8fb528bbartvoid DRD_(thread_set_trace_fork_join)(const Bool t);
10162a784c9382fdf7184065ad76ae8d3b905605f21bartvoid DRD_(thread_set_segment_merging)(const Bool m);
102af44c8236f7a73e71b16b707bba56f33af4d01cesewardj
10362a784c9382fdf7184065ad76ae8d3b905605f21bartDrdThreadId DRD_(VgThreadIdToDrdThreadId)(const ThreadId tid);
10462a784c9382fdf7184065ad76ae8d3b905605f21bartDrdThreadId DRD_(NewVgThreadIdToDrdThreadId)(const ThreadId tid);
10562a784c9382fdf7184065ad76ae8d3b905605f21bartDrdThreadId DRD_(PtThreadIdToDrdThreadId)(const PThreadId tid);
10662a784c9382fdf7184065ad76ae8d3b905605f21bartThreadId DRD_(DrdThreadIdToVgThreadId)(const DrdThreadId tid);
10762a784c9382fdf7184065ad76ae8d3b905605f21bartDrdThreadId DRD_(thread_pre_create)(const DrdThreadId creator,
108af44c8236f7a73e71b16b707bba56f33af4d01cesewardj                              const ThreadId vg_created);
10962a784c9382fdf7184065ad76ae8d3b905605f21bartDrdThreadId DRD_(thread_post_create)(const ThreadId vg_created);
11009dc13f324a19f1bebf58c7f197a581dc8fb528bbartvoid DRD_(thread_post_join)(DrdThreadId drd_joiner, DrdThreadId drd_joinee);
11162a784c9382fdf7184065ad76ae8d3b905605f21bartvoid DRD_(thread_delete)(const DrdThreadId tid);
11262a784c9382fdf7184065ad76ae8d3b905605f21bartvoid DRD_(thread_finished)(const DrdThreadId tid);
11362a784c9382fdf7184065ad76ae8d3b905605f21bartvoid DRD_(thread_pre_cancel)(const DrdThreadId tid);
11462a784c9382fdf7184065ad76ae8d3b905605f21bartvoid DRD_(thread_set_stack_startup)(const DrdThreadId tid, const Addr stack_startup);
11562a784c9382fdf7184065ad76ae8d3b905605f21bartAddr DRD_(thread_get_stack_min)(const DrdThreadId tid);
11662a784c9382fdf7184065ad76ae8d3b905605f21bartAddr DRD_(thread_get_stack_min_min)(const DrdThreadId tid);
11762a784c9382fdf7184065ad76ae8d3b905605f21bartAddr DRD_(thread_get_stack_max)(const DrdThreadId tid);
11862a784c9382fdf7184065ad76ae8d3b905605f21bartSizeT DRD_(thread_get_stack_size)(const DrdThreadId tid);
11962a784c9382fdf7184065ad76ae8d3b905605f21bartvoid DRD_(thread_set_pthreadid)(const DrdThreadId tid, const PThreadId ptid);
12062a784c9382fdf7184065ad76ae8d3b905605f21bartBool DRD_(thread_get_joinable)(const DrdThreadId tid);
12162a784c9382fdf7184065ad76ae8d3b905605f21bartvoid DRD_(thread_set_joinable)(const DrdThreadId tid, const Bool joinable);
12262a784c9382fdf7184065ad76ae8d3b905605f21bartvoid DRD_(thread_set_vg_running_tid)(const ThreadId vg_tid);
12362a784c9382fdf7184065ad76ae8d3b905605f21bartvoid DRD_(thread_set_running_tid)(const ThreadId vg_tid,
1248b09d4f037c6399658b610228c7bbc0c6133d9dasewardj                            const DrdThreadId drd_tid);
12562a784c9382fdf7184065ad76ae8d3b905605f21bartint DRD_(thread_enter_synchr)(const DrdThreadId tid);
12662a784c9382fdf7184065ad76ae8d3b905605f21bartint DRD_(thread_leave_synchr)(const DrdThreadId tid);
12762a784c9382fdf7184065ad76ae8d3b905605f21bartint DRD_(thread_get_synchr_nesting_count)(const DrdThreadId tid);
12862a784c9382fdf7184065ad76ae8d3b905605f21bartvoid DRD_(thread_new_segment)(const DrdThreadId tid);
12962a784c9382fdf7184065ad76ae8d3b905605f21bartVectorClock* DRD_(thread_get_vc)(const DrdThreadId tid);
13062a784c9382fdf7184065ad76ae8d3b905605f21bartvoid DRD_(thread_get_latest_segment)(Segment** sg, const DrdThreadId tid);
13162a784c9382fdf7184065ad76ae8d3b905605f21bartvoid DRD_(thread_combine_vc)(const DrdThreadId joiner, const DrdThreadId joinee);
13262a784c9382fdf7184065ad76ae8d3b905605f21bartvoid DRD_(thread_combine_vc2)(const DrdThreadId tid, const VectorClock* const vc);
13362a784c9382fdf7184065ad76ae8d3b905605f21bart
13462a784c9382fdf7184065ad76ae8d3b905605f21bartvoid DRD_(thread_stop_using_mem)(const Addr a1, const Addr a2);
13562a784c9382fdf7184065ad76ae8d3b905605f21bartvoid DRD_(thread_start_recording)(const DrdThreadId tid);
13662a784c9382fdf7184065ad76ae8d3b905605f21bartvoid DRD_(thread_stop_recording)(const DrdThreadId tid);
13762a784c9382fdf7184065ad76ae8d3b905605f21bartvoid DRD_(thread_print_all)(void);
13862a784c9382fdf7184065ad76ae8d3b905605f21bartvoid DRD_(thread_report_races)(const DrdThreadId tid);
13962a784c9382fdf7184065ad76ae8d3b905605f21bartvoid DRD_(thread_report_races_segment)(const DrdThreadId tid,
140af44c8236f7a73e71b16b707bba56f33af4d01cesewardj                                 const Segment* const p);
14162a784c9382fdf7184065ad76ae8d3b905605f21bartvoid DRD_(thread_report_all_races)(void);
14262a784c9382fdf7184065ad76ae8d3b905605f21bartvoid DRD_(thread_report_conflicting_segments)(const DrdThreadId tid,
143af44c8236f7a73e71b16b707bba56f33af4d01cesewardj                                        const Addr addr,
144af44c8236f7a73e71b16b707bba56f33af4d01cesewardj                                        const SizeT size,
145af44c8236f7a73e71b16b707bba56f33af4d01cesewardj                                        const BmAccessTypeT access_type);
14662a784c9382fdf7184065ad76ae8d3b905605f21bartULong DRD_(thread_get_context_switch_count)(void);
14762a784c9382fdf7184065ad76ae8d3b905605f21bartULong DRD_(thread_get_report_races_count)(void);
14862a784c9382fdf7184065ad76ae8d3b905605f21bartULong DRD_(thread_get_discard_ordered_segments_count)(void);
14962a784c9382fdf7184065ad76ae8d3b905605f21bartULong DRD_(thread_get_update_conflict_set_count)(ULong* dsnsc, ULong* dscvc);
15062a784c9382fdf7184065ad76ae8d3b905605f21bartULong DRD_(thread_get_conflict_set_bitmap_creation_count)(void);
15162a784c9382fdf7184065ad76ae8d3b905605f21bartULong DRD_(thread_get_conflict_set_bitmap2_creation_count)(void);
152af44c8236f7a73e71b16b707bba56f33af4d01cesewardj
153af44c8236f7a73e71b16b707bba56f33af4d01cesewardj
154324a23bea57e0bfc27d9442ec00a8eee8294f01abart/* Inline function definitions. */
155324a23bea57e0bfc27d9442ec00a8eee8294f01abart
156bf80e12418014298bef23cddea3249dee74e5b96bartstatic __inline__
15762a784c9382fdf7184065ad76ae8d3b905605f21bartBool DRD_(IsValidDrdThreadId)(const DrdThreadId tid)
158bf80e12418014298bef23cddea3249dee74e5b96bart{
159bf80e12418014298bef23cddea3249dee74e5b96bart  return (0 <= (int)tid && tid < DRD_N_THREADS && tid != DRD_INVALID_THREADID
160324a23bea57e0bfc27d9442ec00a8eee8294f01abart          && ! (DRD_(g_threadinfo)[tid].vg_thread_exists == False
161324a23bea57e0bfc27d9442ec00a8eee8294f01abart                && DRD_(g_threadinfo)[tid].posix_thread_exists == False
162324a23bea57e0bfc27d9442ec00a8eee8294f01abart                && DRD_(g_threadinfo)[tid].detached_posix_thread == False));
163bf80e12418014298bef23cddea3249dee74e5b96bart}
164bf80e12418014298bef23cddea3249dee74e5b96bart
165088656233045bfaa98d73a9a83eab0a412bd3f2bbartstatic __inline__
16662a784c9382fdf7184065ad76ae8d3b905605f21bartDrdThreadId DRD_(thread_get_running_tid)(void)
1671ea5fff9a68ea6d56cb946eb709838bd40562a79bart{
168324a23bea57e0bfc27d9442ec00a8eee8294f01abart  tl_assert(DRD_(g_drd_running_tid) != DRD_INVALID_THREADID);
169324a23bea57e0bfc27d9442ec00a8eee8294f01abart  return DRD_(g_drd_running_tid);
1701ea5fff9a68ea6d56cb946eb709838bd40562a79bart}
1711ea5fff9a68ea6d56cb946eb709838bd40562a79bart
172088656233045bfaa98d73a9a83eab0a412bd3f2bbartstatic __inline__
17362a784c9382fdf7184065ad76ae8d3b905605f21bartstruct bitmap* DRD_(thread_get_conflict_set)(void)
1741a473c757cae99f11477440d5473be6e5c95e0cebart{
175324a23bea57e0bfc27d9442ec00a8eee8294f01abart  return DRD_(g_conflict_set);
1761a473c757cae99f11477440d5473be6e5c95e0cebart}
1771a473c757cae99f11477440d5473be6e5c95e0cebart
178088656233045bfaa98d73a9a83eab0a412bd3f2bbartstatic __inline__
17962a784c9382fdf7184065ad76ae8d3b905605f21bartBool DRD_(running_thread_is_recording)(void)
180f00a85bc55a2790c31670dd21e449a335c739068bart{
1818b4b2eee19af852047cafd270c48c09d8adea33fbart#ifdef ENABLE_DRD_CONSISTENCY_CHECKS
182324a23bea57e0bfc27d9442ec00a8eee8294f01abart  tl_assert(0 <= (int)DRD_(g_drd_running_tid) && DRD_(g_drd_running_tid) < DRD_N_THREADS
183324a23bea57e0bfc27d9442ec00a8eee8294f01abart            && DRD_(g_drd_running_tid) != DRD_INVALID_THREADID);
184589f9487830f84b24108bed90b4d71c392640dc9bart#endif
185324a23bea57e0bfc27d9442ec00a8eee8294f01abart  return (DRD_(g_threadinfo)[DRD_(g_drd_running_tid)].synchr_nesting == 0
186324a23bea57e0bfc27d9442ec00a8eee8294f01abart          && DRD_(g_threadinfo)[DRD_(g_drd_running_tid)].is_recording);
1871a473c757cae99f11477440d5473be6e5c95e0cebart}
1881a473c757cae99f11477440d5473be6e5c95e0cebart
189088656233045bfaa98d73a9a83eab0a412bd3f2bbartstatic __inline__
19062a784c9382fdf7184065ad76ae8d3b905605f21bartvoid DRD_(thread_set_stack_min)(const DrdThreadId tid, const Addr stack_min)
1911ea5fff9a68ea6d56cb946eb709838bd40562a79bart{
1928b4b2eee19af852047cafd270c48c09d8adea33fbart#ifdef ENABLE_DRD_CONSISTENCY_CHECKS
193f0cdc606f274069652b956e4852da270b2f3dd6abart  tl_assert(0 <= (int)tid
194f0cdc606f274069652b956e4852da270b2f3dd6abart            && tid < DRD_N_THREADS
195f0cdc606f274069652b956e4852da270b2f3dd6abart            && tid != DRD_INVALID_THREADID);
1961ea5fff9a68ea6d56cb946eb709838bd40562a79bart#endif
197324a23bea57e0bfc27d9442ec00a8eee8294f01abart  DRD_(g_threadinfo)[tid].stack_min = stack_min;
1988b4b2eee19af852047cafd270c48c09d8adea33fbart#ifdef ENABLE_DRD_CONSISTENCY_CHECKS
199fda6492f6b5c2c91fd7b46e94bb696adca553c81bart  /* This function can be called after the thread has been created but */
200fda6492f6b5c2c91fd7b46e94bb696adca553c81bart  /* before drd_post_thread_create() has filled in stack_max.          */
201324a23bea57e0bfc27d9442ec00a8eee8294f01abart  tl_assert(DRD_(g_threadinfo)[tid].stack_min < DRD_(g_threadinfo)[tid].stack_max
202324a23bea57e0bfc27d9442ec00a8eee8294f01abart            || DRD_(g_threadinfo)[tid].stack_max == 0);
2031ea5fff9a68ea6d56cb946eb709838bd40562a79bart#endif
204324a23bea57e0bfc27d9442ec00a8eee8294f01abart  if (UNLIKELY(stack_min < DRD_(g_threadinfo)[tid].stack_min_min))
205e773de4785187ef787703968b13cdf76b4721cb7bart  {
206324a23bea57e0bfc27d9442ec00a8eee8294f01abart    DRD_(g_threadinfo)[tid].stack_min_min = stack_min;
2071ea5fff9a68ea6d56cb946eb709838bd40562a79bart  }
2081ea5fff9a68ea6d56cb946eb709838bd40562a79bart}
2091ea5fff9a68ea6d56cb946eb709838bd40562a79bart
210324a23bea57e0bfc27d9442ec00a8eee8294f01abart/**
211324a23bea57e0bfc27d9442ec00a8eee8294f01abart * Return true if and only if the specified address is on the stack of the
212324a23bea57e0bfc27d9442ec00a8eee8294f01abart * currently scheduled thread.
213088656233045bfaa98d73a9a83eab0a412bd3f2bbart */
214088656233045bfaa98d73a9a83eab0a412bd3f2bbartstatic __inline__
21562a784c9382fdf7184065ad76ae8d3b905605f21bartBool DRD_(thread_address_on_stack)(const Addr a)
216088656233045bfaa98d73a9a83eab0a412bd3f2bbart{
217324a23bea57e0bfc27d9442ec00a8eee8294f01abart  return (DRD_(g_threadinfo)[DRD_(g_drd_running_tid)].stack_min <= a
218324a23bea57e0bfc27d9442ec00a8eee8294f01abart	  && a < DRD_(g_threadinfo)[DRD_(g_drd_running_tid)].stack_max);
219088656233045bfaa98d73a9a83eab0a412bd3f2bbart}
220088656233045bfaa98d73a9a83eab0a412bd3f2bbart
2211a473c757cae99f11477440d5473be6e5c95e0cebart/** Return a pointer to the latest segment for the specified thread. */
222088656233045bfaa98d73a9a83eab0a412bd3f2bbartstatic __inline__
22362a784c9382fdf7184065ad76ae8d3b905605f21bartSegment* DRD_(thread_get_segment)(const DrdThreadId tid)
2241a473c757cae99f11477440d5473be6e5c95e0cebart{
2258b4b2eee19af852047cafd270c48c09d8adea33fbart#ifdef ENABLE_DRD_CONSISTENCY_CHECKS
22674a5f21b1495a9e28c648b179b821ffb23484244bart  tl_assert(0 <= (int)tid && tid < DRD_N_THREADS
2271a473c757cae99f11477440d5473be6e5c95e0cebart            && tid != DRD_INVALID_THREADID);
228324a23bea57e0bfc27d9442ec00a8eee8294f01abart  tl_assert(DRD_(g_threadinfo)[tid].last);
229589f9487830f84b24108bed90b4d71c392640dc9bart#endif
230324a23bea57e0bfc27d9442ec00a8eee8294f01abart  return DRD_(g_threadinfo)[tid].last;
231f00a85bc55a2790c31670dd21e449a335c739068bart}
232f00a85bc55a2790c31670dd21e449a335c739068bart
233a79df6ed701ed416ba6241e5b0dd95fae8fa35f9bart/** Return a pointer to the latest segment for the running thread. */
234088656233045bfaa98d73a9a83eab0a412bd3f2bbartstatic __inline__
23562a784c9382fdf7184065ad76ae8d3b905605f21bartSegment* DRD_(running_thread_get_segment)(void)
236a79df6ed701ed416ba6241e5b0dd95fae8fa35f9bart{
23762a784c9382fdf7184065ad76ae8d3b905605f21bart  return DRD_(thread_get_segment)(DRD_(g_drd_running_tid));
238a79df6ed701ed416ba6241e5b0dd95fae8fa35f9bart}
239f00a85bc55a2790c31670dd21e449a335c739068bart
240af44c8236f7a73e71b16b707bba56f33af4d01cesewardj#endif // __THREAD_H
241