提交 0048e603 编写于 作者: D Dmitry Torokhov

Input: uinput - use completions instead of events and manual

       wakeups in force feedback code.
Signed-off-by: NDmitry Torokhov <dtor@mail.ru>
上级 152c12f5
...@@ -53,24 +53,23 @@ static int uinput_dev_event(struct input_dev *dev, unsigned int type, unsigned i ...@@ -53,24 +53,23 @@ static int uinput_dev_event(struct input_dev *dev, unsigned int type, unsigned i
return 0; return 0;
} }
static int uinput_request_alloc_id(struct input_dev *dev, struct uinput_request *request) static int uinput_request_alloc_id(struct uinput_device *udev, struct uinput_request *request)
{ {
/* Atomically allocate an ID for the given request. Returns 0 on success. */ /* Atomically allocate an ID for the given request. Returns 0 on success. */
struct uinput_device *udev = dev->private;
int id; int id;
int err = -1; int err = -1;
down(&udev->requests_sem); spin_lock(&udev->requests_lock);
for (id = 0; id < UINPUT_NUM_REQUESTS; id++) for (id = 0; id < UINPUT_NUM_REQUESTS; id++)
if (!udev->requests[id]) { if (!udev->requests[id]) {
udev->requests[id] = request;
request->id = id; request->id = id;
udev->requests[id] = request;
err = 0; err = 0;
break; break;
} }
up(&udev->requests_sem); spin_unlock(&udev->requests_lock);
return err; return err;
} }
...@@ -79,70 +78,78 @@ static struct uinput_request* uinput_request_find(struct uinput_device *udev, in ...@@ -79,70 +78,78 @@ static struct uinput_request* uinput_request_find(struct uinput_device *udev, in
/* Find an input request, by ID. Returns NULL if the ID isn't valid. */ /* Find an input request, by ID. Returns NULL if the ID isn't valid. */
if (id >= UINPUT_NUM_REQUESTS || id < 0) if (id >= UINPUT_NUM_REQUESTS || id < 0)
return NULL; return NULL;
if (udev->requests[id]->completed)
return NULL;
return udev->requests[id]; return udev->requests[id];
} }
static void uinput_request_init(struct input_dev *dev, struct uinput_request *request, int code) static inline int uinput_request_reserve_slot(struct uinput_device *udev, struct uinput_request *request)
{ {
struct uinput_device *udev = dev->private; /* Allocate slot. If none are available right away, wait. */
return wait_event_interruptible(udev->requests_waitq,
!uinput_request_alloc_id(udev, request));
}
memset(request, 0, sizeof(struct uinput_request)); static void uinput_request_done(struct uinput_device *udev, struct uinput_request *request)
request->code = code; {
init_waitqueue_head(&request->waitq); complete(&request->done);
/* Allocate an ID. If none are available right away, wait. */ /* Mark slot as available */
request->retval = wait_event_interruptible(udev->requests_waitq, udev->requests[request->id] = NULL;
!uinput_request_alloc_id(dev, request)); wake_up_interruptible(&udev->requests_waitq);
} }
static void uinput_request_submit(struct input_dev *dev, struct uinput_request *request) static int uinput_request_submit(struct input_dev *dev, struct uinput_request *request)
{ {
struct uinput_device *udev = dev->private;
int retval; int retval;
/* Tell our userspace app about this new request by queueing an input event */ /* Tell our userspace app about this new request by queueing an input event */
uinput_dev_event(dev, EV_UINPUT, request->code, request->id); uinput_dev_event(dev, EV_UINPUT, request->code, request->id);
/* Wait for the request to complete */ /* Wait for the request to complete */
retval = wait_event_interruptible(request->waitq, request->completed); retval = wait_for_completion_interruptible(&request->done);
if (retval) if (!retval)
request->retval = retval; retval = request->retval;
/* Release this request's ID, let others know it's available */ return retval;
udev->requests[request->id] = NULL;
wake_up_interruptible(&udev->requests_waitq);
} }
static int uinput_dev_upload_effect(struct input_dev *dev, struct ff_effect *effect) static int uinput_dev_upload_effect(struct input_dev *dev, struct ff_effect *effect)
{ {
struct uinput_request request; struct uinput_request request;
int retval;
if (!test_bit(EV_FF, dev->evbit)) if (!test_bit(EV_FF, dev->evbit))
return -ENOSYS; return -ENOSYS;
uinput_request_init(dev, &request, UI_FF_UPLOAD); request.id = -1;
if (request.retval) init_completion(&request.done);
return request.retval; request.code = UI_FF_UPLOAD;
request.u.effect = effect; request.u.effect = effect;
uinput_request_submit(dev, &request);
return request.retval; retval = uinput_request_reserve_slot(dev->private, &request);
if (!retval)
retval = uinput_request_submit(dev, &request);
return retval;
} }
static int uinput_dev_erase_effect(struct input_dev *dev, int effect_id) static int uinput_dev_erase_effect(struct input_dev *dev, int effect_id)
{ {
struct uinput_request request; struct uinput_request request;
int retval;
if (!test_bit(EV_FF, dev->evbit)) if (!test_bit(EV_FF, dev->evbit))
return -ENOSYS; return -ENOSYS;
uinput_request_init(dev, &request, UI_FF_ERASE); request.id = -1;
if (request.retval) init_completion(&request.done);
return request.retval; request.code = UI_FF_ERASE;
request.u.effect_id = effect_id; request.u.effect_id = effect_id;
uinput_request_submit(dev, &request);
return request.retval; retval = uinput_request_reserve_slot(dev->private, &request);
if (!retval)
retval = uinput_request_submit(dev, &request);
return retval;
} }
static int uinput_create_device(struct uinput_device *udev) static int uinput_create_device(struct uinput_device *udev)
...@@ -189,7 +196,7 @@ static int uinput_open(struct inode *inode, struct file *file) ...@@ -189,7 +196,7 @@ static int uinput_open(struct inode *inode, struct file *file)
if (!newdev) if (!newdev)
goto error; goto error;
memset(newdev, 0, sizeof(struct uinput_device)); memset(newdev, 0, sizeof(struct uinput_device));
init_MUTEX(&newdev->requests_sem); spin_lock_init(&newdev->requests_lock);
init_waitqueue_head(&newdev->requests_waitq); init_waitqueue_head(&newdev->requests_waitq);
newinput = kmalloc(sizeof(struct input_dev), GFP_KERNEL); newinput = kmalloc(sizeof(struct input_dev), GFP_KERNEL);
...@@ -551,8 +558,7 @@ static int uinput_ioctl(struct inode *inode, struct file *file, unsigned int cmd ...@@ -551,8 +558,7 @@ static int uinput_ioctl(struct inode *inode, struct file *file, unsigned int cmd
} }
req->retval = ff_up.retval; req->retval = ff_up.retval;
memcpy(req->u.effect, &ff_up.effect, sizeof(struct ff_effect)); memcpy(req->u.effect, &ff_up.effect, sizeof(struct ff_effect));
req->completed = 1; uinput_request_done(udev, req);
wake_up_interruptible(&req->waitq);
break; break;
case UI_END_FF_ERASE: case UI_END_FF_ERASE:
...@@ -566,8 +572,7 @@ static int uinput_ioctl(struct inode *inode, struct file *file, unsigned int cmd ...@@ -566,8 +572,7 @@ static int uinput_ioctl(struct inode *inode, struct file *file, unsigned int cmd
break; break;
} }
req->retval = ff_erase.retval; req->retval = ff_erase.retval;
req->completed = 1; uinput_request_done(udev, req);
wake_up_interruptible(&req->waitq);
break; break;
default: default:
......
...@@ -42,8 +42,7 @@ struct uinput_request { ...@@ -42,8 +42,7 @@ struct uinput_request {
int code; /* UI_FF_UPLOAD, UI_FF_ERASE */ int code; /* UI_FF_UPLOAD, UI_FF_ERASE */
int retval; int retval;
wait_queue_head_t waitq; struct completion done;
int completed;
union { union {
int effect_id; int effect_id;
...@@ -62,7 +61,7 @@ struct uinput_device { ...@@ -62,7 +61,7 @@ struct uinput_device {
struct uinput_request *requests[UINPUT_NUM_REQUESTS]; struct uinput_request *requests[UINPUT_NUM_REQUESTS];
wait_queue_head_t requests_waitq; wait_queue_head_t requests_waitq;
struct semaphore requests_sem; spinlock_t requests_lock;
}; };
#endif /* __KERNEL__ */ #endif /* __KERNEL__ */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册