lkmpg/examples/example_mutex.c
Jim Huang 50b8dfe6c2 Enforce the customized style for example code
Instead of using tab for indention, the style defaults to 4 spaces for
the sake of compact layout.
2021-07-22 06:58:13 +08:00

40 lines
781 B
C

#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/mutex.h>
DEFINE_MUTEX(mymutex);
static int example_mutex_init(void)
{
int ret;
pr_info("example_mutex init\n");
ret = mutex_trylock(&mymutex);
if (ret != 0) {
pr_info("mutex is locked\n");
if (mutex_is_locked(&mymutex) == 0)
pr_info("The mutex failed to lock!\n");
mutex_unlock(&mymutex);
pr_info("mutex is unlocked\n");
} else
pr_info("Failed to lock\n");
return 0;
}
static void example_mutex_exit(void)
{
pr_info("example_mutex exit\n");
}
module_init(example_mutex_init);
module_exit(example_mutex_exit);
MODULE_AUTHOR("Bob Mottram");
MODULE_DESCRIPTION("Mutex example");
MODULE_LICENSE("GPL");