2 * Server-side event management
4 * Copyright (C) 1998 Alexandre Julliard
19 struct object obj; /* object header */
20 int manual_reset; /* is it a manual reset event? */
21 int signaled; /* event has been signaled */
24 static void event_dump( struct object *obj, int verbose );
25 static int event_signaled( struct object *obj, struct thread *thread );
26 static int event_satisfied( struct object *obj, struct thread *thread );
28 static const struct object_ops event_ops =
30 sizeof(struct event), /* size */
31 event_dump, /* dump */
32 add_queue, /* add_queue */
33 remove_queue, /* remove_queue */
34 event_signaled, /* signaled */
35 event_satisfied, /* satisfied */
36 NULL, /* get_poll_events */
37 NULL, /* poll_event */
38 no_get_fd, /* get_fd */
40 no_get_file_info, /* get_file_info */
41 no_destroy /* destroy */
45 struct event *create_event( const WCHAR *name, size_t len,
46 int manual_reset, int initial_state )
50 if ((event = create_named_object( &event_ops, name, len )))
52 if (get_error() != STATUS_OBJECT_NAME_COLLISION)
54 /* initialize it if it didn't already exist */
55 event->manual_reset = manual_reset;
56 event->signaled = initial_state;
62 struct event *get_event_obj( struct process *process, handle_t handle, unsigned int access )
64 return (struct event *)get_handle_obj( process, handle, access, &event_ops );
67 void pulse_event( struct event *event )
70 /* wake up all waiters if manual reset, a single one otherwise */
71 wake_up( &event->obj, !event->manual_reset );
75 void set_event( struct event *event )
78 /* wake up all waiters if manual reset, a single one otherwise */
79 wake_up( &event->obj, !event->manual_reset );
82 void reset_event( struct event *event )
87 static void event_dump( struct object *obj, int verbose )
89 struct event *event = (struct event *)obj;
90 assert( obj->ops == &event_ops );
91 fprintf( stderr, "Event manual=%d signaled=%d ",
92 event->manual_reset, event->signaled );
93 dump_object_name( &event->obj );
94 fputc( '\n', stderr );
97 static int event_signaled( struct object *obj, struct thread *thread )
99 struct event *event = (struct event *)obj;
100 assert( obj->ops == &event_ops );
101 return event->signaled;
104 static int event_satisfied( struct object *obj, struct thread *thread )
106 struct event *event = (struct event *)obj;
107 assert( obj->ops == &event_ops );
108 /* Reset if it's an auto-reset event */
109 if (!event->manual_reset) event->signaled = 0;
110 return 0; /* Not abandoned */
113 /* create an event */
114 DECL_HANDLER(create_event)
119 if ((event = create_event( get_req_data(req), get_req_data_size(req),
120 req->manual_reset, req->initial_state )))
122 req->handle = alloc_handle( current->process, event, EVENT_ALL_ACCESS, req->inherit );
123 release_object( event );
127 /* open a handle to an event */
128 DECL_HANDLER(open_event)
130 req->handle = open_object( get_req_data(req), get_req_data_size(req),
131 &event_ops, req->access, req->inherit );
134 /* do an event operation */
135 DECL_HANDLER(event_op)
139 if (!(event = get_event_obj( current->process, req->handle, EVENT_MODIFY_STATE ))) return;
143 pulse_event( event );
149 reset_event( event );
152 fatal_protocol_error( current, "event_op: invalid operation %d\n", req->op );
154 release_object( event );