#include <linux/mutex.h>
#include <asm/uaccess.h>
#include <linux/circ_buf.h>
+#include <linux/sched.h>
+#include <linux/completion.h>
MODULE_LICENSE("GPL");
static struct circ_buf *hello;
static struct circ_buf hello_instance;
static DEFINE_MUTEX(hello_mtx);
+static DECLARE_COMPLETION(hello_wait);
static int hello_open(struct inode *ino, struct file *fp)
{
mutex_unlock(&hello_mtx);
if (r)
return -EFAULT;
+ complete(&hello_wait);
return sz;
}
if (mutex_lock_interruptible(&hello_mtx))
return -ERESTARTSYS;
len = CIRC_SPACE(hello->head, hello->tail, MAXLEN);
+ while (len == 0) {
+ mutex_unlock(&hello_mtx);
+ if (wait_for_completion_interruptible(&hello_wait))
+ return -ERESTARTSYS;
+ if (mutex_lock_interruptible(&hello_mtx))
+ return -ERESTARTSYS;
+ len = CIRC_SPACE(hello->head, hello->tail, MAXLEN);
+ }
if (sz > len)
sz = len;
fsz = min(sz, CIRC_SPACE_TO_END(hello->head, hello->tail, MAXLEN));