Lines Matching defs:lock

32 #include <sys/lock.h>
50 * distinction between locks and condition variables. A lock may have
52 * always associated with exactly one lock. There is a strict topology.
58 * - It means that a futex object for a lock exists when it is unlocked,
60 * can be requeued to a lock even if the thread performing the wakeup
61 * does not have the lock mapped in its address space.
63 * This futex implementation only implements a single lock type, namely
64 * a read-write lock. A regular mutex type would not be necessary, as
65 * the read-write lock is as efficient as a mutex if used as such.
83 * thread manages to reacquire the lock, it requeues its donated threads
84 * to the lock.
117 /* The lock the waiters should be moved to when signalled. */
124 * being blocked on the lock after being requeued.
134 /* Address of the lock. */
138 * Current owner of the lock. LOCK_UNMANAGED if the lock is
140 * the owner is not known (e.g., when the lock is read-locked).
146 /* Writers blocked on the lock. */
148 /* Readers blocked on the lock. */
150 /* Number of threads blocked on this lock + condition variables. */
179 SX_SYSINIT(futex_global_lock, &futex_global_lock, "CloudABI futex global lock");
275 /* Found matching lock object. */
290 const cloudabi_lock_t *lock, cloudabi_scope_t lock_scope,
301 error = futex_address_create(&fa_lock, td, lock, lock_scope);
313 /* Condition variable is owned by a different lock. */
374 * A futex lock can only be kernel-managed if it has waiters.
375 * Vice versa: if a futex lock has waiters, it must be
409 /* Found matching lock object. */
416 /* None found. Create new lock object. */
429 cloudabi_lock_t *lock, cloudabi_clockid_t clock_id,
435 error = futex_lock_tryrdlock(fl, lock);
439 ("Attempted to sleep on an unmanaged lock"));
443 ("Should have locked write lock on success"));
448 futex_lock_unmanage(fl, lock);
460 ("Attempted to free a managed lock"));
469 futex_lock_unmanage(struct futex_lock *fl, cloudabi_lock_t *lock)
480 error = futex_user_load(lock, &old);
485 error = futex_user_cmpxchg(lock, cmp, &old,
496 /* Sets an owner of a lock, based on a userspace lock value. */
498 futex_lock_set_owner(struct futex_lock *fl, cloudabi_lock_t lock)
502 if ((lock & ~CLOUDABI_LOCK_WRLOCKED) == 0) {
506 lock &= ~(CLOUDABI_LOCK_WRLOCKED | CLOUDABI_LOCK_KERNEL_MANAGED);
509 if (lock == LOCK_UNMANAGED) {
513 fl->fl_owner = lock;
518 cloudabi_lock_t *lock)
523 error = futex_lock_update_owner(fl, lock);
528 return (futex_lock_wake_up_next(fl, lock));
531 /* Syncs in the owner of the lock from userspace if needed. */
535 cloudabi_lock_t lock;
539 error = futex_user_load(address, &lock);
542 futex_lock_set_owner(fl, lock);
562 * Userspace lock is kernel-managed, even though
605 /* Attempted to acquire lock recursively. */
617 * Userspace lock is kernel-managed, even though
623 /* Attempted to acquire lock recursively. */
659 futex_lock_wake_up_next(struct futex_lock *fl, cloudabi_lock_t *lock)
674 error = futex_user_store(lock,
684 error = futex_user_store(lock,
695 error = futex_user_store(lock,
709 cloudabi_lock_t *lock, cloudabi_clockid_t clock_id,
716 error = futex_lock_trywrlock(fl, lock, td->td_tid,
734 /* Suspend execution if the lock was busy. */
736 ("Attempted to sleep on an unmanaged lock"));
740 ("Should have locked write lock on success"));
745 futex_lock_unmanage(fl, lock);
851 * the lock. In other words, we didn't actually
853 * lock to be reacquired.
977 cloudabi_scope_t condvar_scope, cloudabi_lock_t *lock,
987 error = futex_condvar_lookup_or_create(td, condvar, condvar_scope, lock,
1004 /* Drop the lock. */
1005 error = futex_lock_unlock(fl, td, lock);
1017 /* Waited and got the lock assigned to us. */
1024 * Got woken up without having the lock assigned to us.
1029 * associated lock is unlocked. We are the first
1031 * responsible for reacquiring the userspace lock.
1033 error2 = futex_lock_wrlock(fl, td, lock,
1041 futex_lock_unmanage(fl, lock);
1049 cloudabi_futex_lock_rdlock(struct thread *td, cloudabi_lock_t *lock,
1056 /* Look up lock object. */
1057 error = futex_lock_lookup(td, lock, scope, &fl);
1061 error = futex_lock_rdlock(fl, td, lock, clock_id, timeout,
1068 cloudabi_futex_lock_wrlock(struct thread *td, cloudabi_lock_t *lock,
1076 /* Look up lock object. */
1077 error = futex_lock_lookup(td, lock, scope, &fl);
1082 error = futex_lock_wrlock(fl, td, lock, clock_id, timeout,
1117 * The lock is currently not managed by the kernel,
1118 * meaning we must attempt to acquire the userspace lock
1119 * first. We cannot requeue threads to an unmanaged lock,
1122 * Unfortunately, the memory address of the lock is
1124 * acquire the lock on behalf of the first thread to be
1125 * scheduled. The lock may even not be mapped within the
1129 * attempt to acquire the lock. Donate all of the other
1131 * it can requeue them after acquiring the lock.
1138 * condition variable directly to the associated lock.
1156 error = futex_lock_lookup(td, uap->lock, uap->scope, &fl);
1159 error = futex_lock_unlock(fl, td, uap->lock);