2 * Server-side event management
4 * Copyright (C) 1998 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/port.h"
36 struct object obj; /* object header */
37 int manual_reset; /* is it a manual reset event? */
38 int signaled; /* event has been signaled */
41 static void event_dump( struct object *obj, int verbose );
42 static int event_signaled( struct object *obj, struct thread *thread );
43 static int event_satisfied( struct object *obj, struct thread *thread );
44 static int event_signal( struct object *obj, unsigned int access);
46 static const struct object_ops event_ops =
48 sizeof(struct event), /* size */
49 event_dump, /* dump */
50 add_queue, /* add_queue */
51 remove_queue, /* remove_queue */
52 event_signaled, /* signaled */
53 event_satisfied, /* satisfied */
54 event_signal, /* signal */
55 no_get_fd, /* get_fd */
56 no_destroy /* destroy */
60 struct event *create_event( const WCHAR *name, size_t len,
61 int manual_reset, int initial_state )
65 if ((event = create_named_object( sync_namespace, &event_ops, name, len )))
67 if (get_error() != STATUS_OBJECT_NAME_COLLISION)
69 /* initialize it if it didn't already exist */
70 event->manual_reset = manual_reset;
71 event->signaled = initial_state;
77 struct event *get_event_obj( struct process *process, obj_handle_t handle, unsigned int access )
79 return (struct event *)get_handle_obj( process, handle, access, &event_ops );
82 void pulse_event( struct event *event )
85 /* wake up all waiters if manual reset, a single one otherwise */
86 wake_up( &event->obj, !event->manual_reset );
90 void set_event( struct event *event )
93 /* wake up all waiters if manual reset, a single one otherwise */
94 wake_up( &event->obj, !event->manual_reset );
97 void reset_event( struct event *event )
102 static void event_dump( struct object *obj, int verbose )
104 struct event *event = (struct event *)obj;
105 assert( obj->ops == &event_ops );
106 fprintf( stderr, "Event manual=%d signaled=%d ",
107 event->manual_reset, event->signaled );
108 dump_object_name( &event->obj );
109 fputc( '\n', stderr );
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 int event_signal( struct object *obj, unsigned int access )
130 struct event *event = (struct event *)obj;
131 assert( obj->ops == &event_ops );
133 if (!(access & EVENT_MODIFY_STATE))
135 set_error( STATUS_ACCESS_DENIED );
142 /* create an event */
143 DECL_HANDLER(create_event)
148 if ((event = create_event( get_req_data(), get_req_data_size(),
149 req->manual_reset, req->initial_state )))
151 reply->handle = alloc_handle( current->process, event, req->access, req->inherit );
152 release_object( event );
156 /* open a handle to an event */
157 DECL_HANDLER(open_event)
159 reply->handle = open_object( sync_namespace, get_req_data(), get_req_data_size(),
160 &event_ops, req->access, req->inherit );
163 /* do an event operation */
164 DECL_HANDLER(event_op)
168 if (!(event = get_event_obj( current->process, req->handle, EVENT_MODIFY_STATE ))) return;
172 pulse_event( event );
178 reset_event( event );
181 fatal_protocol_error( current, "event_op: invalid operation %d\n", req->op );
183 release_object( event );