1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- #include <linux/version.h>
- #include <linux/init.h>
- #include <linux/kernel.h>
- #include <linux/module.h>
- #include <linux/syscalls.h>
- #include <linux/mutex.h>
- #include <linux/errno.h>
- #include "defines.h"
- #include "ksync.h"
- /////////////////////////////////////////////////////////////////////////////
- static DEFINE_MUTEX(g_mutex);
- /////////////////////////////////////////////////////////////////////////////
- void ksync_lock(void)
- {
- mutex_lock(&g_mutex);
- }
- /////////////////////////////////////////////////////////////////////////////
- void ksync_unlock(void)
- {
- mutex_unlock(&g_mutex);
- }
- /////////////////////////////////////////////////////////////////////////////
- int ksync_sleep_jiffies(long jiffies)
- {
- if(jiffies <= 0)
- return 0;
- set_current_state(TASK_INTERRUPTIBLE); // may return early if a signal is delivered to the current task
- return schedule_timeout(jiffies);
- }
- /////////////////////////////////////////////////////////////////////////////
- int ksync_sleep_ms(long ms)
- {
- return ksync_sleep_jiffies(msecs_to_jiffies(ms));
- }
|