No longer sending atoms in ((CREATESTRUCT*)lParam)->lpszName of
[wine.git] / server / event.c
blob04f51603918b4fcb1c23000dfa5ac53e76b710b4
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/process.h"
14 #include "server/thread.h"
16 struct event
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 =
30 event_dump,
31 add_queue,
32 remove_queue,
33 event_signaled,
34 event_satisfied,
35 no_read_fd,
36 no_write_fd,
37 no_flush,
38 no_get_file_info,
39 event_destroy
43 struct object *create_event( const char *name, int manual_reset, int initial_state )
45 struct event *event;
47 if (!(event = (struct event *)create_named_object( name, &event_ops, sizeof(*event) )))
48 return NULL;
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;
55 return &event->obj;
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 )
65 struct event *event;
67 if (!(event = (struct event *)get_handle_obj( current->process, handle,
68 EVENT_MODIFY_STATE, &event_ops )))
69 return 0;
70 event->signaled = 1;
71 /* wake up all waiters if manual reset, a single one otherwise */
72 wake_up( &event->obj, !event->manual_reset );
73 event->signaled = 0;
74 release_object( event );
75 return 1;
78 int set_event( int handle )
80 struct event *event;
82 if (!(event = (struct event *)get_handle_obj( current->process, handle,
83 EVENT_MODIFY_STATE, &event_ops )))
84 return 0;
85 event->signaled = 1;
86 /* wake up all waiters if manual reset, a single one otherwise */
87 wake_up( &event->obj, !event->manual_reset );
88 release_object( event );
89 return 1;
92 int reset_event( int handle )
94 struct event *event;
96 if (!(event = (struct event *)get_handle_obj( current->process, handle,
97 EVENT_MODIFY_STATE, &event_ops )))
98 return 0;
99 event->signaled = 0;
100 release_object( event );
101 return 1;
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 );
133 free( event );