Home | History | Annotate | Download | only in helgrind

Lines Matching defs:lk

225 static void del_LockN ( Lock* lk ) 
227 tl_assert(HG_(is_sane_LockN)(lk));
228 tl_assert(lk->hbso);
229 libhb_so_dealloc(lk->hbso);
230 if (lk->heldBy)
231 VG_(deleteBag)( lk->heldBy );
233 if (lk == admin_locks) {
234 tl_assert(lk->admin_prev == NULL);
235 if (lk->admin_next)
236 lk->admin_next->admin_prev = NULL;
237 admin_locks = lk->admin_next;
240 tl_assert(lk->admin_prev != NULL);
241 lk->admin_prev->admin_next = lk->admin_next;
242 if (lk->admin_next)
243 lk->admin_next->admin_prev = lk->admin_prev;
246 VG_(memset)(lk, 0xAA, sizeof(*lk));
247 HG_(free)(lk);
250 /* Update 'lk' to reflect that 'thr' now has a write-acquisition of
253 static void lockN_acquire_writer ( Lock* lk, Thread* thr )
255 tl_assert(HG_(is_sane_LockN)(lk));
263 if (lk->acquired_at == NULL) {
265 tl_assert(lk->heldBy == NULL);
267 lk->acquired_at
270 tl_assert(lk->heldBy != NULL);
274 switch (lk->kind) {
277 tl_assert(lk->heldBy == NULL); /* can't w-lock recursively */
278 tl_assert(!lk->heldW);
279 lk->heldW = True;
280 lk->heldBy = VG_(newBag)( HG_(zalloc), "hg.lNaw.1", HG_(free) );
281 VG_(addToBag)( lk->heldBy, (UWord)thr );
284 if (lk->heldBy == NULL)
287 tl_assert(lk->heldW);
288 /* assert: lk is only held by one thread .. */
289 tl_assert(VG_(sizeUniqueBag)(lk->heldBy) == 1);
291 tl_assert(VG_(elemBag)(lk->heldBy, (UWord)thr)
292 == VG_(sizeTotalBag)(lk->heldBy));
293 VG_(addToBag)(lk->heldBy, (UWord)thr);
296 tl_assert(lk->heldBy == NULL && !lk->heldW); /* must be unheld */
301 tl_assert(HG_(is_sane_LockN)(lk));
304 static void lockN_acquire_reader ( Lock* lk, Thread* thr )
306 tl_assert(HG_(is_sane_LockN)(lk));
309 tl_assert(lk->kind == LK_rdwr);
310 /* lk must be free or already r-held. */
311 tl_assert(lk->heldBy == NULL
312 || (lk->heldBy != NULL && !lk->heldW));
319 if (lk->acquired_at == NULL) {
321 tl_assert(lk->heldBy == NULL);
323 lk->acquired_at
326 tl_assert(lk->heldBy != NULL);
330 if (lk->heldBy) {
331 VG_(addToBag)(lk->heldBy, (UWord)thr);
333 lk->heldW = False;
334 lk->heldBy = VG_(newBag)( HG_(zalloc), "hg.lNar.1", HG_(free) );
335 VG_(addToBag)( lk->heldBy, (UWord)thr );
337 tl_assert(!lk->heldW);
338 tl_assert(HG_(is_sane_LockN)(lk));
341 /* Update 'lk' to reflect a release of it by 'thr'. This is done
345 static void lockN_release ( Lock* lk, Thread* thr )
348 tl_assert(HG_(is_sane_LockN)(lk));
351 tl_assert(lk->heldBy);
354 b = VG_(delFromBag)(lk->heldBy, (UWord)thr);
355 /* thr must actually have been a holder of lk */
358 tl_assert(lk->acquired_at);
359 if (VG_(isEmptyBag)(lk->heldBy)) {
360 VG_(deleteBag)(lk->heldBy);
361 lk->heldBy = NULL;
362 lk->heldW = False;
363 lk->acquired_at = NULL;
365 tl_assert(HG_(is_sane_LockN)(lk));
368 static void remove_Lock_from_locksets_of_all_owning_Threads( Lock* lk )
371 if (!lk->heldBy) {
372 tl_assert(!lk->heldW);
376 VG_(initIterBag)( lk->heldBy );
377 while (VG_(nextIterBag)( lk->heldBy, (UWord*)&thr, NULL )) {
380 thr->locksetA, (UWord)lk ));
382 = HG_(delFromWS)( univ_lsets, thr->locksetA, (UWord)lk );
384 if (lk->heldW) {
386 thr->locksetW, (UWord)lk ));
388 = HG_(delFromWS)( univ_lsets, thr->locksetW, (UWord)lk );
391 VG_(doneIterBag)( lk->heldBy );
477 /* Pretty Print lock lk.
482 static void pp_Lock ( Int d, Lock* lk,
488 VG_(printf)("Lock %p (ga %#lx) {\n", lk, lk->guestaddr);
490 VG_(printf)("Lock ga %#lx {\n", lk->guestaddr);
492 || !HG_(get_and_pp_addrdescr) ((Addr) lk->guestaddr))
496 space(d+3); VG_(printf)("admin_n %p\n", lk->admin_next);
497 space(d+3); VG_(printf)("admin_p %p\n", lk->admin_prev);
498 space(d+3); VG_(printf)("magic 0x%x\n", (UInt)lk->magic);
501 space(d+3); VG_(printf)("unique %llu\n", lk->unique);
503 lk->kind));
505 space(d+3); VG_(printf)("heldW %s\n", lk->heldW ? "yes" : "no");
508 space(d+3); VG_(printf)("heldBy %p", lk->heldBy);
510 if (lk->heldBy) {
514 VG_(initIterBag)( lk->heldBy );
515 while (VG_(nextIterBag)( lk->heldBy, (UWord*)&thr, &count )) {
520 lk->heldW ? 'W' : 'R',
529 VG_(doneIterBag)( lk->heldBy );
538 Lock* lk;
539 for (n = 0, lk = admin_locks; lk; n++, lk = lk->admin_next) {
543 for (i = 0, lk = admin_locks; lk; i++, lk = lk->admin_next) {
548 pp_Lock(d+3, lk,
558 Lock* lk;
563 (UWord*)&lk )) {
565 VG_(printf)("guest %p -> Lock %p\n", gla, lk);
777 Lock* lk = NULL;
778 found = VG_(lookupFM)( map_locks, NULL, (UWord*)&lk, (UWord)ga );
779 tl_assert(found ? lk != NULL : lk == NULL);
780 return lk;
786 Lock* lk = NULL;
788 (UWord*)&ga2, (UWord*)&lk, (UWord)ga );
792 tl_assert(lk != NULL);
815 for lk in Thread.lockset
816 lk == LockedBy(t)
833 for each lk in Locks {
835 lk->tag is valid
836 lk->guest_addr does not have shadow state NoAccess
837 if lk == LockedBy(t), then t->lockset contains lk
838 if lk == UnlockedBy(segid) then segid is valid SegmentID
840 and seg->thr->lockset does not contain lk
841 if lk == UnlockedNew then (no lockset contains lk)
843 secmaps for lk has .mbHasLocks == True
869 each lk in lset is a valid Lock
876 /* Return True iff 'thr' holds 'lk' in some mode. */
877 static Bool thread_is_a_holder_of_Lock ( Thread* thr, Lock* lk )
879 if (lk->heldBy)
880 return VG_(elemBag)( lk->heldBy, (UWord)thr ) > 0;
895 Lock* lk;
904 lk = (Lock*)ls_words[i];
906 if (!HG_(is_sane_LockN)(lk)) BAD("2");
909 if (!thread_is_a_holder_of_Lock(thr,lk)) BAD("3");
927 Lock* lk;
930 for (i = 0, lk = admin_locks; lk; i++, lk = lk->admin_next)
933 // for each entry (gla, lk) in map_locks
934 // gla == lk->guest_addr
937 (UWord*)&gla, (UWord*)&lk )) {
938 if (lk->guestaddr != gla) BAD("2");
942 for (lk = admin_locks; lk; lk = lk->admin_next) {
945 if (!HG_(is_sane_LockN)(lk)) BAD("3");
947 if (lk != map_locks_maybe_lookup(lk->guestaddr)) BAD("4");
950 if (lk->heldBy) {
953 VG_(initIterBag)( lk->heldBy );
954 while (VG_(nextIterBag)( lk->heldBy,
959 if (!HG_(elemWS)(univ_lsets, thr->locksetA, (UWord)lk))
962 if (lk->heldW
963 && !HG_(elemWS)(univ_lsets, thr->locksetW, (UWord)lk))
965 if ((!lk->heldW)
966 && HG_(elemWS)(univ_lsets, thr->locksetW, (UWord)lk))
969 VG_(doneIterBag)( lk->heldBy );
972 if (lk->heldW) BAD("9"); /* should be False if !heldBy */
973 // since lk is unheld, then (no lockset contains lk)
1007 static void laog__handle_one_lock_deletion ( Lock* lk ); /* fwds */
1100 Lock* lk;
1105 'HG_(is_sane_LockN)(lk)' is both a pre- and post-condition of this
1116 lk = map_locks_lookup_or_create(
1118 tl_assert( HG_(is_sane_LockN)(lk) );
1122 tl_assert(lk->hbso);
1124 if (lk->heldBy == NULL) {
1126 tl_assert(!lk->heldW);
1127 lockN_acquire_writer( lk, thr );
1129 libhb_so_recv( thr->hbthr, lk->hbso, True/*strong_recv*/ );
1135 tl_assert(lk->heldBy);
1136 if (!lk->heldW) {
1145 tl_assert(VG_(sizeUniqueBag)(lk->heldBy) == 1); /* from precondition */
1147 if (thr != (Thread*)VG_(anyElementOfBag)(lk->heldBy)) {
1160 if (lk->kind != LK_mbRec) {
1169 lockN_acquire_writer( lk, thr );
1172 libhb_so_recv( thr->hbthr, lk->hbso, True/*strong_recv*/ );
1179 laog__pre_thread_acquires_lock( thr, lk );
1182 thr->locksetA = HG_(addToWS)( univ_lsets, thr->locksetA, (UWord)lk );
1183 thr->locksetW = HG_(addToWS)( univ_lsets, thr->locksetW, (UWord)lk );
1187 tl_assert(HG_(is_sane_LockN)(lk));
1197 Lock* lk;
1202 'HG_(is_sane_LockN)(lk)' is both a pre- and post-condition of this
1215 lk = map_locks_lookup_or_create(
1217 tl_assert( HG_(is_sane_LockN)(lk) );
1221 tl_assert(lk->hbso);
1223 if (lk->heldBy == NULL) {
1225 tl_assert(!lk->heldW);
1226 lockN_acquire_reader( lk, thr );
1228 libhb_so_recv( thr->hbthr, lk->hbso, False/*!strong_recv*/ );
1234 tl_assert(lk->heldBy);
1235 if (lk->heldW) {
1244 lockN_acquire_reader( lk, thr );
1247 libhb_so_recv( thr->hbthr, lk->hbso, False/*!strong_recv*/ );
1254 laog__pre_thread_acquires_lock( thr, lk );
1257 thr->locksetA = HG_(addToWS)( univ_lsets, thr->locksetA, (UWord)lk );
1258 /* but don't update thr->locksetW, since lk is only rd-held */
1262 tl_assert(HG_(is_sane_LockN)(lk));
2022 Lock* lk;
2032 lk = map_locks_maybe_lookup( (Addr)mutex );
2034 if (lk == NULL && mutex_is_init) {
2042 if (lk == NULL || (lk->kind != LK_nonRec && lk->kind != LK_mbRec)) {
2047 if (lk) {
2048 tl_assert( HG_(is_sane_LockN)(lk) );
2049 tl_assert( lk->guestaddr == (Addr)mutex );
2050 if (lk->heldBy) {
2055 remove_Lock_from_locksets_of_all_owning_Threads( lk );
2056 VG_(deleteBag)( lk->heldBy );
2057 lk->heldBy = NULL;
2058 lk->heldW = False;
2059 lk->acquired_at = NULL;
2061 tl_assert( !lk->heldBy );
2062 tl_assert( HG_(is_sane_LockN)(lk) );
2065 laog__handle_one_lock_deletion(lk);
2066 map_locks_delete( lk->guestaddr );
2067 del_LockN( lk );
2081 Lock* lk;
2090 lk = map_locks_maybe_lookup( (Addr)mutex );
2092 if (lk && (lk->kind == LK_rdwr)) {
2097 if ( lk
2099 && (lk->kind == LK_nonRec || lk->kind == LK_rdwr)
2100 && lk->heldBy
2101 && lk->heldW
2102 && VG_(elemBag)( lk->heldBy, (UWord)thr ) > 0 ) {
2110 if (lk->acquired_at) {
2111 HG_(record_error_Misc_w_aux)( thr, errstr, auxstr, lk->acquired_at );
2175 Lock* lk;
2189 lk = map_locks_maybe_lookup( (Addr)slock );
2190 if (lk && lk->heldBy) {
2202 Lock* lk;
2212 lk = map_locks_maybe_lookup( (Addr)slock );
2213 if (!lk) {
2352 //Lock* lk;
2386 Lock* lk = NULL;
2388 lk = map_locks_maybe_lookup( (Addr)cvi->mx_ga );
2390 /* note: lk could be NULL. Be careful. */
2391 if (lk) {
2392 if (lk->kind == LK_rdwr) {
2396 if (lk->heldBy == NULL) {
2401 if (lk->heldBy != NULL && 0 == VG_(elemBag)(lk->heldBy, (UWord)thr)) {
2427 Lock* lk;
2439 lk = map_locks_maybe_lookup( (Addr)mutex );
2444 if (lk == NULL) {
2450 tl_assert( HG_(is_sane_LockN)(lk) );
2451 if (lk->kind == LK_rdwr) {
2457 if (lk->heldBy == NULL) {
2462 if (lk->heldBy != NULL
2463 && VG_(elemBag)( lk->heldBy, (UWord)thr ) == 0) {
2591 Lock* lk;
2600 lk = map_locks_maybe_lookup( (Addr)rwl );
2602 if (lk == NULL || lk->kind != LK_rdwr) {
2607 if (lk) {
2608 tl_assert( HG_(is_sane_LockN)(lk) );
2609 tl_assert( lk->guestaddr == (Addr)rwl );
2610 if (lk->heldBy) {
2615 remove_Lock_from_locksets_of_all_owning_Threads( lk );
2616 VG_(deleteBag)( lk->heldBy );
2617 lk->heldBy = NULL;
2618 lk->heldW = False;
2619 lk->acquired_at = NULL;
2621 tl_assert( !lk->heldBy );
2622 tl_assert( HG_(is_sane_LockN)(lk) );
2625 laog__handle_one_lock_deletion(lk);
2626 map_locks_delete( lk->guestaddr );
2627 del_LockN( lk );
2642 Lock* lk;
2652 lk = map_locks_maybe_lookup( (Addr)rwl );
2653 if ( lk
2654 && (lk->kind == LK_nonRec || lk->kind == LK_mbRec) ) {
3760 static WordSetID /* in univ_laog */ laog__succs ( Lock* lk ) {
3765 if (VG_(lookupFM)( laog, &keyW, (UWord*)&links, (UWord)lk )) {
3767 tl_assert(keyW == (UWord)lk);
3775 static WordSetID /* in univ_laog */ laog__preds ( Lock* lk ) {
3780 if (VG_(lookupFM)( laog, &keyW, (UWord*)&links, (UWord)lk )) {
3782 tl_assert(keyW == (UWord)lk);
3886 /* Thread 'thr' is acquiring 'lk'. Check for inconsistent ordering
3887 between 'lk' and the locks already held by 'thr' and issue a
3893 Lock* lk
3900 /* It may be that 'thr' already holds 'lk' and is recursively
3903 if (HG_(elemWS)( univ_lsets, thr->locksetA, (UWord)lk ))
3906 /* First, the check. Complain if there is any path in laog from lk
3908 existed, it would mean that previously lk was acquired before
3912 other = laog__do_dfs_from_to(lk, thr->locksetA);
3915 /* So we managed to find a path lk --*--> other in the graph,
3916 which implies that 'lk' should have been acquired before
3918 the lk/other arguments to record_error_LockOrder in the order
3922 key.src_ga = lk->guestaddr;
3935 thr, lk, other,
3980 lk is being taken), and the stack trace where other was acquired:
3985 thr, lk, other,
3991 (old, lk) | old <- locks already held by thr
3992 Since both old and lk are currently held by thr, their acquired_at
3995 tl_assert(lk->acquired_at);
4000 laog__add_edge( old, lk );
4031 static void laog__handle_one_lock_deletion ( Lock* lk )
4037 preds = laog__preds( lk );
4038 succs = laog__succs( lk );
4049 laog__del_edge( (Lock*)preds_words[i], lk );
4052 laog__del_edge( lk, (Lock*)succs_words[j] );
4070 // Remove lk information from laog links FM
4076 (UWord*)&linked_lk, (UWord*)&links, (UWord)lk)) {
4077 tl_assert (linked_lk == lk);
4081 /* FIXME ??? What about removing lock lk data from EXPOSITION ??? */
4969 Lock* lk;
4979 for (i = 0, lk = admin_locks; lk; i++, lk = lk->admin_next) {
4980 if (all_locks || lk_addr == lk->guestaddr) {
4981 pp_Lock(0, lk,