From ef50770eb84845636bbfd949e0d08430ca88d85d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fran=C3=A7ois=20Tigeot?= Date: Mon, 8 Jun 2020 07:42:20 +0200 Subject: [PATCH] drm/linux: Add mutex_lock_nested() and mutex_trylock_recursive() --- sys/dev/drm/include/linux/mutex.h | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/sys/dev/drm/include/linux/mutex.h b/sys/dev/drm/include/linux/mutex.h index 69c8f1ed39..c10c76b8f9 100644 --- a/sys/dev/drm/include/linux/mutex.h +++ b/sys/dev/drm/include/linux/mutex.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 François Tigeot + * Copyright (c) 2014-2020 François Tigeot * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -59,4 +59,24 @@ mutex_destroy(struct lock *mutex) lockuninit(mutex); } +#define mutex_lock_nested(lock, unused) mutex_lock(lock) + +enum mutex_trylock_recursive_enum { + MUTEX_TRYLOCK_FAILED = 0, + MUTEX_TRYLOCK_SUCCESS = 1, + MUTEX_TRYLOCK_RECURSIVE, +}; + +static inline enum mutex_trylock_recursive_enum +mutex_trylock_recursive(struct lock *lock) +{ + if (lockowned(lock)) + return MUTEX_TRYLOCK_RECURSIVE; + + if (mutex_trylock(lock)) + return MUTEX_TRYLOCK_SUCCESS; + + return MUTEX_TRYLOCK_FAILED; +} + #endif /* _LINUX_MUTEX_H_ */ -- 2.41.0