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"
37 struct object obj
; /* object header */
38 int manual_reset
; /* is it a manual reset event? */
39 int signaled
; /* event has been signaled */
42 static void event_dump( struct object
*obj
, int verbose
);
43 static int event_signaled( struct object
*obj
, struct thread
*thread
);
44 static int event_satisfied( struct object
*obj
, struct thread
*thread
);
45 static int event_signal( struct object
*obj
, unsigned int access
);
47 static const struct object_ops event_ops
=
49 sizeof(struct event
), /* size */
50 event_dump
, /* dump */
51 add_queue
, /* add_queue */
52 remove_queue
, /* remove_queue */
53 event_signaled
, /* signaled */
54 event_satisfied
, /* satisfied */
55 event_signal
, /* signal */
56 no_get_fd
, /* get_fd */
57 no_close_handle
, /* close_handle */
58 no_destroy
/* destroy */
62 struct event
*create_event( const struct unicode_str
*name
, unsigned int attr
,
63 int manual_reset
, int initial_state
)
67 if ((event
= create_named_object( sync_namespace
, &event_ops
, name
, attr
)))
69 if (get_error() != STATUS_OBJECT_NAME_COLLISION
)
71 /* initialize it if it didn't already exist */
72 event
->manual_reset
= manual_reset
;
73 event
->signaled
= initial_state
;
79 struct event
*get_event_obj( struct process
*process
, obj_handle_t handle
, unsigned int access
)
81 return (struct event
*)get_handle_obj( process
, handle
, access
, &event_ops
);
84 void pulse_event( struct event
*event
)
87 /* wake up all waiters if manual reset, a single one otherwise */
88 wake_up( &event
->obj
, !event
->manual_reset
);
92 void set_event( struct event
*event
)
95 /* wake up all waiters if manual reset, a single one otherwise */
96 wake_up( &event
->obj
, !event
->manual_reset
);
99 void reset_event( struct event
*event
)
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 ",
109 event
->manual_reset
, event
->signaled
);
110 dump_object_name( &event
->obj
);
111 fputc( '\n', stderr
);
114 static int event_signaled( struct object
*obj
, struct thread
*thread
)
116 struct event
*event
= (struct event
*)obj
;
117 assert( obj
->ops
== &event_ops
);
118 return event
->signaled
;
121 static int event_satisfied( struct object
*obj
, struct thread
*thread
)
123 struct event
*event
= (struct event
*)obj
;
124 assert( obj
->ops
== &event_ops
);
125 /* Reset if it's an auto-reset event */
126 if (!event
->manual_reset
) event
->signaled
= 0;
127 return 0; /* Not abandoned */
130 static int event_signal( struct object
*obj
, unsigned int access
)
132 struct event
*event
= (struct event
*)obj
;
133 assert( obj
->ops
== &event_ops
);
135 if (!(access
& EVENT_MODIFY_STATE
))
137 set_error( STATUS_ACCESS_DENIED
);
144 /* create an event */
145 DECL_HANDLER(create_event
)
148 struct unicode_str name
;
151 get_req_unicode_str( &name
);
152 if ((event
= create_event( &name
, req
->attributes
, req
->manual_reset
, req
->initial_state
)))
154 reply
->handle
= alloc_handle( current
->process
, event
, req
->access
,
155 req
->attributes
& OBJ_INHERIT
);
156 release_object( event
);
160 /* open a handle to an event */
161 DECL_HANDLER(open_event
)
163 struct unicode_str name
;
165 get_req_unicode_str( &name
);
166 reply
->handle
= open_object( sync_namespace
, &name
, &event_ops
, req
->access
, req
->attributes
);
169 /* do an event operation */
170 DECL_HANDLER(event_op
)
174 if (!(event
= get_event_obj( current
->process
, req
->handle
, EVENT_MODIFY_STATE
))) return;
178 pulse_event( event
);
184 reset_event( event
);
187 fatal_protocol_error( current
, "event_op: invalid operation %d\n", req
->op
);
189 release_object( event
);