Stubs for WaitNamedPipe[A|W].
[wine/multimedia.git] / server / event.c
blobef9dd7650deedab1a3cd54750fdd0f2909175841
1 /*
2 * Server-side event management
4 * Copyright (C) 1998 Alexandre Julliard
5 */
7 #include <assert.h>
8 #include <stdio.h>
9 #include <stdlib.h>
11 #include "winerror.h"
12 #include "winnt.h"
13 #include "server/thread.h"
15 struct event
17 struct object obj; /* object header */
18 int manual_reset; /* is it a manual reset event? */
19 int signaled; /* event has been signaled */
22 static void dump_event( struct object *obj, int verbose );
23 static int event_signaled( struct object *obj, struct thread *thread );
24 static int event_satisfied( struct object *obj, struct thread *thread );
25 static void destroy_event( struct object *obj );
27 static const struct object_ops event_ops =
29 dump_event,
30 event_signaled,
31 event_satisfied,
32 destroy_event
36 struct object *create_event( const char *name, int manual_reset, int initial_state )
38 struct event *event;
40 if (!(event = (struct event *)create_named_object( name, &event_ops, sizeof(*event) )))
41 return NULL;
42 if (GET_ERROR() != ERROR_ALREADY_EXISTS)
44 /* initialize it if it didn't already exist */
45 event->manual_reset = manual_reset;
46 event->signaled = initial_state;
48 return &event->obj;
51 int open_event( unsigned int access, int inherit, const char *name )
53 return open_object( name, &event_ops, access, inherit );
56 int pulse_event( int handle )
58 struct event *event;
60 if (!(event = (struct event *)get_handle_obj( current->process, handle,
61 EVENT_MODIFY_STATE, &event_ops )))
62 return 0;
63 event->signaled = 1;
64 /* wake up all waiters if manual reset, a single one otherwise */
65 wake_up( &event->obj, !event->manual_reset );
66 event->signaled = 0;
67 release_object( event );
68 return 1;
71 int set_event( int handle )
73 struct event *event;
75 if (!(event = (struct event *)get_handle_obj( current->process, handle,
76 EVENT_MODIFY_STATE, &event_ops )))
77 return 0;
78 event->signaled = 1;
79 /* wake up all waiters if manual reset, a single one otherwise */
80 wake_up( &event->obj, !event->manual_reset );
81 release_object( event );
82 return 1;
85 int reset_event( int handle )
87 struct event *event;
89 if (!(event = (struct event *)get_handle_obj( current->process, handle,
90 EVENT_MODIFY_STATE, &event_ops )))
91 return 0;
92 event->signaled = 0;
93 release_object( event );
94 return 1;
97 static void dump_event( struct object *obj, int verbose )
99 struct event *event = (struct event *)obj;
100 assert( obj->ops == &event_ops );
101 printf( "Event manual=%d signaled=%d\n", event->manual_reset, event->signaled );
104 static int event_signaled( struct object *obj, struct thread *thread )
106 struct event *event = (struct event *)obj;
107 assert( obj->ops == &event_ops );
108 return event->signaled;
111 static int event_satisfied( struct object *obj, struct thread *thread )
113 struct event *event = (struct event *)obj;
114 assert( obj->ops == &event_ops );
115 /* Reset if it's an auto-reset event */
116 if (!event->manual_reset) event->signaled = 0;
117 return 0; /* Not abandoned */
120 static void destroy_event( struct object *obj )
122 struct event *event = (struct event *)obj;
123 assert( obj->ops == &event_ops );
124 free( event );