Home | History | Annotate | Download | only in helgrind

Lines Matching defs:lock

70 // FIXME: when client destroys a lock or a CV, remove these
95 // the thread still holds the lock.
128 static Lock* admin_locks = NULL;
133 /* Mapping table for lock guest addresses to Lock* */
134 static WordFM* map_locks = NULL; /* WordFM LockAddr Lock* */
136 /* The word-set universes for lock sets. */
137 static WordSetU* univ_lsets = NULL; /* sets of Lock* */
138 static WordSetU* univ_laog = NULL; /* sets of Lock*, for LAOG */
149 Lock* HG_(get_admin_locks) ( void ) { return admin_locks; }
180 // Make a new lock which is unlocked (hence ownerless)
181 // and insert the new lock in admin_locks double linked list.
182 static Lock* mk_LockN ( LockKind kind, Addr guestaddr ) {
184 Lock* lock = HG_(zalloc)( "hg.mk_Lock.1", sizeof(Lock) );
187 admin_locks->admin_prev = lock;
188 lock->admin_next = admin_locks;
189 lock->admin_prev = NULL;
190 admin_locks = lock;
192 lock->unique = unique++;
193 lock->magic = LockN_MAGIC;
194 lock->appeared_at = NULL;
195 lock->acquired_at = NULL;
196 lock->hbso = libhb_so_alloc();
197 lock->guestaddr = guestaddr;
198 lock->kind = kind;
199 lock->heldW = False;
200 lock->heldBy = NULL;
201 tl_assert(HG_(is_sane_LockN)(lock));
202 return lock;
205 /* Release storage for a Lock. Also release storage in .heldBy, if
207 static void del_LockN ( Lock* lk )
214 /* begin: del lock from double linked list */
235 static void lockN_acquire_writer ( Lock* lk, Thread* thr )
243 /* We need to keep recording snapshots of where the lock was
244 acquired, so as to produce better lock-order error messages. */
259 tl_assert(lk->heldBy == NULL); /* can't w-lock recursively */
268 /* 2nd and subsequent locking of a lock by its owner */
286 static void lockN_acquire_reader ( Lock* lk, Thread* thr )
290 /* can only add reader to a reader-writer lock. */
299 /* We need to keep recording snapshots of where the lock was
300 acquired, so as to produce better lock-order error messages. */
327 static void lockN_release ( Lock* lk, Thread* thr )
332 /* lock must be held by someone */
350 static void remove_Lock_from_locksets_of_all_owning_Threads( Lock* lk )
357 /* for each thread that holds this lock do ... */
459 static void pp_Lock ( Int d, Lock* lk )
461 space(d+0); VG_(printf)("Lock %p (ga %#lx) {\n", lk, lk->guestaddr);
488 Lock* lk;
506 Lock* lk;
513 VG_(printf)("guest %p -> Lock %p\n", gla, lk);
669 /*--- map_locks :: WordFM guest-Addr-of-lock Lock* ---*/
672 /* Make sure there is a lock table entry for the given (lock) guest
674 In any case, return the address of the existing or new Lock. */
676 Lock* map_locks_lookup_or_create ( LockKind lkk, Addr ga, ThreadId tid )
679 Lock* oldlock = NULL;
684 Lock* lock = mk_LockN(lkk, ga);
685 lock->appeared_at = VG_(record_ExeContext)( tid, 0 );
686 tl_assert(HG_(is_sane_LockN)(lock));
687 VG_(addToFM)( map_locks, (Word)ga, (Word)lock );
689 return lock;
698 static Lock* map_locks_maybe_lookup ( Addr ga )
701 Lock* lk = NULL;
710 Lock* lk = NULL;
715 are deleting a (ga, Lock) pair which actually exists. */
732 Thread vs Segment/Lock/SecMaps
736 // Thread.lockset: each element is really a valid Lock
738 // Thread.lockset: each Lock in set is actually held by that thread
748 (that is, no lock is claimed to be held by more than one thread)
752 Lock vs Thread/Segment/SecMaps
771 Segment vs Thread/Lock/SecMaps
783 SecMaps vs Segment/Thread/Lock
793 each lk in lset is a valid Lock
801 static Bool thread_is_a_holder_of_Lock ( Thread* thr, Lock* lk )
819 Lock* lk;
828 lk = (Lock*)ls_words[i];
829 // Thread.lockset: each element is really a valid Lock
831 // Thread.lockset: each Lock in set is actually held by that
851 Lock* lk;
867 // lock is sane. Quite comprehensive, also checks that
870 // map_locks binds guest address back to this lock
872 // look at all threads mentioned as holders of this lock. Ensure
873 // this lock is mentioned in their locksets.
895 /* lock not held by anybody */
927 static void laog__pre_thread_acquires_lock ( Thread*, Lock* ); /* fwds */
931 static void laog__handle_one_lock_deletion ( Lock* lk ); /* fwds */
1018 /* The lock at 'lock_ga' has acquired a writer. Make all necessary
1024 Lock* lk;
1027 However, that will barf if any 'invalid' lock states would
1032 Because this routine is only called after successful lock
1033 acquisition, we should not be asked to move the lock into any
1038 /* Try to find the lock. If we can't, then create a new one with
1049 /* the lock isn't held. Simple. */
1052 /* acquire a dependency from the lock's VCs */
1057 /* So the lock is already held. If held as a r-lock then
1062 thr, "Bug in libpthread: write lock "
1067 /* So the lock is held in w-mode. If it's held by some other
1073 thr, "Bug in libpthread: write lock "
1079 /* So the lock is already held in w-mode by 'thr'. That means this
1080 is an attempt to lock it recursively, which is only allowable
1082 once the lock has been acquired, this must also be a libpthread
1086 thr, "Bug in libpthread: recursive write lock "
1092 /* So we are recursively re-locking a lock we already w-hold. */
1094 /* acquire a dependency from the lock's VC. Probably pointless,
1101 /* check lock order acquisition graph, and update. This has to
1102 happen before the lock is added to the thread's locksetA/W. */
1115 /* The lock at 'lock_ga' has acquired a reader. Make all necessary
1121 Lock* lk;
1124 However, that will barf if any 'invalid' lock states would
1129 Because this routine is only called after successful lock
1130 acquisition, we should not be asked to move the lock into any
1135 /* Try to find the lock. If we can't, then create a new one with
1136 kind 'lkk'. Only a reader-writer lock can be read-locked,
1148 /* the lock isn't held. Simple. */
1151 /* acquire a dependency from the lock's VC */
1156 /* So the lock is already held. If held as a w-lock then
1160 HG_(record_error_Misc)( thr, "Bug in libpthread: read lock "
1166 /* Easy enough. In short anybody can get a read-lock on a rwlock
1169 /* acquire a dependency from the lock's VC. Probably pointless,
1176 /* check lock order acquisition graph, and update. This has to
1177 happen before the lock is added to the thread's locksetA/W. */
1190 /* The lock at 'lock_ga' is just about to be unlocked. Make all
1196 Lock* lock;
1200 /* This routine is called prior to a lock release, before
1202 to detect and reject any attempts to move the lock into an
1206 should refer to a reader-writer lock, and is False if [ditto]
1210 lock = map_locks_maybe_lookup( lock_ga );
1212 if (!lock) {
1213 /* We know nothing about a lock at 'lock_ga'. Nevertheless
1220 tl_assert(lock->guestaddr == lock_ga);
1221 tl_assert(HG_(is_sane_LockN)(lock));
1223 if (isRDWR && lock->kind != LK_rdwr) {
1227 if ((!isRDWR) && lock->kind == LK_rdwr) {
1232 if (!lock->heldBy) {
1233 /* The lock is not held. This indicates a serious bug in the
1235 tl_assert(!lock->heldW);
1236 HG_(record_error_UnlockUnlocked)( thr, lock );
1237 tl_assert(!HG_(elemWS)( univ_lsets, thr->locksetA, (Word)lock ));
1238 tl_assert(!HG_(elemWS)( univ_lsets, thr->locksetW, (Word)lock ));
1243 tl_assert(lock->heldBy);
1244 was_heldW = lock->heldW;
1246 /* The lock is held. Is this thread one of the holders? If not,
1248 n = VG_(elemBag)( lock->heldBy, (Word)thr );
1251 /* We are not a current holder of the lock. This is a bug in
1255 Thread* realOwner = (Thread*)VG_(anyElementOfBag)( lock->heldBy );
1258 tl_assert(!HG_(elemWS)( univ_lsets, thr->locksetA, (Word)lock ));
1259 tl_assert(!HG_(elemWS)( univ_lsets, thr->locksetW, (Word)lock ));
1260 HG_(record_error_UnlockForeign)( thr, realOwner, lock );
1264 /* Ok, we hold the lock 'n' times. */
1267 lockN_release( lock, thr );
1273 tl_assert(lock->heldBy);
1274 tl_assert(n == VG_(elemBag)( lock->heldBy, (Word)thr ));
1275 /* We still hold the lock. So either it's a recursive lock
1277 tl_assert(lock->kind == LK_mbRec
1278 || (lock->kind == LK_rdwr && !lock->heldW));
1279 tl_assert(HG_(elemWS)( univ_lsets, thr->locksetA, (Word)lock ));
1280 if (lock->heldW)
1281 tl_assert(HG_(elemWS)( univ_lsets, thr->locksetW, (Word)lock ));
1283 tl_assert(!HG_(elemWS)( univ_lsets, thr->locksetW, (Word)lock ));
1285 /* n is zero. This means we don't hold the lock any more. But
1288 if (lock->kind == LK_rdwr && lock->heldBy) {
1293 which in turn implies it must be r-held, since a lock
1295 /* The lock is now R-held by somebody else: */
1296 tl_assert(lock->heldW == False);
1302 simultaneously), it must mean the lock is now not held by
1304 /* The lock is now not held by anybody: */
1305 tl_assert(!lock->heldBy);
1306 tl_assert(lock->heldW == False);
1308 //if (lock->heldBy) {
1309 // tl_assert(0 == VG_(elemBag)( lock->heldBy, (Word)thr ));
1313 = HG_(delFromWS)( univ_lsets, thr->locksetA, (Word)lock );
1315 = HG_(delFromWS)( univ_lsets, thr->locksetW, (Word)lock );
1316 /* push our VC into the lock */
1318 tl_assert(lock->hbso);
1319 /* If the lock was previously W-held, then we want to do a
1321 libhb_so_send( thr->hbthr, lock->hbso, was_heldW );
1326 tl_assert(HG_(is_sane_LockN)(lock));
1587 VG_(sprintf)(buf, "Exiting thread still holds %d lock%s",
1859 /* EXPOSITION only: by intercepting lock init events we can show the
1860 user where the lock was initialised, rather than only being able to
1861 show where it was first locked. Intercepting lock initialisations
1881 Lock* lk;
1901 /* Basically act like we unlocked the lock */
1904 /* remove lock from locksets of all owning threads */
1930 Lock* lk;
1952 /* uh, it's a non-recursive lock and we already w-hold it, and
1953 this is a real lock operation (not a speculative "tryLock"
1956 HChar* errstr = "Attempt to re-lock a "
1957 "non-recursive lock I already hold";
1958 HChar* auxstr = "Lock was previously acquired";
1980 LK_mbRec, /* if not known, create new lock with this LockKind */
2024 Lock* lk;
2051 Lock* lk;
2052 /* More kludgery. If the lock has never been seen before, do
2190 //Lock* lk;
2208 // is desired." For that reason, print "dubious" if the lock isn't
2224 Lock* lk = NULL;
2232 "pthread_cond_{signal,broadcast}: associated lock is a rwlock");
2237 "associated lock is not held by any thread");
2242 "associated lock is not held by calling thread");
2265 Lock* lk;
2412 Lock* lk;
2432 /* Basically act like we unlocked the lock */
2435 /* remove lock from locksets of all owning threads */
2463 Lock* lk;
2476 /* Wrong kind of lock. Duh. */
2478 thr, "pthread_rwlock_{rd,rw}lock with a "
2499 LK_rdwr, /* if not known, create new lock with this LockKind */
3231 /*--- Lock acquisition order monitoring ---*/
3267 /* lock order acquisition graph */
3268 static WordFM* laog = NULL; /* WordFM Lock* LAOGLinks* */
3275 Addr src_ga; /* Lock guest addresses for */
3316 Lock* me;
3396 // lock/unlock operations), t2t 50 10 2 was about 25% faster than the
3399 // On smaller lock sets (e.g. t2t 20 5 2, giving about 100 locks), the
3420 static void laog__add_edge ( Lock* src, Lock* dst ) {
3503 static void laog__del_edge ( Lock* src, Lock* dst ) {
3547 static WordSetID /* in univ_laog */ laog__succs ( Lock* lk ) {
3562 static WordSetID /* in univ_laog */ laog__preds ( Lock* lk ) {
3580 Lock* me;
3593 laog__succs( (Lock*)ws_words[i] ),
3600 laog__preds( (Lock*)ws_words[i] ),
3622 Lock* laog__do_dfs_from_to ( Lock* src, WordSetID dsts /* univ_lsets */ )
3624 Lock* ret;
3626 XArray* stack; /* of Lock* */
3627 WordFM* visited; /* Lock* -> void, iow, Set(Lock*) */
3628 Lock* here;
3640 stack = VG_(newXA)( HG_(zalloc), "hg.lddft.1", HG_(free), sizeof(Lock*) );
3651 here = *(Lock**) VG_(indexXA)( stack, ssz-1 );
3679 Thread* thr, /* NB: BEFORE lock is added */
3680 Lock* lk
3685 Lock* other;
3740 Lock* old = (Lock*)ls_words[i];
3745 /* Why "except_Locks" ? We're here because a lock is being
3770 /* Delete from 'laog' any pair mentioning a lock in locksToDelete */
3773 static void laog__handle_one_lock_deletion ( Lock* lk )
3791 laog__del_edge( (Lock*)preds_words[i], lk );
3794 laog__del_edge( lk, (Lock*)succs_words[j] );
3802 laog__add_edge( (Lock*)preds_words[i], (Lock*)succs_words[j] );
3815 Lock* linked_lk;
3823 /* FIXME ??? What about removing lock lk data from EXPOSITION ??? */
3838 // laog__handle_one_lock_deletion( (Lock*)ws_words[i] );
4021 old range contained a lock, then die_mem_heap will complain.
4692 /* EXPOSITION only: by intercepting lock init events we can show
4693 the user where the lock was initialised, rather than only
4695 lock initialisations is not necessary for the basic operation
4949 " --track-lockorders=no|yes show lock ordering errors? [yes]\n"
4968 "lock-order-acquisition-graph\n");
4972 VG_(printf)(" 000010 at lock/unlock events\n");
5027 VG_(printf)(" locksets: %'8d unique lock sets\n",
5030 VG_(printf)(" univ_laog: %'8d unique lock sets\n",