Lines Matching refs:Thr
143 a pair, (Thr*, ULong), but that takes 16 bytes on a 64-bit target.
144 We pack it into 64 bits by representing the Thr* using a ThrID, a
171 NB3: this probably also relies on the fact that Thr's are never
173 Thr's to thrid values (set up in Thr__new) persists forever.
261 // data decls: Thr, ULong_n_EC //
305 /* A small integer giving a unique identity to this Thr. See
315 1-1 mapping between Thread and Thr structures -- each Thr points
316 at its corresponding Thread, and vice versa. Really, Thr and
361 static void (*main_get_stacktrace)( Thr*, Addr*, UWord ) = NULL;
362 static ExeContext* (*main_get_EC)( Thr* ) = NULL;
1998 /* There's a 1-1 mapping between Thr and ThrIDs -- the latter merely
1999 being compact stand-ins for Thr*'s. Use these functions to map
2001 static ThrID Thr__to_ThrID ( Thr* thr ); /* fwds */
2002 static Thr* Thr__from_ThrID ( ThrID thrid ); /* fwds */
2075 /* Sanity check: check for unique .sts.thr values. */
2121 static void VTS__singleton ( /*OUT*/VTS* out, Thr* thr, ULong tym );
2126 static void VTS__tick ( /*OUT*/VTS* out, Thr* me, VTS* vts );
2156 static ULong VTS__indexAt_SLOW ( VTS* vts, Thr* idx );
2163 static void VTS__declare_thread_very_dead ( Thr* idx );
2274 static void VTS__singleton ( /*OUT*/VTS* out, Thr* thr, ULong tym )
2276 tl_assert(thr);
2282 out->ts[hi].thrid = Thr__to_ThrID(thr);
2290 static void VTS__tick ( /*OUT*/VTS* out, Thr* me, VTS* vts )
2449 /* having laboriously determined (thr, tyma, tymb), do something
2636 ULong VTS__indexAt_SLOW ( VTS* vts, Thr* idx )
2654 static void VTS__declare_thread_very_dead ( Thr* thr )
2656 if (0) VG_(printf)("VTQ: tae %p\n", thr);
2658 tl_assert(thr->llexit_done);
2659 tl_assert(thr->joinedwith_done);
2662 nyu = Thr__to_ThrID(thr);
2671 VtsID__rcdec(thr->viR);
2672 VtsID__rcdec(thr->viW);
2673 thr->viR = VtsID_INVALID;
2674 thr->viW = VtsID_INVALID;
3260 Thr* hbthr = hgthread->hbthr;
3490 /* create a singleton VTS, namely [thr:1] */
3491 static VtsID VtsID__mk_Singleton ( Thr* thr, ULong tym ) {
3493 VTS__singleton(temp_max_sized_VTS, thr,tym);
3498 static VtsID VtsID__tick ( VtsID vi, Thr* idx ) {
3506 static ULong VtsID__indexAt ( VtsID vi, Thr* idx ) {
3516 static Thr* VtsID__findFirst_notLEQ ( VtsID vi1, VtsID vi2 )
3519 Thr* diffthr;
4003 /* Maps ThrID values to their Thr*s (which contain ThrID values that
4006 static XArray* /* of Thr* */ thrid_to_thr_map = NULL;
4012 static ThrID Thr__to_ThrID ( Thr* thr ) {
4013 return thr->thrid;
4015 static Thr* Thr__from_ThrID ( UInt thrid ) {
4016 Thr* thr = *(Thr**)VG_(indexXA)( thrid_to_thr_map, thrid - 1024 );
4017 tl_assert(thr->thrid == thrid);
4018 return thr;
4021 static Thr* Thr__new ( void )
4023 Thr* thr = HG_(zalloc)( "libhb.Thr__new.1", sizeof(Thr) );
4024 thr->viR = VtsID_INVALID;
4025 thr->viW = VtsID_INVALID;
4026 thr->llexit_done = False;
4027 thr->joinedwith_done = False;
4028 thr->filter = HG_(zalloc)( "libhb.Thr__new.2", sizeof(Filter) );
4030 thr->local_Kws_n_stacks
4035 /* Add this Thr* <-> ThrID binding to the mapping, and
4039 HG_(free), sizeof(Thr*) );
4047 thr->thrid = thrid_counter++;
4048 Word ix = VG_(addToXA)( thrid_to_thr_map, &thr );
4049 tl_assert(ix + 1024 == thr->thrid);
4051 return thr;
4054 static void note_local_Kw_n_stack_for ( Thr* thr )
4058 tl_assert(thr);
4064 /* This is the scalar Kw for thr. */
4065 pair.ull = VtsID__indexAt( thr->viW, thr );
4066 pair.ec = main_get_EC( thr );
4068 tl_assert(thr->local_Kws_n_stacks);
4071 nPresent = VG_(sizeXA)( thr->local_Kws_n_stacks );
4076 VG_(dropHeadXA)( thr->local_Kws_n_stacks, nPresent / 2 );
4077 nPresent = VG_(sizeXA)( thr->local_Kws_n_stacks );
4079 VG_(printf)("LOCAL Kw: thr %p, Kw %llu, ec %p (!!! gc !!!)\n",
4080 thr, pair.ull, pair.ec );
4085 = (ULong_n_EC*)VG_(indexXA)( thr->local_Kws_n_stacks, nPresent-1 );
4092 VG_(addToXA)( thr->local_Kws_n_stacks, &pair );
4095 VG_(printf)("LOCAL Kw: thr %p, Kw %llu, ec %p\n",
4096 thr, pair.ull, pair.ec );
4406 static RCEC* get_RCEC ( Thr* thr )
4414 main_get_stacktrace( thr, &example.frames[0], N_FRAMES );
4582 static void event_map_bind ( Addr a, SizeT szB, Bool isW, Thr* thr )
4588 tl_assert(thr);
4589 ThrID thrid = thr->thrid;
4592 WordSetID locksHeldW = thr->hgthread->locksetW;
4594 rcec = get_RCEC( thr );
4601 address/thr/sz/isW. */
4613 /* thread 'thr' has an entry. Update its RCEC, if it differs. */
4651 Returns the most recent conflicting access with thr/[a, a+szB[/isW. */
4653 /*OUT*/Thr** resThr,
4657 Thr* thr, Addr a, SizeT szB, Bool isW )
4670 tl_assert(thr);
4673 ThrID thrid = thr->thrid;
4978 static void record_race_info ( Thr* acc_thr,
5015 Thr* confThr;
5019 (in fact it's the one with the lowest Thr* value). */
5106 Thr* acc_thr,
5171 Thr* acc_thr,
5248 static void zsm_sapply08__msmcread ( Thr* thr, Addr a ) {
5266 svNew = msmcread( svOld, thr,a,1 );
5272 static void zsm_sapply08__msmcwrite ( Thr* thr, Addr a ) {
5290 svNew = msmcwrite( svOld, thr,a,1 );
5298 static void zsm_sapply16__msmcread ( Thr* thr, Addr a ) {
5321 svNew = msmcread( svOld, thr,a,2 );
5328 zsm_sapply08__msmcread( thr, a + 0 );
5329 zsm_sapply08__msmcread( thr, a + 1 );
5332 static void zsm_sapply16__msmcwrite ( Thr* thr, Addr a ) {
5355 svNew = msmcwrite( svOld, thr,a,2 );
5362 zsm_sapply08__msmcwrite( thr, a + 0 );
5363 zsm_sapply08__msmcwrite( thr, a + 1 );
5368 static void zsm_sapply32__msmcread ( Thr* thr, Addr a ) {
5391 svNew = msmcread( svOld, thr,a,4 );
5398 zsm_sapply16__msmcread( thr, a + 0 );
5399 zsm_sapply16__msmcread( thr, a + 2 );
5402 static void zsm_sapply32__msmcwrite ( Thr* thr, Addr a ) {
5425 svNew = msmcwrite( svOld, thr,a,4 );
5432 zsm_sapply16__msmcwrite( thr, a + 0 );
5433 zsm_sapply16__msmcwrite( thr, a + 2 );
5438 static void zsm_sapply64__msmcread ( Thr* thr, Addr a ) {
5455 svNew = msmcread( svOld, thr,a,8 );
5462 zsm_sapply32__msmcread( thr, a + 0 );
5463 zsm_sapply32__msmcread( thr, a + 4 );
5466 static void zsm_sapply64__msmcwrite ( Thr* thr, Addr a ) {
5483 svNew = msmcwrite( svOld, thr,a,8 );
5490 zsm_sapply32__msmcwrite( thr, a + 0 );
5491 zsm_sapply32__msmcwrite( thr, a + 4 );
5891 void zsm_sapply08_f__msmcwrite ( Thr* thr, Addr a ) {
5894 if (LIKELY(Filter__ok_to_skip_cwr08(thr->filter, a))) {
5898 zsm_sapply08__msmcwrite(thr, a);
5901 void zsm_sapply16_f__msmcwrite ( Thr* thr, Addr a ) {
5904 if (LIKELY(Filter__ok_to_skip_cwr16(thr->filter, a))) {
5908 zsm_sapply16__msmcwrite(thr, a);
5911 void zsm_sapply32_f__msmcwrite ( Thr* thr, Addr a ) {
5914 if (LIKELY(Filter__ok_to_skip_cwr32(thr->filter, a))) {
5918 zsm_sapply32__msmcwrite(thr, a);
5921 void zsm_sapply64_f__msmcwrite ( Thr* thr, Addr a ) {
5924 if (LIKELY(Filter__ok_to_skip_cwr64(thr->filter, a))) {
5928 zsm_sapply64__msmcwrite(thr, a);
5931 void zsm_sapplyNN_f__msmcwrite ( Thr* thr, Addr a, SizeT len )
5935 zsm_sapply32_f__msmcwrite( thr, a );
5939 zsm_sapply64_f__msmcwrite( thr, a );
5947 zsm_sapply08_f__msmcwrite( thr, a );
5955 zsm_sapply16_f__msmcwrite( thr, a );
5963 zsm_sapply32_f__msmcwrite( thr, a );
5973 zsm_sapply64_f__msmcwrite( thr, a );
5984 zsm_sapply32_f__msmcwrite( thr, a );
5993 zsm_sapply16_f__msmcwrite( thr, a );
6000 zsm_sapply08_f__msmcwrite( thr, a );
6007 void zsm_sapply08_f__msmcread ( Thr* thr, Addr a ) {
6010 if (LIKELY(Filter__ok_to_skip_crd08(thr->filter, a))) {
6014 zsm_sapply08__msmcread(thr, a);
6017 void zsm_sapply16_f__msmcread ( Thr* thr, Addr a ) {
6020 if (LIKELY(Filter__ok_to_skip_crd16(thr->filter, a))) {
6024 zsm_sapply16__msmcread(thr, a);
6027 void zsm_sapply32_f__msmcread ( Thr* thr, Addr a ) {
6030 if (LIKELY(Filter__ok_to_skip_crd32(thr->filter, a))) {
6034 zsm_sapply32__msmcread(thr, a);
6037 void zsm_sapply64_f__msmcread ( Thr* thr, Addr a ) {
6040 if (LIKELY(Filter__ok_to_skip_crd64(thr->filter, a))) {
6044 zsm_sapply64__msmcread(thr, a);
6047 void zsm_sapplyNN_f__msmcread ( Thr* thr, Addr a, SizeT len )
6051 zsm_sapply32_f__msmcread( thr, a );
6055 zsm_sapply64_f__msmcread( thr, a );
6063 zsm_sapply08_f__msmcread( thr, a );
6071 zsm_sapply16_f__msmcread( thr, a );
6079 zsm_sapply32_f__msmcread( thr, a );
6089 zsm_sapply64_f__msmcread( thr, a );
6100 zsm_sapply32_f__msmcread( thr, a );
6109 zsm_sapply16_f__msmcread( thr, a );
6116 zsm_sapply08_f__msmcread( thr, a );
6123 void libhb_Thr_resumes ( Thr* thr )
6125 if (0) VG_(printf)("resume %p\n", thr);
6126 tl_assert(thr);
6127 tl_assert(!thr->llexit_done);
6128 Filter__clear(thr->filter, "libhb_Thr_resumes");
6134 tl_assert(thr->local_Kws_n_stacks);
6135 if (VG_(sizeXA)( thr->local_Kws_n_stacks ) == 0)
6136 note_local_Kw_n_stack_for(thr);
6200 static void show_thread_state ( const HChar* str, Thr* t )
6204 VG_(printf)("thr \"%s\" %p has vi* %u==", str, t, t->viR );
6208 VG_(printf)("thr \"%s\" %p has viR %u==", str, t, t->viR );
6217 Thr* libhb_init (
6218 void (*get_stacktrace)( Thr*, Addr*, UWord ),
6219 ExeContext* (*get_EC)( Thr* )
6222 Thr* thr;
6268 thr = Thr__new();
6269 vi = VtsID__mk_Singleton( thr, 1 );
6270 thr->viR = vi;
6271 thr->viW = vi;
6272 VtsID__rcinc(thr->viR);
6273 VtsID__rcinc(thr->viW);
6275 show_thread_state(" root", thr);
6276 return thr;
6280 Thr* libhb_create ( Thr* parent )
6286 Thr* child = Thr__new();
6436 Thr* hbthr = hgthread->hbthr;
6549 void libhb_async_exit ( Thr* thr )
6551 tl_assert(thr);
6552 tl_assert(!thr->llexit_done);
6553 thr->llexit_done = True;
6557 tl_assert(thr->filter);
6558 HG_(free)(thr->filter);
6559 thr->filter = NULL;
6564 if (thr->joinedwith_done)
6565 VTS__declare_thread_very_dead(thr);
6569 yes, then we better not free up thr->local_Kws_n_stacks. The
6574 // VG_(deleteXA)(thr->local_Kws_n_stacks);
6575 // thr->local_Kws_n_stacks = NULL;
6580 references to its vector clocks (Thr::viR and Thr::viW). */
6581 void libhb_joinedwith_done ( Thr* thr )
6583 tl_assert(thr);
6584 /* Caller must ensure that this is only ever called once per Thr. */
6585 tl_assert(!thr->joinedwith_done);
6586 thr->joinedwith_done = True;
6587 if (thr->llexit_done)
6588 VTS__declare_thread_very_dead(thr);
6610 void libhb_so_send ( Thr* thr, SO* so, Bool strong_send )
6612 /* Copy the VTSs from 'thr' into the sync object, and then move
6620 { Bool leq = VtsID__cmpLEQ(thr->viW, thr->viR);
6628 so->viR = thr->viR;
6629 so->viW = thr->viW;
6639 so->viR = strong_send ? thr->viR : VtsID__join2( so->viR, thr->viR );
6640 so->viW = strong_send ? thr->viW : VtsID__join2( so->viW, thr->viW );
6646 VtsID__rcdec(thr->viR);
6647 VtsID__rcdec(thr->viW);
6648 thr->viR = VtsID__tick( thr->viR, thr );
6649 thr->viW = VtsID__tick( thr->viW, thr );
6650 if (!thr->llexit_done) {
6651 Filter__clear(thr->filter, "libhb_so_send");
6652 note_local_Kw_n_stack_for(thr);
6654 VtsID__rcinc(thr->viR);
6655 VtsID__rcinc(thr->viW);
6658 show_thread_state("s-send", thr);
6660 show_thread_state("w-send", thr);
6663 void libhb_so_recv ( Thr* thr, SO* so, Bool strong_recv )
6674 VtsID__rcdec(thr->viR);
6675 thr->viR = VtsID__join2( thr->viR, so->viR );
6676 VtsID__rcinc(thr->viR);
6683 //VtsID__rcdec(thr->viR);
6684 //thr->viR = VtsID__tick( thr->viR, thr );
6685 //VtsID__rcinc(thr->viR);
6691 VtsID__rcdec(thr->viW);
6692 thr->viW = VtsID__join2( thr->viW, so->viW );
6693 VtsID__rcinc(thr->viW);
6696 //VtsID__rcdec(thr->viW);
6697 //thr->viW = VtsID__tick( thr->viW, thr );
6698 //VtsID__rcinc(thr->viW);
6701 if (thr->filter)
6702 Filter__clear(thr->filter, "libhb_so_recv");
6703 note_local_Kw_n_stack_for(thr);
6706 show_thread_state("s-recv", thr);
6708 show_thread_state("w-recv", thr);
6714 show_thread_state("d-recv", thr);
6737 static void trace ( Thr* thr, Addr a, SizeT szB, const HChar* s )
6740 VG_(printf)("thr %p (%#lx,%lu) %s: 0x%016llx ", thr,a,szB,s,sv);
6741 show_thread_state("", thr);
6745 void libhb_srange_new ( Thr* thr, Addr a, SizeT szB )
6747 SVal sv = SVal__mkC(thr->viW, thr->viW);
6749 if (0 && TRACEME(a,szB)) trace(thr,a,szB,"nw-before");
6751 Filter__clear_range( thr->filter, a, szB );
6752 if (0 && TRACEME(a,szB)) trace(thr,a,szB,"nw-after ");
6755 void libhb_srange_noaccess_NoFX ( Thr* thr, Addr a, SizeT szB )
6939 void libhb_srange_noaccess_AHAE ( Thr* thr, Addr a, SizeT szB )
6949 Filter__clear_range( thr->filter, a, szB );
7021 void libhb_srange_untrack ( Thr* thr, Addr a, SizeT szB )
7025 if (0 && TRACEME(a,szB)) trace(thr,a,szB,"untrack-before");
7030 Filter__clear_range( thr->filter, a, szB );
7031 if (0 && TRACEME(a,szB)) trace(thr,a,szB,"untrack-after ");
7034 Thread* libhb_get_Thr_hgthread ( Thr* thr ) {
7035 tl_assert(thr);
7036 return thr->hgthread;
7039 void libhb_set_Thr_hgthread ( Thr* thr, Thread* hgthread ) {
7040 tl_assert(thr);
7041 thr->hgthread = hgthread;
7044 void libhb_copy_shadow_state ( Thr* thr, Addr src, Addr dst, SizeT len )
7047 Filter__clear_range( thr->filter, dst, len );