2 * Server-side event management
4 * Copyright (C) 1998 Alexandre Julliard
13 #include "server/process.h"
14 #include "server/thread.h"
18 struct object obj; /* object header */
19 int manual_reset; /* is it a manual reset event? */
20 int signaled; /* event has been signaled */
23 static void event_dump( struct object *obj, int verbose );
24 static int event_signaled( struct object *obj, struct thread *thread );
25 static int event_satisfied( struct object *obj, struct thread *thread );
26 static void event_destroy( struct object *obj );
28 static const struct object_ops event_ops =
43 struct object *create_event( const char *name, int manual_reset, int initial_state )
47 if (!(event = (struct event *)create_named_object( name, &event_ops, sizeof(*event) )))
49 if (GET_ERROR() != ERROR_ALREADY_EXISTS)
51 /* initialize it if it didn't already exist */
52 event->manual_reset = manual_reset;
53 event->signaled = initial_state;
58 int open_event( unsigned int access, int inherit, const char *name )
60 return open_object( name, &event_ops, access, inherit );
63 int pulse_event( int handle )
67 if (!(event = (struct event *)get_handle_obj( current->process, handle,
68 EVENT_MODIFY_STATE, &event_ops )))
71 /* wake up all waiters if manual reset, a single one otherwise */
72 wake_up( &event->obj, !event->manual_reset );
74 release_object( event );
78 int set_event( int handle )
82 if (!(event = (struct event *)get_handle_obj( current->process, handle,
83 EVENT_MODIFY_STATE, &event_ops )))
86 /* wake up all waiters if manual reset, a single one otherwise */
87 wake_up( &event->obj, !event->manual_reset );
88 release_object( event );
92 int reset_event( int handle )
96 if (!(event = (struct event *)get_handle_obj( current->process, handle,
97 EVENT_MODIFY_STATE, &event_ops )))
100 release_object( event );
104 static void event_dump( struct object *obj, int verbose )
106 struct event *event = (struct event *)obj;
107 assert( obj->ops == &event_ops );
108 fprintf( stderr, "Event manual=%d signaled=%d name='%s'\n",
109 event->manual_reset, event->signaled,
110 get_object_name( &event->obj ) );
113 static int event_signaled( struct object *obj, struct thread *thread )
115 struct event *event = (struct event *)obj;
116 assert( obj->ops == &event_ops );
117 return event->signaled;
120 static int event_satisfied( struct object *obj, struct thread *thread )
122 struct event *event = (struct event *)obj;
123 assert( obj->ops == &event_ops );
124 /* Reset if it's an auto-reset event */
125 if (!event->manual_reset) event->signaled = 0;
126 return 0; /* Not abandoned */
129 static void event_destroy( struct object *obj )
131 struct event *event = (struct event *)obj;
132 assert( obj->ops == &event_ops );