Skip to content

Commit ef5dc12

Browse files
rddunlapIngo Molnar
authored andcommitted
mutex: Fix annotations to include it in kernel-locking docbook
Fix kernel-doc notation in linux/mutex.h and kernel/mutex.c, then add these 2 files to the kernel-locking docbook as the Mutex API reference chapter. Add one API function to mutex-design.txt and correct a typo in that file. Signed-off-by: Randy Dunlap <randy.dunlap@oracle.com> Cc: Rusty Russell <rusty@rustcorp.com.au> LKML-Reference: <20100902154816.6cc2f9ad.randy.dunlap@oracle.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent 950eaac commit ef5dc12

4 files changed

Lines changed: 23 additions & 17 deletions

File tree

‎Documentation/DocBook/kernel-locking.tmpl‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,6 +1961,12 @@ machines due to caching.
19611961
</sect1>
19621962
</chapter>
19631963

1964+
<chapter id="apiref">
1965+
<title>Mutex API reference</title>
1966+
!Iinclude/linux/mutex.h
1967+
!Ekernel/mutex.c
1968+
</chapter>
1969+
19641970
<chapter id="references">
19651971
<title>Further reading</title>
19661972

‎Documentation/mutex-design.txt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ firstly, there's nothing wrong with semaphores. But if the simpler
99
mutex semantics are sufficient for your code, then there are a couple
1010
of advantages of mutexes:
1111

12-
- 'struct mutex' is smaller on most architectures: .e.g on x86,
12+
- 'struct mutex' is smaller on most architectures: E.g. on x86,
1313
'struct semaphore' is 20 bytes, 'struct mutex' is 16 bytes.
1414
A smaller structure size means less RAM footprint, and better
1515
CPU-cache utilization.
@@ -136,3 +136,4 @@ the APIs of 'struct mutex' have been streamlined:
136136
void mutex_lock_nested(struct mutex *lock, unsigned int subclass);
137137
int mutex_lock_interruptible_nested(struct mutex *lock,
138138
unsigned int subclass);
139+
int atomic_dec_and_mutex_lock(atomic_t *cnt, struct mutex *lock);

‎include/linux/mutex.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ struct mutex_waiter {
7878
# include <linux/mutex-debug.h>
7979
#else
8080
# define __DEBUG_MUTEX_INITIALIZER(lockname)
81+
/**
82+
* mutex_init - initialize the mutex
83+
* @mutex: the mutex to be initialized
84+
*
85+
* Initialize the mutex to unlocked state.
86+
*
87+
* It is not allowed to initialize an already locked mutex.
88+
*/
8189
# define mutex_init(mutex) \
8290
do { \
8391
static struct lock_class_key __key; \

‎kernel/mutex.c‎

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,6 @@
3636
# include <asm/mutex.h>
3737
#endif
3838

39-
/***
40-
* mutex_init - initialize the mutex
41-
* @lock: the mutex to be initialized
42-
* @key: the lock_class_key for the class; used by mutex lock debugging
43-
*
44-
* Initialize the mutex to unlocked state.
45-
*
46-
* It is not allowed to initialize an already locked mutex.
47-
*/
4839
void
4940
__mutex_init(struct mutex *lock, const char *name, struct lock_class_key *key)
5041
{
@@ -68,7 +59,7 @@ EXPORT_SYMBOL(__mutex_init);
6859
static __used noinline void __sched
6960
__mutex_lock_slowpath(atomic_t *lock_count);
7061

71-
/***
62+
/**
7263
* mutex_lock - acquire the mutex
7364
* @lock: the mutex to be acquired
7465
*
@@ -105,7 +96,7 @@ EXPORT_SYMBOL(mutex_lock);
10596

10697
static __used noinline void __sched __mutex_unlock_slowpath(atomic_t *lock_count);
10798

108-
/***
99+
/**
109100
* mutex_unlock - release the mutex
110101
* @lock: the mutex to be released
111102
*
@@ -364,8 +355,8 @@ __mutex_lock_killable_slowpath(atomic_t *lock_count);
364355
static noinline int __sched
365356
__mutex_lock_interruptible_slowpath(atomic_t *lock_count);
366357

367-
/***
368-
* mutex_lock_interruptible - acquire the mutex, interruptable
358+
/**
359+
* mutex_lock_interruptible - acquire the mutex, interruptible
369360
* @lock: the mutex to be acquired
370361
*
371362
* Lock the mutex like mutex_lock(), and return 0 if the mutex has
@@ -456,15 +447,15 @@ static inline int __mutex_trylock_slowpath(atomic_t *lock_count)
456447
return prev == 1;
457448
}
458449

459-
/***
460-
* mutex_trylock - try acquire the mutex, without waiting
450+
/**
451+
* mutex_trylock - try to acquire the mutex, without waiting
461452
* @lock: the mutex to be acquired
462453
*
463454
* Try to acquire the mutex atomically. Returns 1 if the mutex
464455
* has been acquired successfully, and 0 on contention.
465456
*
466457
* NOTE: this function follows the spin_trylock() convention, so
467-
* it is negated to the down_trylock() return values! Be careful
458+
* it is negated from the down_trylock() return values! Be careful
468459
* about this when converting semaphore users to mutexes.
469460
*
470461
* This function must not be used in interrupt context. The

0 commit comments

Comments
 (0)