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 =
45 static struct event *create_event( const char *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() != ERROR_ALREADY_EXISTS)
54 /* initialize it if it didn't already exist */
55 event->manual_reset = manual_reset;
56 event->signaled = initial_state;
62 static int pulse_event( int handle )
66 if (!(event = (struct event *)get_handle_obj( current->process, handle,
67 EVENT_MODIFY_STATE, &event_ops )))
70 /* wake up all waiters if manual reset, a single one otherwise */
71 wake_up( &event->obj, !event->manual_reset );
73 release_object( event );
77 static int set_event( int handle )
81 if (!(event = (struct event *)get_handle_obj( current->process, handle,
82 EVENT_MODIFY_STATE, &event_ops )))
85 /* wake up all waiters if manual reset, a single one otherwise */
86 wake_up( &event->obj, !event->manual_reset );
87 release_object( event );
91 static int reset_event( int handle )
95 if (!(event = (struct event *)get_handle_obj( current->process, handle,
96 EVENT_MODIFY_STATE, &event_ops )))
99 release_object( event );
103 static void event_dump( struct object *obj, int verbose )
105 struct event *event = (struct event *)obj;
106 assert( obj->ops == &event_ops );
107 fprintf( stderr, "Event manual=%d signaled=%d name='%s'\n",
108 event->manual_reset, event->signaled,
109 get_object_name( &event->obj ) );
112 static int event_signaled( struct object *obj, struct thread *thread )
114 struct event *event = (struct event *)obj;
115 assert( obj->ops == &event_ops );
116 return event->signaled;
119 static int event_satisfied( struct object *obj, struct thread *thread )
121 struct event *event = (struct event *)obj;
122 assert( obj->ops == &event_ops );
123 /* Reset if it's an auto-reset event */
124 if (!event->manual_reset) event->signaled = 0;
125 return 0; /* Not abandoned */
128 /* create an event */
129 DECL_HANDLER(create_event)
131 size_t len = get_req_strlen( req->name );
135 if ((event = create_event( req->name, len, req->manual_reset, req->initial_state )))
137 req->handle = alloc_handle( current->process, event, EVENT_ALL_ACCESS, req->inherit );
138 release_object( event );
142 /* open a handle to an event */
143 DECL_HANDLER(open_event)
145 size_t len = get_req_strlen( req->name );
146 req->handle = open_object( req->name, len, &event_ops, req->access, req->inherit );
149 /* do an event operation */
150 DECL_HANDLER(event_op)
155 pulse_event( req->handle );
158 set_event( req->handle );
161 reset_event( req->handle );
164 fatal_protocol_error( current, "event_op: invalid operation %d\n", req->op );