2 * Server-side event management
4 * Copyright (C) 1998 Alexandre Julliard
20 struct object obj; /* object header */
21 int manual_reset; /* is it a manual reset event? */
22 int signaled; /* event has been signaled */
25 static void event_dump( struct object *obj, int verbose );
26 static int event_signaled( struct object *obj, struct thread *thread );
27 static int event_satisfied( struct object *obj, struct thread *thread );
29 static const struct object_ops event_ops =
31 sizeof(struct event), /* size */
32 event_dump, /* dump */
33 add_queue, /* add_queue */
34 remove_queue, /* remove_queue */
35 event_signaled, /* signaled */
36 event_satisfied, /* satisfied */
37 NULL, /* get_poll_events */
38 NULL, /* poll_event */
39 no_read_fd, /* get_read_fd */
40 no_write_fd, /* get_write_fd */
42 no_get_file_info, /* get_file_info */
43 no_destroy /* destroy */
47 static struct event *create_event( const WCHAR *name, size_t len,
48 int manual_reset, int initial_state )
52 if ((event = create_named_object( &event_ops, name, len )))
54 if (get_error() != ERROR_ALREADY_EXISTS)
56 /* initialize it if it didn't already exist */
57 event->manual_reset = manual_reset;
58 event->signaled = initial_state;
64 struct event *get_event_obj( struct process *process, int handle, unsigned int access )
66 return (struct event *)get_handle_obj( process, handle, access, &event_ops );
69 void pulse_event( struct event *event )
72 /* wake up all waiters if manual reset, a single one otherwise */
73 wake_up( &event->obj, !event->manual_reset );
77 void set_event( struct event *event )
80 /* wake up all waiters if manual reset, a single one otherwise */
81 wake_up( &event->obj, !event->manual_reset );
84 void reset_event( struct event *event )
89 static void event_dump( struct object *obj, int verbose )
91 struct event *event = (struct event *)obj;
92 assert( obj->ops == &event_ops );
93 fprintf( stderr, "Event manual=%d signaled=%d ",
94 event->manual_reset, event->signaled );
95 dump_object_name( &event->obj );
96 fputc( '\n', stderr );
99 static int event_signaled( struct object *obj, struct thread *thread )
101 struct event *event = (struct event *)obj;
102 assert( obj->ops == &event_ops );
103 return event->signaled;
106 static int event_satisfied( struct object *obj, struct thread *thread )
108 struct event *event = (struct event *)obj;
109 assert( obj->ops == &event_ops );
110 /* Reset if it's an auto-reset event */
111 if (!event->manual_reset) event->signaled = 0;
112 return 0; /* Not abandoned */
115 /* create an event */
116 DECL_HANDLER(create_event)
118 size_t len = get_req_strlenW( req->name );
122 if ((event = create_event( req->name, len, req->manual_reset, req->initial_state )))
124 req->handle = alloc_handle( current->process, event, EVENT_ALL_ACCESS, req->inherit );
125 release_object( event );
129 /* open a handle to an event */
130 DECL_HANDLER(open_event)
132 size_t len = get_req_strlenW( req->name );
133 req->handle = open_object( req->name, len, &event_ops, req->access, req->inherit );
136 /* do an event operation */
137 DECL_HANDLER(event_op)
141 if (!(event = get_event_obj( current->process, req->handle, EVENT_MODIFY_STATE ))) return;
145 pulse_event( event );
151 reset_event( event );
154 fatal_protocol_error( current, "event_op: invalid operation %d\n", req->op );
156 release_object( event );