DEBUG_cmp_sym: micro optimization/cleanup.
[wine/multimedia.git] / server / event.c
blobbc1b5a4c6bfc61e478ca1fbe382ef708349e20f9
1 /*
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
21 #include "config.h"
22 #include "wine/port.h"
24 #include <assert.h>
25 #include <stdio.h>
26 #include <stdlib.h>
28 #include "windef.h"
30 #include "handle.h"
31 #include "thread.h"
32 #include "request.h"
34 struct event
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 );
45 static const struct object_ops event_ops =
47 sizeof(struct event), /* size */
48 event_dump, /* dump */
49 add_queue, /* add_queue */
50 remove_queue, /* remove_queue */
51 event_signaled, /* signaled */
52 event_satisfied, /* satisfied */
53 no_get_fd, /* get_fd */
54 no_destroy /* destroy */
58 struct event *create_event( const WCHAR *name, size_t len,
59 int manual_reset, int initial_state )
61 struct event *event;
63 if ((event = create_named_object( sync_namespace, &event_ops, name, len )))
65 if (get_error() != STATUS_OBJECT_NAME_COLLISION)
67 /* initialize it if it didn't already exist */
68 event->manual_reset = manual_reset;
69 event->signaled = initial_state;
72 return event;
75 struct event *get_event_obj( struct process *process, obj_handle_t handle, unsigned int access )
77 return (struct event *)get_handle_obj( process, handle, access, &event_ops );
80 void pulse_event( struct event *event )
82 event->signaled = 1;
83 /* wake up all waiters if manual reset, a single one otherwise */
84 wake_up( &event->obj, !event->manual_reset );
85 event->signaled = 0;
88 void set_event( struct event *event )
90 event->signaled = 1;
91 /* wake up all waiters if manual reset, a single one otherwise */
92 wake_up( &event->obj, !event->manual_reset );
95 void reset_event( struct event *event )
97 event->signaled = 0;
100 static void event_dump( struct object *obj, int verbose )
102 struct event *event = (struct event *)obj;
103 assert( obj->ops == &event_ops );
104 fprintf( stderr, "Event manual=%d signaled=%d ",
105 event->manual_reset, event->signaled );
106 dump_object_name( &event->obj );
107 fputc( '\n', stderr );
110 static int event_signaled( struct object *obj, struct thread *thread )
112 struct event *event = (struct event *)obj;
113 assert( obj->ops == &event_ops );
114 return event->signaled;
117 static int event_satisfied( struct object *obj, struct thread *thread )
119 struct event *event = (struct event *)obj;
120 assert( obj->ops == &event_ops );
121 /* Reset if it's an auto-reset event */
122 if (!event->manual_reset) event->signaled = 0;
123 return 0; /* Not abandoned */
126 /* create an event */
127 DECL_HANDLER(create_event)
129 struct event *event;
131 reply->handle = 0;
132 if ((event = create_event( get_req_data(), get_req_data_size(),
133 req->manual_reset, req->initial_state )))
135 reply->handle = alloc_handle( current->process, event, EVENT_ALL_ACCESS, req->inherit );
136 release_object( event );
140 /* open a handle to an event */
141 DECL_HANDLER(open_event)
143 reply->handle = open_object( sync_namespace, get_req_data(), get_req_data_size(),
144 &event_ops, req->access, req->inherit );
147 /* do an event operation */
148 DECL_HANDLER(event_op)
150 struct event *event;
152 if (!(event = get_event_obj( current->process, req->handle, EVENT_MODIFY_STATE ))) return;
153 switch(req->op)
155 case PULSE_EVENT:
156 pulse_event( event );
157 break;
158 case SET_EVENT:
159 set_event( event );
160 break;
161 case RESET_EVENT:
162 reset_event( event );
163 break;
164 default:
165 fatal_protocol_error( current, "event_op: invalid operation %d\n", req->op );
167 release_object( event );