Removed a number of global handle allocations and critical section
[wine/multimedia.git] / server / object.h
blob53cb9dc702bff040f1f92f5ce42c775b1bdde8eb
1 /*
2 * Wine server objects
4 * Copyright (C) 1998 Alexandre Julliard
5 */
7 #ifndef __WINE_SERVER_OBJECT_H
8 #define __WINE_SERVER_OBJECT_H
10 #ifndef __WINE_SERVER__
11 #error This file can only be used in the Wine server
12 #endif
14 #include <sys/poll.h>
15 #include <sys/time.h>
16 #include "server.h"
18 #define DEBUG_OBJECTS
20 /* kernel objects */
22 struct object;
23 struct object_name;
24 struct thread;
25 struct process;
26 struct file;
27 struct wait_queue_entry;
29 /* operations valid on all objects */
30 struct object_ops
32 /* size of this object type */
33 size_t size;
34 /* dump the object (for debugging) */
35 void (*dump)(struct object *,int);
36 /* add a thread to the object wait queue */
37 int (*add_queue)(struct object *,struct wait_queue_entry *);
38 /* remove a thread from the object wait queue */
39 void (*remove_queue)(struct object *,struct wait_queue_entry *);
40 /* is object signaled? */
41 int (*signaled)(struct object *,struct thread *);
42 /* wait satisfied; return 1 if abandoned */
43 int (*satisfied)(struct object *,struct thread *);
44 /* get the events we want to poll() for on this object */
45 int (*get_poll_events)(struct object *);
46 /* a poll() event occured */
47 void (*poll_event)(struct object *,int event);
48 /* return a Unix fd that can be used to read from the object */
49 int (*get_read_fd)(struct object *);
50 /* return a Unix fd that can be used to write to the object */
51 int (*get_write_fd)(struct object *);
52 /* flush the object buffers */
53 int (*flush)(struct object *);
54 /* get file information */
55 int (*get_file_info)(struct object *,struct get_file_info_request *);
56 /* destroy on refcount == 0 */
57 void (*destroy)(struct object *);
60 struct object
62 unsigned int refcount; /* reference count */
63 int fd; /* file descriptor */
64 int select; /* select() user id */
65 const struct object_ops *ops;
66 struct wait_queue_entry *head;
67 struct wait_queue_entry *tail;
68 struct object_name *name;
69 #ifdef DEBUG_OBJECTS
70 struct object *prev;
71 struct object *next;
72 #endif
75 extern void *mem_alloc( size_t size ); /* malloc wrapper */
76 extern void *memdup( const void *data, size_t len );
77 extern void *alloc_object( const struct object_ops *ops, int fd );
78 extern void dump_object_name( struct object *obj );
79 extern void *create_named_object( const struct object_ops *ops, const WCHAR *name, size_t len );
80 /* grab/release_object can take any pointer, but you better make sure */
81 /* that the thing pointed to starts with a struct object... */
82 extern struct object *grab_object( void *obj );
83 extern void release_object( void *obj );
84 extern struct object *find_object( const WCHAR *name, size_t len );
85 extern int no_add_queue( struct object *obj, struct wait_queue_entry *entry );
86 extern int no_satisfied( struct object *obj, struct thread *thread );
87 extern int no_read_fd( struct object *obj );
88 extern int no_write_fd( struct object *obj );
89 extern int no_flush( struct object *obj );
90 extern int no_get_file_info( struct object *obj, struct get_file_info_request *info );
91 extern void no_destroy( struct object *obj );
92 extern int default_poll_add_queue( struct object *obj, struct wait_queue_entry *entry );
93 extern void default_poll_remove_queue( struct object *obj, struct wait_queue_entry *entry );
94 extern int default_poll_signaled( struct object *obj, struct thread *thread );
95 extern void default_poll_event( struct object *obj, int event );
96 #ifdef DEBUG_OBJECTS
97 extern void dump_objects(void);
98 #endif
100 /* select functions */
102 extern int add_select_user( struct object *obj );
103 extern void remove_select_user( struct object *obj );
104 extern void change_select_fd( struct object *obj, int fd );
105 extern void set_select_events( struct object *obj, int events );
106 extern int check_select_events( int fd, int events );
107 extern void select_loop(void);
109 /* timeout functions */
111 struct timeout_user;
113 typedef void (*timeout_callback)( void *private );
115 extern struct timeout_user *add_timeout_user( struct timeval *when,
116 timeout_callback func, void *private );
117 extern void remove_timeout_user( struct timeout_user *user );
118 extern void add_timeout( struct timeval *when, int timeout );
119 /* return 1 if t1 is before t2 */
120 static inline int time_before( struct timeval *t1, struct timeval *t2 )
122 return ((t1->tv_sec < t2->tv_sec) ||
123 ((t1->tv_sec == t2->tv_sec) && (t1->tv_usec < t2->tv_usec)));
126 /* event functions */
128 struct event;
130 extern struct event *get_event_obj( struct process *process, int handle, unsigned int access );
131 extern void pulse_event( struct event *event );
132 extern void set_event( struct event *event );
133 extern void reset_event( struct event *event );
135 /* mutex functions */
137 extern void abandon_mutexes( struct thread *thread );
139 /* file functions */
141 extern struct file *get_file_obj( struct process *process, int handle,
142 unsigned int access );
143 extern int file_get_mmap_fd( struct file *file );
144 extern int grow_file( struct file *file, int size_high, int size_low );
145 extern int create_anonymous_file(void);
146 extern struct file *create_temp_file( int access );
147 extern void file_set_error(void);
149 /* console functions */
151 extern int alloc_console( struct process *process );
152 extern int free_console( struct process *process );
154 /* debugger functions */
156 extern int set_process_debugger( struct process *process, struct thread *debugger );
157 extern void generate_debug_event( struct thread *thread, int code, void *arg );
158 extern void generate_startup_debug_events( struct process *process, void *entry );
159 extern void debug_exit_thread( struct thread *thread );
161 /* mapping functions */
163 extern int get_page_size(void);
165 /* registry functions */
167 extern void close_registry(void);
169 /* atom functions */
171 extern void close_atom_table(void);
173 /* global variables (command-line options) */
175 extern int debug_level;
176 extern int persistent_server;
178 #endif /* __WINE_SERVER_OBJECT_H */