Commit c9e60ec7 authored by Zebediah Figura's avatar Zebediah Figura Committed by Vitaly Lipatov

server: Allow (re)setting esync events on the server side.

Some server calls pass an event handle, most notably asyncs. We need to be able to handle these correctly. Accordingly we pass them along to esync if it turns out the underlying object is actually an esync object. In an ideal world we'd just convert all instances of events on the server side to use esyncs instead. But we want to keep esync perfectly configurable, so this is how we do it.
parent 9bba79fb
......@@ -114,7 +114,7 @@ struct esync
static void esync_dump( struct object *obj, int verbose );
static void esync_destroy( struct object *obj );
static const struct object_ops esync_ops =
const struct object_ops esync_ops =
{
sizeof(struct esync), /* size */
&no_type, /* type */
......@@ -337,6 +337,26 @@ void esync_clear( int fd )
read( fd, &value, sizeof(value) );
}
/* Server-side event support. */
void esync_set_event( struct esync *esync )
{
static const uint64_t value = 1;
assert( esync->obj.ops == &esync_ops );
if (write( esync->fd, &value, sizeof(value) ) == -1)
perror( "esync: write" );
}
void esync_reset_event( struct esync *esync )
{
static uint64_t value = 1;
assert( esync->obj.ops == &esync_ops );
/* we don't care about the return value */
read( esync->fd, &value, sizeof(value) );
}
DECL_HANDLER(create_esync)
{
struct esync *esync;
......
......@@ -25,3 +25,9 @@ void esync_init(void);
int esync_create_fd( int initval, int flags );
void esync_wake_up( struct object *obj );
void esync_clear( int fd );
struct esync;
extern const struct object_ops esync_ops;
void esync_set_event( struct esync *esync );
void esync_reset_event( struct esync *esync );
......@@ -166,6 +166,10 @@ struct event *create_event( struct object *root, const struct unicode_str *name,
struct event *get_event_obj( struct process *process, obj_handle_t handle, unsigned int access )
{
struct object *obj;
if (do_esync() && (obj = get_handle_obj( process, handle, access, &esync_ops)))
return (struct event *)obj; /* even though it's not an event */
return (struct event *)get_handle_obj( process, handle, access, &event_ops );
}
......@@ -179,6 +183,12 @@ static void pulse_event( struct event *event )
void set_event( struct event *event )
{
if (do_esync() && event->obj.ops == &esync_ops)
{
esync_set_event( (struct esync *)event );
return;
}
event->signaled = 1;
/* wake up all waiters if manual reset, a single one otherwise */
wake_up( &event->obj, !event->manual_reset );
......@@ -186,6 +196,11 @@ void set_event( struct event *event )
void reset_event( struct event *event )
{
if (do_esync() && event->obj.ops == &esync_ops)
{
esync_reset_event( (struct esync *)event );
return;
}
event->signaled = 0;
if (do_esync())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment