Lines Matching full:mutex

16 #include <linux/mutex.h>
64 } mutex; member
132 struct mutex wait_all_lock;
238 if (obj->u.mutex.owner && obj->u.mutex.owner != owner) in is_signaled()
240 return obj->u.mutex.count < UINT_MAX; in is_signaled()
287 if (obj->u.mutex.ownerdead) in try_wake_all()
289 obj->u.mutex.ownerdead = false; in try_wake_all()
290 obj->u.mutex.count++; in try_wake_all()
291 obj->u.mutex.owner = q->owner; in try_wake_all()
340 static void try_wake_any_mutex(struct ntsync_obj *mutex) in try_wake_any_mutex() argument
344 ntsync_assert_held(mutex); in try_wake_any_mutex()
345 lockdep_assert(mutex->type == NTSYNC_TYPE_MUTEX); in try_wake_any_mutex()
347 list_for_each_entry(entry, &mutex->any_waiters, node) { in try_wake_any_mutex()
351 if (mutex->u.mutex.count == UINT_MAX) in try_wake_any_mutex()
353 if (mutex->u.mutex.owner && mutex->u.mutex.owner != q->owner) in try_wake_any_mutex()
357 if (mutex->u.mutex.ownerdead) in try_wake_any_mutex()
359 mutex->u.mutex.ownerdead = false; in try_wake_any_mutex()
360 mutex->u.mutex.count++; in try_wake_any_mutex()
361 mutex->u.mutex.owner = q->owner; in try_wake_any_mutex()
441 * Actually change the mutex state, returning -EPERM if not the owner.
443 static int unlock_mutex_state(struct ntsync_obj *mutex, in unlock_mutex_state() argument
446 ntsync_assert_held(mutex); in unlock_mutex_state()
448 if (mutex->u.mutex.owner != args->owner) in unlock_mutex_state()
451 if (!--mutex->u.mutex.count) in unlock_mutex_state()
452 mutex->u.mutex.owner = 0; in unlock_mutex_state()
456 static int ntsync_mutex_unlock(struct ntsync_obj *mutex, void __user *argp) in ntsync_mutex_unlock() argument
459 struct ntsync_device *dev = mutex->dev; in ntsync_mutex_unlock()
470 if (mutex->type != NTSYNC_TYPE_MUTEX) in ntsync_mutex_unlock()
473 all = ntsync_lock_obj(dev, mutex); in ntsync_mutex_unlock()
475 prev_count = mutex->u.mutex.count; in ntsync_mutex_unlock()
476 ret = unlock_mutex_state(mutex, &args); in ntsync_mutex_unlock()
479 try_wake_all_obj(dev, mutex); in ntsync_mutex_unlock()
480 try_wake_any_mutex(mutex); in ntsync_mutex_unlock()
483 ntsync_unlock_obj(dev, mutex, all); in ntsync_mutex_unlock()
492 * Actually change the mutex state to mark its owner as dead,
495 static int kill_mutex_state(struct ntsync_obj *mutex, __u32 owner) in kill_mutex_state() argument
497 ntsync_assert_held(mutex); in kill_mutex_state()
499 if (mutex->u.mutex.owner != owner) in kill_mutex_state()
502 mutex->u.mutex.ownerdead = true; in kill_mutex_state()
503 mutex->u.mutex.owner = 0; in kill_mutex_state()
504 mutex->u.mutex.count = 0; in kill_mutex_state()
508 static int ntsync_mutex_kill(struct ntsync_obj *mutex, void __user *argp) in ntsync_mutex_kill() argument
510 struct ntsync_device *dev = mutex->dev; in ntsync_mutex_kill()
520 if (mutex->type != NTSYNC_TYPE_MUTEX) in ntsync_mutex_kill()
523 all = ntsync_lock_obj(dev, mutex); in ntsync_mutex_kill()
525 ret = kill_mutex_state(mutex, owner); in ntsync_mutex_kill()
528 try_wake_all_obj(dev, mutex); in ntsync_mutex_kill()
529 try_wake_any_mutex(mutex); in ntsync_mutex_kill()
532 ntsync_unlock_obj(dev, mutex, all); in ntsync_mutex_kill()
608 static int ntsync_mutex_read(struct ntsync_obj *mutex, void __user *argp) in ntsync_mutex_read() argument
611 struct ntsync_device *dev = mutex->dev; in ntsync_mutex_read()
616 if (mutex->type != NTSYNC_TYPE_MUTEX) in ntsync_mutex_read()
619 all = ntsync_lock_obj(dev, mutex); in ntsync_mutex_read()
621 args.count = mutex->u.mutex.count; in ntsync_mutex_read()
622 args.owner = mutex->u.mutex.owner; in ntsync_mutex_read()
623 ret = mutex->u.mutex.ownerdead ? -EOWNERDEAD : 0; in ntsync_mutex_read()
625 ntsync_unlock_obj(dev, mutex, all); in ntsync_mutex_read()
768 struct ntsync_obj *mutex; in ntsync_create_mutex() local
777 mutex = ntsync_alloc_obj(dev, NTSYNC_TYPE_MUTEX); in ntsync_create_mutex()
778 if (!mutex) in ntsync_create_mutex()
780 mutex->u.mutex.count = args.count; in ntsync_create_mutex()
781 mutex->u.mutex.owner = args.owner; in ntsync_create_mutex()
782 fd = ntsync_obj_get_fd(mutex); in ntsync_create_mutex()
784 ntsync_free_obj(mutex); in ntsync_create_mutex()