2 * Server-side event management
4 * Copyright (C) 1998 Alexandre Julliard
19 struct object obj
; /* object header */
20 int manual_reset
; /* is it a manual reset event? */
21 int signaled
; /* event has been signaled */
24 static void event_dump( struct object
*obj
, int verbose
);
25 static int event_signaled( struct object
*obj
, struct thread
*thread
);
26 static int event_satisfied( struct object
*obj
, struct thread
*thread
);
27 static void event_destroy( struct object
*obj
);
29 static const struct object_ops event_ops
=
44 static struct object
*create_event( const char *name
, int manual_reset
, int initial_state
)
48 if (!(event
= (struct event
*)create_named_object( name
, &event_ops
, sizeof(*event
) )))
50 if (GET_ERROR() != ERROR_ALREADY_EXISTS
)
52 /* initialize it if it didn't already exist */
53 event
->manual_reset
= manual_reset
;
54 event
->signaled
= initial_state
;
59 static int pulse_event( int handle
)
63 if (!(event
= (struct event
*)get_handle_obj( current
->process
, handle
,
64 EVENT_MODIFY_STATE
, &event_ops
)))
67 /* wake up all waiters if manual reset, a single one otherwise */
68 wake_up( &event
->obj
, !event
->manual_reset
);
70 release_object( event
);
74 static int set_event( int handle
)
78 if (!(event
= (struct event
*)get_handle_obj( current
->process
, handle
,
79 EVENT_MODIFY_STATE
, &event_ops
)))
82 /* wake up all waiters if manual reset, a single one otherwise */
83 wake_up( &event
->obj
, !event
->manual_reset
);
84 release_object( event
);
88 static int reset_event( int handle
)
92 if (!(event
= (struct event
*)get_handle_obj( current
->process
, handle
,
93 EVENT_MODIFY_STATE
, &event_ops
)))
96 release_object( event
);
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 name='%s'\n",
105 event
->manual_reset
, event
->signaled
,
106 get_object_name( &event
->obj
) );
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
);
132 /* create an event */
133 DECL_HANDLER(create_event
)
135 struct create_event_reply reply
= { -1 };
137 char *name
= (char *)data
;
138 if (!len
) name
= NULL
;
139 else CHECK_STRING( "create_event", name
, len
);
141 obj
= create_event( name
, req
->manual_reset
, req
->initial_state
);
144 reply
.handle
= alloc_handle( current
->process
, obj
, EVENT_ALL_ACCESS
, req
->inherit
);
145 release_object( obj
);
147 send_reply( current
, -1, 1, &reply
, sizeof(reply
) );
150 /* open a handle to an event */
151 DECL_HANDLER(open_event
)
153 struct open_event_reply reply
;
154 char *name
= (char *)data
;
155 if (!len
) name
= NULL
;
156 else CHECK_STRING( "open_event", name
, len
);
158 reply
.handle
= open_object( name
, &event_ops
, req
->access
, req
->inherit
);
159 send_reply( current
, -1, 1, &reply
, sizeof(reply
) );
162 /* do an event operation */
163 DECL_HANDLER(event_op
)
168 pulse_event( req
->handle
);
171 set_event( req
->handle
);
174 reset_event( req
->handle
);
177 fatal_protocol_error( "event_op: invalid operation %d\n", req
->op
);
179 send_reply( current
, -1, 0 );