~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/server/completion.c

Version: ~ [ wine-1.0-rc1 ] ~ [ wine-0.9.61 ] ~ [ wine-0.9.60 ] ~ [ wine-0.9.59 ] ~ [ wine-0.9.58 ] ~ [ wine-0.9.57 ] ~ [ wine-0.9.56 ] ~ [ wine-0.9.55 ] ~ [ wine-0.9.54 ] ~ [ wine-0.9.53 ] ~ [ wine-0.9.52 ] ~ [ wine-0.9.51 ] ~ [ wine-0.9.50 ] ~ [ wine-0.9.49 ] ~ [ wine-0.9.48 ] ~ [ wine-0.9.47 ] ~ [ wine-0.9.46 ] ~ [ wine-0.9.45 ] ~ [ wine-0.9.44 ] ~ [ wine-0.9.43 ] ~ [ wine-0.9.42 ] ~ [ wine-0.9.41 ] ~ [ wine-0.9.40 ] ~ [ wine-0.9.39 ] ~ [ wine-0.9.38 ] ~ [ wine-0.9.37 ] ~ [ wine-0.9.36 ] ~ [ wine-0.9.35 ] ~ [ wine-0.9.34 ] ~ [ wine-0.9.33 ] ~ [ wine-0.9.32 ] ~ [ wine-0.9.31 ] ~ [ wine-0.9.30 ] ~ [ wine-0.9.29 ] ~ [ wine-0.9.28 ] ~ [ wine-0.9.27 ] ~ [ wine-0.9.26 ] ~ [ wine-0.9.25 ] ~ [ wine-0.9.24 ] ~ [ wine-0.9.23 ] ~ [ wine-0.9.22 ] ~ [ wine-0.9.21 ] ~ [ wine-0.9.20 ] ~ [ wine-0.9.19 ] ~ [ wine-0.9.18 ] ~ [ wine-0.9.17 ] ~ [ wine-0.9.16 ] ~ [ wine-0.9.15 ] ~ [ wine-0.9.14 ] ~ [ wine-0.9.13 ] ~ [ wine-0.9.12 ] ~ [ wine-0.9.11 ] ~ [ wine-0.9.10 ] ~ [ wine-0.9.9 ] ~ [ wine-0.9.8 ] ~ [ wine-0.9.7 ] ~ [ wine-0.9.6 ] ~ [ wine-0.9.5 ] ~ [ wine-0.9.4 ] ~ [ wine-0.9.3 ] ~ [ wine-0.9.2 ] ~ [ wine-0.9.1 ] ~ [ wine-0.9 ] ~ [ wine20050930 ] ~ [ wine20050830 ] ~ [ wine20050725 ] ~ [ wine20050628 ] ~ [ wine20050524 ] ~ [ wine20050419 ] ~ [ wine20050310 ] ~ [ wine20050211 ] ~ [ wine20050111 ] ~ [ wine20041201 ] ~ [ wine20041019 ] ~ [ wine20040914 ] ~ [ wine20040813 ] ~ [ wine20040716 ] ~ [ wine20040615 ] ~ [ wine20040505 ] ~ [ wine20040408 ] ~ [ wine20040309 ] ~ [ wine20040213 ] ~ [ wine20040121 ] ~ [ wine20031212 ] ~ [ wine20031118 ] ~ [ wine20031016 ] ~ [ wine20030911 ] ~ [ wine20030813 ] ~ [ wine20030709 ] ~ [ wine20030618 ] ~ [ wine20030508 ] ~ [ wine20030408 ] ~ [ wine20030318 ] ~ [ wine20030219 ] ~ [ wine20030115 ] ~ [ wine20021219 ] ~ [ wine20021125 ] ~ [ wine20021031 ] ~ [ wine20021007 ] ~ [ wine20020904 ] ~ [ wine20020804 ] ~ [ wine20020710 ] ~ [ wine20020605 ] ~ [ wine20020509 ] ~ [ wine20020411 ] ~ [ wine20020310 ] ~ [ wine20020228 ] ~ [ wine20011226 ] ~ [ wine20011108 ] ~ [ wine20011004 ] ~ [ wine20010824 ] ~ [ wine20010731 ] ~ [ wine20010629 ] ~ [ wine20010510 ] ~ [ wine20010418 ] ~ [ wine20010326 ] ~ [ wine20010305 ] ~ [ wine20010216 ] ~ [ wine20010112 ] ~ [ wine20001222 ] ~ [ wine20001202 ] ~ [ wine20001026 ] ~ [ wine20001002 ] ~ [ wine20000909 ] ~ [ wine20000821 ] ~ [ wine20000801 ] ~ [ wine20000716 ] ~ [ wine20000326 ] ~ [ wine20000227 ] ~ [ wine20000130 ] ~ [ wine20000109 ] ~

  1 /*
  2  * Server-side IO completion ports implementation
  3  *
  4  * Copyright (C) 2007 Andrey Turkin
  5  *
  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.
 10  *
 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.
 15  *
 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 19  *
 20  */
 21 
 22 /* FIXMEs:
 23  *  - built-in wait queues used which means:
 24  *    + threads are awaken FIFO and not LIFO as native does
 25  *    + "max concurrent active threads" parameter not used
 26  *    + completion handle is waitable, while native isn't
 27  */
 28 
 29 #include "config.h"
 30 #include "wine/port.h"
 31 
 32 #include <stdarg.h>
 33 #include <stdio.h>
 34 
 35 #include "ntstatus.h"
 36 #define WIN32_NO_STATUS
 37 #include "windef.h"
 38 #include "winternl.h"
 39 
 40 #include "wine/unicode.h"
 41 #include "object.h"
 42 #include "file.h"
 43 #include "handle.h"
 44 #include "request.h"
 45 
 46 
 47 struct completion
 48 {
 49     struct object  obj;
 50     struct list    queue;
 51     unsigned int   depth;
 52 };
 53 
 54 static void completion_dump( struct object*, int );
 55 static struct object_type *completion_get_type( struct object *obj );
 56 static void completion_destroy( struct object * );
 57 static int  completion_signaled( struct object *obj, struct thread *thread );
 58 
 59 static const struct object_ops completion_ops =
 60 {
 61     sizeof(struct completion), /* size */
 62     completion_dump,           /* dump */
 63     completion_get_type,       /* get_type */
 64     add_queue,                 /* add_queue */
 65     remove_queue,              /* remove_queue */
 66     completion_signaled,       /* signaled */
 67     no_satisfied,              /* satisfied */
 68     no_signal,                 /* signal */
 69     no_get_fd,                 /* get_fd */
 70     no_map_access,             /* map_access */
 71     default_get_sd,            /* get_sd */
 72     default_set_sd,            /* set_sd */
 73     no_lookup_name,            /* lookup_name */
 74     no_open_file,              /* open_file */
 75     no_close_handle,           /* close_handle */
 76     completion_destroy         /* destroy */
 77 };
 78 
 79 struct comp_msg
 80 {
 81     struct   list queue_entry;
 82     unsigned long ckey;
 83     unsigned long cvalue;
 84     unsigned long information;
 85     unsigned int  status;
 86 };
 87 
 88 static void completion_destroy( struct object *obj)
 89 {
 90     struct completion *completion = (struct completion *) obj;
 91     struct comp_msg *tmp, *next;
 92 
 93     LIST_FOR_EACH_ENTRY_SAFE( tmp, next, &completion->queue, struct comp_msg, queue_entry )
 94     {
 95         free( tmp );
 96     }
 97 }
 98 
 99 static void completion_dump( struct object *obj, int verbose )
100 {
101     struct completion *completion = (struct completion *) obj;
102 
103     assert( obj->ops == &completion_ops );
104     fprintf( stderr, "Completion " );
105     dump_object_name( &completion->obj );
106     fprintf( stderr, " (%u packets pending)\n", completion->depth );
107 }
108 
109 static struct object_type *completion_get_type( struct object *obj )
110 {
111     static const WCHAR name[] = {'C','o','m','p','l','e','t','i','o','n'};
112     static const struct unicode_str str = { name, sizeof(name) };
113     return get_object_type( &str );
114 }
115 
116 static int completion_signaled( struct object *obj, struct thread *thread )
117 {
118     struct completion *completion = (struct completion *)obj;
119 
120     return !list_empty( &completion->queue );
121 }
122 
123 static struct completion *create_completion( struct directory *root, const struct unicode_str *name, unsigned int attr, unsigned int concurrent )
124 {
125     struct completion *completion;
126 
127     if ((completion = create_named_object_dir( root, name, attr, &completion_ops )))
128     {
129         if (get_error() != STATUS_OBJECT_NAME_EXISTS)
130         {
131             list_init( &completion->queue );
132             completion->depth = 0;
133         }
134     }
135 
136     return completion;
137 }
138 
139 struct completion *get_completion_obj( struct process *process, obj_handle_t handle, unsigned int access )
140 {
141     return (struct completion *) get_handle_obj( process, handle, access, &completion_ops );
142 }
143 
144 void add_completion( struct completion *completion, unsigned long ckey, unsigned long cvalue, unsigned int status, unsigned long information )
145 {
146     struct comp_msg *msg = mem_alloc( sizeof( *msg ) );
147 
148     if (!msg)
149         return;
150 
151     msg->ckey = ckey;
152     msg->cvalue = cvalue;
153     msg->status = status;
154     msg->information = information;
155 
156     list_add_tail( &completion->queue, &msg->queue_entry );
157     completion->depth++;
158     wake_up( &completion->obj, 1 );
159 }
160 
161 /* create a completion */
162 DECL_HANDLER(create_completion)
163 {
164     struct completion *completion;
165     struct unicode_str name;
166     struct directory *root = NULL;
167 
168     reply->handle = 0;
169 
170     get_req_unicode_str( &name );
171     if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 )))
172         return;
173 
174     if ( (completion = create_completion( root, &name, req->attributes, req->concurrent )) != NULL )
175     {
176         reply->handle = alloc_handle( current->process, completion, req->access, req->attributes );
177         release_object( completion );
178     }
179 
180     if (root) release_object( root );
181 }
182 
183 /* open a completion */
184 DECL_HANDLER(open_completion)
185 {
186     struct completion *completion;
187     struct unicode_str name;
188     struct directory *root = NULL;
189 
190     reply->handle = 0;
191 
192     get_req_unicode_str( &name );
193     if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 )))
194         return;
195 
196     if ( (completion = open_object_dir( root, &name, req->attributes, &completion_ops )) != NULL )
197     {
198         reply->handle = alloc_handle( current->process, completion, req->access, req->attributes );
199         release_object( completion );
200     }
201 
202     if (root) release_object( root );
203 }
204 
205 
206 /* add completion to completion port */
207 DECL_HANDLER(add_completion)
208 {
209     struct completion* completion = get_completion_obj( current->process, req->handle, IO_COMPLETION_MODIFY_STATE );
210 
211     if (!completion) return;
212 
213     add_completion( completion, req->ckey, req->cvalue, req->status, req->information );
214 
215     release_object( completion );
216 }
217 
218 /* get completion from completion port */
219 DECL_HANDLER(remove_completion)
220 {
221     struct completion* completion = get_completion_obj( current->process, req->handle, IO_COMPLETION_MODIFY_STATE );
222     struct list *entry;
223     struct comp_msg *msg;
224 
225     if (!completion) return;
226 
227     entry = list_head( &completion->queue );
228     if (!entry)
229         set_error( STATUS_PENDING );
230     else
231     {
232         list_remove( entry );
233         completion->depth--;
234         msg = LIST_ENTRY( entry, struct comp_msg, queue_entry );
235         reply->ckey = msg->ckey;
236         reply->cvalue = msg->cvalue;
237         reply->status = msg->status;
238         reply->information = msg->information;
239         free( msg );
240     }
241 
242     release_object( completion );
243 }
244 
245 /* get queue depth for completion port */
246 DECL_HANDLER(query_completion)
247 {
248     struct completion* completion = get_completion_obj( current->process, req->handle, IO_COMPLETION_QUERY_STATE );
249 
250     if (!completion) return;
251 
252     reply->depth = completion->depth;
253 
254     release_object( completion );
255 }
256 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.