Moved ADVAPI32 files to dlls/advapi32.
[wine/multimedia.git] / server / event.c
bloba6ca09968b156f742ed929d92a1cba1f23983b84
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 event_dump( 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 event_destroy( struct object *obj );
27 static const struct object_ops event_ops =
29 event_dump,
30 add_queue,
31 remove_queue,
32 event_signaled,
33 event_satisfied,
34 no_read_fd,
35 no_write_fd,
36 no_flush,
37 no_get_file_info,
38 event_destroy
42 struct object *create_event( const char *name, int manual_reset, int initial_state )
44 struct event *event;
46 if (!(event = (struct event *)create_named_object( name, &event_ops, sizeof(*event) )))
47 return NULL;
48 if (GET_ERROR() != ERROR_ALREADY_EXISTS)
50 /* initialize it if it didn't already exist */
51 event->manual_reset = manual_reset;
52 event->signaled = initial_state;
54 return &event->obj;
57 int open_event( unsigned int access, int inherit, const char *name )
59 return open_object( name, &event_ops, access, inherit );
62 int pulse_event( int handle )
64 struct event *event;
66 if (!(event = (struct event *)get_handle_obj( current->process, handle,
67 EVENT_MODIFY_STATE, &event_ops )))
68 return 0;
69 event->signaled = 1;
70 /* wake up all waiters if manual reset, a single one otherwise */
71 wake_up( &event->obj, !event->manual_reset );
72 event->signaled = 0;
73 release_object( event );
74 return 1;
77 int set_event( int handle )
79 struct event *event;
81 if (!(event = (struct event *)get_handle_obj( current->process, handle,
82 EVENT_MODIFY_STATE, &event_ops )))
83 return 0;
84 event->signaled = 1;
85 /* wake up all waiters if manual reset, a single one otherwise */
86 wake_up( &event->obj, !event->manual_reset );
87 release_object( event );
88 return 1;
91 int reset_event( int handle )
93 struct event *event;
95 if (!(event = (struct event *)get_handle_obj( current->process, handle,
96 EVENT_MODIFY_STATE, &event_ops )))
97 return 0;
98 event->signaled = 0;
99 release_object( event );
100 return 1;
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 static void event_destroy( struct object *obj )
130 struct event *event = (struct event *)obj;
131 assert( obj->ops == &event_ops );
132 free( event );