Skip to content

Commit 5f35d5a

Browse files
Mukesh OjhaPeter Zijlstra
authored andcommitted
locking/mutex: Make __mutex_owner static to mutex.c
__mutex_owner() should only be used by the mutex api's. So, to put this restiction let's move the __mutex_owner() function definition from linux/mutex.h to mutex.c file. There exist functions that uses __mutex_owner() like mutex_is_locked() and mutex_trylock_recursive(), So to keep legacy thing intact move them as well and export them. Move mutex_waiter structure also to keep it private to the file. Signed-off-by: Mukesh Ojha <mojha@codeaurora.org> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: mingo@redhat.com Cc: will@kernel.org Link: https://lkml.kernel.org/r/1564585504-3543-1-git-send-email-mojha@codeaurora.org
1 parent 24a376d commit 5f35d5a

3 files changed

Lines changed: 44 additions & 35 deletions

File tree

‎include/linux/mutex.h‎

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -65,29 +65,6 @@ struct mutex {
6565
#endif
6666
};
6767

68-
/*
69-
* Internal helper function; C doesn't allow us to hide it :/
70-
*
71-
* DO NOT USE (outside of mutex code).
72-
*/
73-
static inline struct task_struct *__mutex_owner(struct mutex *lock)
74-
{
75-
return (struct task_struct *)(atomic_long_read(&lock->owner) & ~0x07);
76-
}
77-
78-
/*
79-
* This is the control structure for tasks blocked on mutex,
80-
* which resides on the blocked task's kernel stack:
81-
*/
82-
struct mutex_waiter {
83-
struct list_head list;
84-
struct task_struct *task;
85-
struct ww_acquire_ctx *ww_ctx;
86-
#ifdef CONFIG_DEBUG_MUTEXES
87-
void *magic;
88-
#endif
89-
};
90-
9168
#ifdef CONFIG_DEBUG_MUTEXES
9269

9370
#define __DEBUG_MUTEX_INITIALIZER(lockname) \
@@ -144,10 +121,7 @@ extern void __mutex_init(struct mutex *lock, const char *name,
144121
*
145122
* Returns true if the mutex is locked, false if unlocked.
146123
*/
147-
static inline bool mutex_is_locked(struct mutex *lock)
148-
{
149-
return __mutex_owner(lock) != NULL;
150-
}
124+
extern bool mutex_is_locked(struct mutex *lock);
151125

152126
/*
153127
* See kernel/locking/mutex.c for detailed documentation of these APIs.
@@ -220,13 +194,7 @@ enum mutex_trylock_recursive_enum {
220194
* - MUTEX_TRYLOCK_SUCCESS - lock acquired,
221195
* - MUTEX_TRYLOCK_RECURSIVE - we already owned the lock.
222196
*/
223-
static inline /* __deprecated */ __must_check enum mutex_trylock_recursive_enum
224-
mutex_trylock_recursive(struct mutex *lock)
225-
{
226-
if (unlikely(__mutex_owner(lock) == current))
227-
return MUTEX_TRYLOCK_RECURSIVE;
228-
229-
return mutex_trylock(lock);
230-
}
197+
extern /* __deprecated */ __must_check enum mutex_trylock_recursive_enum
198+
mutex_trylock_recursive(struct mutex *lock);
231199

232200
#endif /* __LINUX_MUTEX_H */

‎kernel/locking/mutex.c‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@
3636
# include "mutex.h"
3737
#endif
3838

39+
/*
40+
* This is the control structure for tasks blocked on mutex,
41+
* which resides on the blocked task's kernel stack:
42+
*/
43+
struct mutex_waiter {
44+
struct list_head list;
45+
struct task_struct *task;
46+
struct ww_acquire_ctx *ww_ctx;
47+
#ifdef CONFIG_DEBUG_MUTEXES
48+
void *magic;
49+
#endif
50+
};
51+
3952
void
4053
__mutex_init(struct mutex *lock, const char *name, struct lock_class_key *key)
4154
{
@@ -65,11 +78,37 @@ EXPORT_SYMBOL(__mutex_init);
6578

6679
#define MUTEX_FLAGS 0x07
6780

81+
/*
82+
* Internal helper function; C doesn't allow us to hide it :/
83+
*
84+
* DO NOT USE (outside of mutex code).
85+
*/
86+
static inline struct task_struct *__mutex_owner(struct mutex *lock)
87+
{
88+
return (struct task_struct *)(atomic_long_read(&lock->owner) & ~0x07);
89+
}
90+
6891
static inline struct task_struct *__owner_task(unsigned long owner)
6992
{
7093
return (struct task_struct *)(owner & ~MUTEX_FLAGS);
7194
}
7295

96+
bool mutex_is_locked(struct mutex *lock)
97+
{
98+
return __mutex_owner(lock) != NULL;
99+
}
100+
EXPORT_SYMBOL(mutex_is_locked);
101+
102+
__must_check enum mutex_trylock_recursive_enum
103+
mutex_trylock_recursive(struct mutex *lock)
104+
{
105+
if (unlikely(__mutex_owner(lock) == current))
106+
return MUTEX_TRYLOCK_RECURSIVE;
107+
108+
return mutex_trylock(lock);
109+
}
110+
EXPORT_SYMBOL(mutex_trylock_recursive);
111+
73112
static inline unsigned long __owner_flags(unsigned long owner)
74113
{
75114
return owner & MUTEX_FLAGS;

‎kernel/locking/mutex.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#define debug_mutex_unlock(lock) do { } while (0)
2020
#define debug_mutex_init(lock, name, key) do { } while (0)
2121

22+
struct mutex_waiter;
23+
2224
static inline void
2325
debug_mutex_lock_common(struct mutex *lock, struct mutex_waiter *waiter)
2426
{

0 commit comments

Comments
 (0)