Fixed CHECK_STRING display.
[wine/multimedia.git] / server / event.c
blob7a400ef4ed673946ef2db98670367d018e0ecb61
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 event_destroy
41 struct object *create_event( const char *name, int manual_reset, int initial_state )
43 struct event *event;
45 if (!(event = (struct event *)create_named_object( name, &event_ops, sizeof(*event) )))
46 return NULL;
47 if (GET_ERROR() != ERROR_ALREADY_EXISTS)
49 /* initialize it if it didn't already exist */
50 event->manual_reset = manual_reset;
51 event->signaled = initial_state;
53 return &event->obj;
56 int open_event( unsigned int access, int inherit, const char *name )
58 return open_object( name, &event_ops, access, inherit );
61 int pulse_event( int handle )
63 struct event *event;
65 if (!(event = (struct event *)get_handle_obj( current->process, handle,
66 EVENT_MODIFY_STATE, &event_ops )))
67 return 0;
68 event->signaled = 1;
69 /* wake up all waiters if manual reset, a single one otherwise */
70 wake_up( &event->obj, !event->manual_reset );
71 event->signaled = 0;
72 release_object( event );
73 return 1;
76 int set_event( int handle )
78 struct event *event;
80 if (!(event = (struct event *)get_handle_obj( current->process, handle,
81 EVENT_MODIFY_STATE, &event_ops )))
82 return 0;
83 event->signaled = 1;
84 /* wake up all waiters if manual reset, a single one otherwise */
85 wake_up( &event->obj, !event->manual_reset );
86 release_object( event );
87 return 1;
90 int reset_event( int handle )
92 struct event *event;
94 if (!(event = (struct event *)get_handle_obj( current->process, handle,
95 EVENT_MODIFY_STATE, &event_ops )))
96 return 0;
97 event->signaled = 0;
98 release_object( event );
99 return 1;
102 static void event_dump( struct object *obj, int verbose )
104 struct event *event = (struct event *)obj;
105 assert( obj->ops == &event_ops );
106 printf( "Event manual=%d signaled=%d\n", event->manual_reset, event->signaled );
109 static int event_signaled( struct object *obj, struct thread *thread )
111 struct event *event = (struct event *)obj;
112 assert( obj->ops == &event_ops );
113 return event->signaled;
116 static int event_satisfied( struct object *obj, struct thread *thread )
118 struct event *event = (struct event *)obj;
119 assert( obj->ops == &event_ops );
120 /* Reset if it's an auto-reset event */
121 if (!event->manual_reset) event->signaled = 0;
122 return 0; /* Not abandoned */
125 static void event_destroy( struct object *obj )
127 struct event *event = (struct event *)obj;
128 assert( obj->ops == &event_ops );
129 free( event );