2 * Server-side event management
4 * Copyright (C) 1998 Alexandre Julliard
13 #include "server/thread.h"
17 struct object obj
; /* object header */
18 int manual_reset
; /* is it a manual reset event? */
19 int signaled
; /* event has been signaled */
22 static void dump_event( struct object
*obj
, int verbose
);
23 static int event_signaled( struct object
*obj
, struct thread
*thread
);
24 static int event_satisfied( struct object
*obj
, struct thread
*thread
);
25 static void destroy_event( struct object
*obj
);
27 static const struct object_ops event_ops
=
36 struct object
*create_event( const char *name
, int manual_reset
, int initial_state
)
40 if (!(event
= (struct event
*)create_named_object( name
, &event_ops
, sizeof(*event
) )))
42 if (GET_ERROR() != ERROR_ALREADY_EXISTS
)
44 /* initialize it if it didn't already exist */
45 event
->manual_reset
= manual_reset
;
46 event
->signaled
= initial_state
;
51 int open_event( unsigned int access
, int inherit
, const char *name
)
53 return open_object( name
, &event_ops
, access
, inherit
);
56 int pulse_event( int handle
)
60 if (!(event
= (struct event
*)get_handle_obj( current
->process
, handle
,
61 EVENT_MODIFY_STATE
, &event_ops
)))
64 /* wake up all waiters if manual reset, a single one otherwise */
65 wake_up( &event
->obj
, !event
->manual_reset
);
67 release_object( event
);
71 int set_event( int handle
)
75 if (!(event
= (struct event
*)get_handle_obj( current
->process
, handle
,
76 EVENT_MODIFY_STATE
, &event_ops
)))
79 /* wake up all waiters if manual reset, a single one otherwise */
80 wake_up( &event
->obj
, !event
->manual_reset
);
81 release_object( event
);
85 int reset_event( int handle
)
89 if (!(event
= (struct event
*)get_handle_obj( current
->process
, handle
,
90 EVENT_MODIFY_STATE
, &event_ops
)))
93 release_object( event
);
97 static void dump_event( struct object
*obj
, int verbose
)
99 struct event
*event
= (struct event
*)obj
;
100 assert( obj
->ops
== &event_ops
);
101 printf( "Event manual=%d signaled=%d\n", event
->manual_reset
, event
->signaled
);
104 static int event_signaled( struct object
*obj
, struct thread
*thread
)
106 struct event
*event
= (struct event
*)obj
;
107 assert( obj
->ops
== &event_ops
);
108 return event
->signaled
;
111 static int event_satisfied( struct object
*obj
, struct thread
*thread
)
113 struct event
*event
= (struct event
*)obj
;
114 assert( obj
->ops
== &event_ops
);
115 /* Reset if it's an auto-reset event */
116 if (!event
->manual_reset
) event
->signaled
= 0;
117 return 0; /* Not abandoned */
120 static void destroy_event( struct object
*obj
)
122 struct event
*event
= (struct event
*)obj
;
123 assert( obj
->ops
== &event_ops
);