Home | History | Annotate | Download | only in helgrind

Lines Matching defs:lk

207 static void del_LockN ( Lock* lk ) 
209 tl_assert(HG_(is_sane_LockN)(lk));
210 tl_assert(lk->hbso);
211 libhb_so_dealloc(lk->hbso);
212 if (lk->heldBy)
213 VG_(deleteBag)( lk->heldBy );
215 if (lk == admin_locks) {
216 tl_assert(lk->admin_prev == NULL);
217 if (lk->admin_next)
218 lk->admin_next->admin_prev = NULL;
219 admin_locks = lk->admin_next;
222 tl_assert(lk->admin_prev != NULL);
223 lk->admin_prev->admin_next = lk->admin_next;
224 if (lk->admin_next)
225 lk->admin_next->admin_prev = lk->admin_prev;
228 VG_(memset)(lk, 0xAA, sizeof(*lk));
229 HG_(free)(lk);
232 /* Update 'lk' to reflect that 'thr' now has a write-acquisition of
235 static void lockN_acquire_writer ( Lock* lk, Thread* thr )
237 tl_assert(HG_(is_sane_LockN)(lk));
245 if (lk->acquired_at == NULL) {
247 tl_assert(lk->heldBy == NULL);
249 lk->acquired_at
252 tl_assert(lk->heldBy != NULL);
256 switch (lk->kind) {
259 tl_assert(lk->heldBy == NULL); /* can't w-lock recursively */
260 tl_assert(!lk->heldW);
261 lk->heldW = True;
262 lk->heldBy = VG_(newBag)( HG_(zalloc), "hg.lNaw.1", HG_(free) );
263 VG_(addToBag)( lk->heldBy, (Word)thr );
266 if (lk->heldBy == NULL)
269 tl_assert(lk->heldW);
270 /* assert: lk is only held by one thread .. */
271 tl_assert(VG_(sizeUniqueBag(lk->heldBy)) == 1);
273 tl_assert(VG_(elemBag)(lk->heldBy, (Word)thr)
274 == VG_(sizeTotalBag)(lk->heldBy));
275 VG_(addToBag)(lk->heldBy, (Word)thr);
278 tl_assert(lk->heldBy == NULL && !lk->heldW); /* must be unheld */
283 tl_assert(HG_(is_sane_LockN)(lk));
286 static void lockN_acquire_reader ( Lock* lk, Thread* thr )
288 tl_assert(HG_(is_sane_LockN)(lk));
291 tl_assert(lk->kind == LK_rdwr);
292 /* lk must be free or already r-held. */
293 tl_assert(lk->heldBy == NULL
294 || (lk->heldBy != NULL && !lk->heldW));
301 if (lk->acquired_at == NULL) {
303 tl_assert(lk->heldBy == NULL);
305 lk->acquired_at
308 tl_assert(lk->heldBy != NULL);
312 if (lk->heldBy) {
313 VG_(addToBag)(lk->heldBy, (Word)thr);
315 lk->heldW = False;
316 lk->heldBy = VG_(newBag)( HG_(zalloc), "hg.lNar.1", HG_(free) );
317 VG_(addToBag)( lk->heldBy, (Word)thr );
319 tl_assert(!lk->heldW);
320 tl_assert(HG_(is_sane_LockN)(lk));
323 /* Update 'lk' to reflect a release of it by 'thr'. This is done
327 static void lockN_release ( Lock* lk, Thread* thr )
330 tl_assert(HG_(is_sane_LockN)(lk));
333 tl_assert(lk->heldBy);
336 b = VG_(delFromBag)(lk->heldBy, (Word)thr);
337 /* thr must actually have been a holder of lk */
340 tl_assert(lk->acquired_at);
341 if (VG_(isEmptyBag)(lk->heldBy)) {
342 VG_(deleteBag)(lk->heldBy);
343 lk->heldBy = NULL;
344 lk->heldW = False;
345 lk->acquired_at = NULL;
347 tl_assert(HG_(is_sane_LockN)(lk));
350 static void remove_Lock_from_locksets_of_all_owning_Threads( Lock* lk )
353 if (!lk->heldBy) {
354 tl_assert(!lk->heldW);
358 VG_(initIterBag)( lk->heldBy );
359 while (VG_(nextIterBag)( lk->heldBy, (Word*)&thr, NULL )) {
362 thr->locksetA, (Word)lk ));
364 = HG_(delFromWS)( univ_lsets, thr->locksetA, (Word)lk );
366 if (lk->heldW) {
368 thr->locksetW, (Word)lk ));
370 = HG_(delFromWS)( univ_lsets, thr->locksetW, (Word)lk );
373 VG_(doneIterBag)( lk->heldBy );
459 static void pp_Lock ( Int d, Lock* lk )
461 space(d+0); VG_(printf)("Lock %p (ga %#lx) {\n", lk, lk->guestaddr);
463 space(d+3); VG_(printf)("admin_n %p\n", lk->admin_next);
464 space(d+3); VG_(printf)("admin_p %p\n", lk->admin_prev);
465 space(d+3); VG_(printf)("magic 0x%x\n", (UInt)lk->magic);
467 space(d+3); VG_(printf)("unique %llu\n", lk->unique);
468 space(d+3); VG_(printf)("kind %s\n", show_LockKind(lk->kind));
469 space(d+3); VG_(printf)("heldW %s\n", lk->heldW ? "yes" : "no");
470 space(d+3); VG_(printf)("heldBy %p", lk->heldBy);
471 if (lk->heldBy) {
475 VG_(initIterBag)( lk->heldBy );
476 while (VG_(nextIterBag)( lk->heldBy, (Word*)&thr, &count ))
478 VG_(doneIterBag)( lk->heldBy );
488 Lock* lk;
489 for (n = 0, lk = admin_locks; lk; n++, lk = lk->admin_next) {
493 for (i = 0, lk = admin_locks; lk; i++, lk = lk->admin_next) {
498 pp_Lock(d+3, lk);
506 Lock* lk;
511 (Word*)&lk )) {
513 VG_(printf)("guest %p -> Lock %p\n", gla, lk);
701 Lock* lk = NULL;
702 found = VG_(lookupFM)( map_locks, NULL, (Word*)&lk, (Word)ga );
703 tl_assert(found ? lk != NULL : lk == NULL);
704 return lk;
710 Lock* lk = NULL;
712 (Word*)&ga2, (Word*)&lk, (Word)ga );
716 tl_assert(lk != NULL);
739 for lk in Thread.lockset
740 lk == LockedBy(t)
757 for each lk in Locks {
759 lk->tag is valid
760 lk->guest_addr does not have shadow state NoAccess
761 if lk == LockedBy(t), then t->lockset contains lk
762 if lk == UnlockedBy(segid) then segid is valid SegmentID
764 and seg->thr->lockset does not contain lk
765 if lk == UnlockedNew then (no lockset contains lk)
767 secmaps for lk has .mbHasLocks == True
793 each lk in lset is a valid Lock
800 /* Return True iff 'thr' holds 'lk' in some mode. */
801 static Bool thread_is_a_holder_of_Lock ( Thread* thr, Lock* lk )
803 if (lk->heldBy)
804 return VG_(elemBag)( lk->heldBy, (Word)thr ) > 0;
819 Lock* lk;
828 lk = (Lock*)ls_words[i];
830 if (!HG_(is_sane_LockN)(lk)) BAD("2");
833 if (!thread_is_a_holder_of_Lock(thr,lk)) BAD("3");
851 Lock* lk;
854 for (i = 0, lk = admin_locks; lk; i++, lk = lk->admin_next)
857 // for each entry (gla, lk) in map_locks
858 // gla == lk->guest_addr
861 (Word*)&gla, (Word*)&lk )) {
862 if (lk->guestaddr != gla) BAD("2");
866 for (lk = admin_locks; lk; lk = lk->admin_next) {
869 if (!HG_(is_sane_LockN)(lk)) BAD("3");
871 if (lk != map_locks_maybe_lookup(lk->guestaddr)) BAD("4");
874 if (lk->heldBy) {
877 VG_(initIterBag)( lk->heldBy );
878 while (VG_(nextIterBag)( lk->heldBy,
883 if (!HG_(elemWS)(univ_lsets, thr->locksetA, (Word)lk))
886 if (lk->heldW
887 && !HG_(elemWS)(univ_lsets, thr->locksetW, (Word)lk))
889 if ((!lk->heldW)
890 && HG_(elemWS)(univ_lsets, thr->locksetW, (Word)lk))
893 VG_(doneIterBag)( lk->heldBy );
896 if (lk->heldW) BAD("9"); /* should be False if !heldBy */
897 // since lk is unheld, then (no lockset contains lk)
931 static void laog__handle_one_lock_deletion ( Lock* lk ); /* fwds */
1024 Lock* lk;
1029 'HG_(is_sane_LockN)(lk)' is both a pre- and post-condition of this
1040 lk = map_locks_lookup_or_create(
1042 tl_assert( HG_(is_sane_LockN)(lk) );
1046 tl_assert(lk->hbso);
1048 if (lk->heldBy == NULL) {
1050 tl_assert(!lk->heldW);
1051 lockN_acquire_writer( lk, thr );
1053 libhb_so_recv( thr->hbthr, lk->hbso, True/*strong_recv*/ );
1059 tl_assert(lk->heldBy);
1060 if (!lk->heldW) {
1069 tl_assert(VG_(sizeUniqueBag)(lk->heldBy) == 1); /* from precondition */
1071 if (thr != (Thread*)VG_(anyElementOfBag)(lk->heldBy)) {
1084 if (lk->kind != LK_mbRec) {
1093 lockN_acquire_writer( lk, thr );
1096 libhb_so_recv( thr->hbthr, lk->hbso, True/*strong_recv*/ );
1103 laog__pre_thread_acquires_lock( thr, lk );
1106 thr->locksetA = HG_(addToWS)( univ_lsets, thr->locksetA, (Word)lk );
1107 thr->locksetW = HG_(addToWS)( univ_lsets, thr->locksetW, (Word)lk );
1111 tl_assert(HG_(is_sane_LockN)(lk));
1121 Lock* lk;
1126 'HG_(is_sane_LockN)(lk)' is both a pre- and post-condition of this
1139 lk = map_locks_lookup_or_create(
1141 tl_assert( HG_(is_sane_LockN)(lk) );
1145 tl_assert(lk->hbso);
1147 if (lk->heldBy == NULL) {
1149 tl_assert(!lk->heldW);
1150 lockN_acquire_reader( lk, thr );
1152 libhb_so_recv( thr->hbthr, lk->hbso, False/*!strong_recv*/ );
1158 tl_assert(lk->heldBy);
1159 if (lk->heldW) {
1168 lockN_acquire_reader( lk, thr );
1171 libhb_so_recv( thr->hbthr, lk->hbso, False/*!strong_recv*/ );
1178 laog__pre_thread_acquires_lock( thr, lk );
1181 thr->locksetA = HG_(addToWS)( univ_lsets, thr->locksetA, (Word)lk );
1182 /* but don't update thr->locksetW, since lk is only rd-held */
1186 tl_assert(HG_(is_sane_LockN)(lk));
1881 Lock* lk;
1890 lk = map_locks_maybe_lookup( (Addr)mutex );
1892 if (lk == NULL || (lk->kind != LK_nonRec && lk->kind != LK_mbRec)) {
1897 if (lk) {
1898 tl_assert( HG_(is_sane_LockN)(lk) );
1899 tl_assert( lk->guestaddr == (Addr)mutex );
1900 if (lk->heldBy) {
1905 remove_Lock_from_locksets_of_all_owning_Threads( lk );
1906 VG_(deleteBag)( lk->heldBy );
1907 lk->heldBy = NULL;
1908 lk->heldW = False;
1909 lk->acquired_at = NULL;
1911 tl_assert( !lk->heldBy );
1912 tl_assert( HG_(is_sane_LockN)(lk) );
1915 laog__handle_one_lock_deletion(lk);
1916 map_locks_delete( lk->guestaddr );
1917 del_LockN( lk );
1930 Lock* lk;
1939 lk = map_locks_maybe_lookup( (Addr)mutex );
1941 if (lk && (lk->kind == LK_rdwr)) {
1946 if ( lk
1948 && (lk->kind == LK_nonRec || lk->kind == LK_rdwr)
1949 && lk->heldBy
1950 && lk->heldW
1951 && VG_(elemBag)( lk->heldBy, (Word)thr ) > 0 ) {
1959 if (lk->acquired_at) {
1960 HG_(record_error_Misc_w_aux)( thr, errstr, auxstr, lk->acquired_at );
2024 Lock* lk;
2038 lk = map_locks_maybe_lookup( (Addr)slock );
2039 if (lk && lk->heldBy) {
2051 Lock* lk;
2061 lk = map_locks_maybe_lookup( (Addr)slock );
2062 if (!lk) {
2190 //Lock* lk;
2224 Lock* lk = NULL;
2226 lk = map_locks_maybe_lookup( (Addr)cvi->mx_ga );
2228 /* note: lk could be NULL. Be careful. */
2229 if (lk) {
2230 if (lk->kind == LK_rdwr) {
2234 if (lk->heldBy == NULL) {
2239 if (lk->heldBy != NULL && 0 == VG_(elemBag)(lk->heldBy, (Word)thr)) {
2265 Lock* lk;
2277 lk = map_locks_maybe_lookup( (Addr)mutex );
2282 if (lk == NULL) {
2288 tl_assert( HG_(is_sane_LockN)(lk) );
2289 if (lk->kind == LK_rdwr) {
2295 if (lk->heldBy == NULL) {
2300 if (lk->heldBy != NULL
2301 && VG_(elemBag)( lk->heldBy, (Word)thr ) == 0) {
2412 Lock* lk;
2421 lk = map_locks_maybe_lookup( (Addr)rwl );
2423 if (lk == NULL || lk->kind != LK_rdwr) {
2428 if (lk) {
2429 tl_assert( HG_(is_sane_LockN)(lk) );
2430 tl_assert( lk->guestaddr == (Addr)rwl );
2431 if (lk->heldBy) {
2436 remove_Lock_from_locksets_of_all_owning_Threads( lk );
2437 VG_(deleteBag)( lk->heldBy );
2438 lk->heldBy = NULL;
2439 lk->heldW = False;
2440 lk->acquired_at = NULL;
2442 tl_assert( !lk->heldBy );
2443 tl_assert( HG_(is_sane_LockN)(lk) );
2446 laog__handle_one_lock_deletion(lk);
2447 map_locks_delete( lk->guestaddr );
2448 del_LockN( lk );
2463 Lock* lk;
2473 lk = map_locks_maybe_lookup( (Addr)rwl );
2474 if ( lk
2475 && (lk->kind == LK_nonRec || lk->kind == LK_mbRec) ) {
3547 static WordSetID /* in univ_laog */ laog__succs ( Lock* lk ) {
3552 if (VG_(lookupFM)( laog, &keyW, (Word*)&links, (Word)lk )) {
3554 tl_assert(keyW == (Word)lk);
3562 static WordSetID /* in univ_laog */ laog__preds ( Lock* lk ) {
3567 if (VG_(lookupFM)( laog, &keyW, (Word*)&links, (Word)lk )) {
3569 tl_assert(keyW == (Word)lk);
3673 /* Thread 'thr' is acquiring 'lk'. Check for inconsistent ordering
3674 between 'lk' and the locks already held by 'thr' and issue a
3680 Lock* lk
3687 /* It may be that 'thr' already holds 'lk' and is recursively
3690 if (HG_(elemWS)( univ_lsets, thr->locksetA, (Word)lk ))
3693 /* First, the check. Complain if there is any path in laog from lk
3695 existed, it would mean that previously lk was acquired before
3699 other = laog__do_dfs_from_to(lk, thr->locksetA);
3702 /* So we managed to find a path lk --*--> other in the graph,
3703 which implies that 'lk' should have been acquired before
3705 the lk/other arguments to record_error_LockOrder in the order
3709 key.src_ga = lk->guestaddr;
3722 thr, lk->guestaddr, other->guestaddr,
3727 thr, lk->guestaddr, other->guestaddr,
3733 (old, lk) | old <- locks already held by thr
3734 Since both old and lk are currently held by thr, their acquired_at
3737 tl_assert(lk->acquired_at);
3742 laog__add_edge( old, lk );
3773 static void laog__handle_one_lock_deletion ( Lock* lk )
3779 preds = laog__preds( lk );
3780 succs = laog__succs( lk );
3791 laog__del_edge( (Lock*)preds_words[i], lk );
3794 laog__del_edge( lk, (Lock*)succs_words[j] );
3812 // Remove lk information from laog links FM
3818 (UWord*)&linked_lk, (UWord*)&links, (UWord)lk)) {
3819 tl_assert (linked_lk == lk);
3823 /* FIXME ??? What about removing lock lk data from EXPOSITION ??? */