Skip to content

Commit

Permalink
winesync: Introduce WINESYNC_IOC_SET_EVENT
Browse files Browse the repository at this point in the history
  • Loading branch information
Zebediah Figura authored and xanmod committed May 30, 2022
1 parent 18569c1 commit 8670834
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
45 changes: 45 additions & 0 deletions drivers/misc/winesync.c
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,49 @@ static int winesync_kill_owner(struct winesync_device *dev, void __user *argp)
return 0;
}

static int winesync_set_event(struct winesync_device *dev, void __user *argp)
{
struct winesync_event_args __user *user_args = argp;
struct winesync_event_args args;
struct winesync_obj *event;
bool prev_state;

if (copy_from_user(&args, argp, sizeof(args)))
return -EFAULT;

event = get_obj_typed(dev, args.event, WINESYNC_TYPE_EVENT);
if (!event)
return -EINVAL;

if (atomic_read(&event->all_hint) > 0) {
spin_lock(&dev->wait_all_lock);
spin_lock(&event->lock);

prev_state = event->u.event.signaled;
event->u.event.signaled = true;
try_wake_all_obj(dev, event);
try_wake_any_event(event);

spin_unlock(&event->lock);
spin_unlock(&dev->wait_all_lock);
} else {
spin_lock(&event->lock);

prev_state = event->u.event.signaled;
event->u.event.signaled = true;
try_wake_any_event(event);

spin_unlock(&event->lock);
}

put_obj(event);

if (put_user(prev_state, &user_args->signaled))
return -EFAULT;

return 0;
}

static int winesync_schedule(const struct winesync_q *q, ktime_t *timeout)
{
int ret = 0;
Expand Down Expand Up @@ -1006,6 +1049,8 @@ static long winesync_char_ioctl(struct file *file, unsigned int cmd,
return winesync_read_mutex(dev, argp);
case WINESYNC_IOC_READ_SEM:
return winesync_read_sem(dev, argp);
case WINESYNC_IOC_SET_EVENT:
return winesync_set_event(dev, argp);
case WINESYNC_IOC_WAIT_ALL:
return winesync_wait_all(dev, argp);
case WINESYNC_IOC_WAIT_ANY:
Expand Down
2 changes: 2 additions & 0 deletions include/uapi/linux/winesync.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,7 @@ struct winesync_wait_args {
struct winesync_mutex_args)
#define WINESYNC_IOC_CREATE_EVENT _IOWR(WINESYNC_IOC_BASE, 10, \
struct winesync_event_args)
#define WINESYNC_IOC_SET_EVENT _IOWR(WINESYNC_IOC_BASE, 11, \
struct winesync_event_args)

#endif

0 comments on commit 8670834

Please sign in to comment.