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 struct event *get_event_obj( struct process *process, int handle, unsigned int access )
64 return (struct event *)get_handle_obj( current->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 name='%s'\n",
92 event->manual_reset, event->signaled,
93 get_object_name( &event->obj ) );
96 static int event_signaled( struct object *obj, struct thread *thread )
98 struct event *event = (struct event *)obj;
99 assert( obj->ops == &event_ops );
100 return event->signaled;
103 static int event_satisfied( struct object *obj, struct thread *thread )
105 struct event *event = (struct event *)obj;
106 assert( obj->ops == &event_ops );
107 /* Reset if it's an auto-reset event */
108 if (!event->manual_reset) event->signaled = 0;
109 return 0; /* Not abandoned */
112 /* create an event */
113 DECL_HANDLER(create_event)
115 size_t len = get_req_strlen( req->name );
119 if ((event = create_event( req->name, len, req->manual_reset, req->initial_state )))
121 req->handle = alloc_handle( current->process, event, EVENT_ALL_ACCESS, req->inherit );
122 release_object( event );
126 /* open a handle to an event */
127 DECL_HANDLER(open_event)
129 size_t len = get_req_strlen( req->name );
130 req->handle = open_object( req->name, len, &event_ops, req->access, req->inherit );
133 /* do an event operation */
134 DECL_HANDLER(event_op)
138 if (!(event = get_event_obj( current->process, req->handle, EVENT_MODIFY_STATE ))) return;
142 pulse_event( event );
148 reset_event( event );
151 fatal_protocol_error( current, "event_op: invalid operation %d\n", req->op );
153 release_object( event );