2 * Server-side support for async i/o operations
4 * Copyright (C) 1998 Alexandre Julliard
5 * Copyright (C) 2000 Mike McCormack
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
37 void destroy_async( struct async *async )
39 struct async_queue *aq = async->q;
41 /*fprintf(stderr,"destroyed async %p\n",async->overlapped); */
44 remove_timeout_user(async->timeout);
45 async->timeout = NULL;
48 async->prev->next = async->next;
50 aq->head = async->next;
53 async->next->prev = async->prev;
55 aq->tail = async->prev;
60 release_object( async->thread );
64 void async_notify(struct async *async, int status)
66 /* fprintf(stderr,"notifying %p!\n",async->overlapped); */
67 async->status = status;
68 thread_queue_apc(async->thread, NULL, NULL, APC_ASYNC_IO, 1, 2, async->overlapped, status);
71 void destroy_async_queue( struct async_queue *q )
75 async_notify(q->head, STATUS_CANCELLED);
76 destroy_async(q->head);
80 struct async *find_async(struct async_queue *q, struct thread *thread, void *overlapped)
84 /* fprintf(stderr,"find_async: %p\n",overlapped); */
89 for(async = q->head; async; async = async->next)
90 if((async->overlapped==overlapped) && (async->thread == thread))
96 void async_insert(struct async_queue *q, struct async *async)
99 async->prev = q->tail;
103 q->tail->next = async;
110 static void async_callback(void *private)
112 struct async *async = (struct async *)private;
114 /* fprintf(stderr,"%p timeout out\n",async->overlapped); */
115 async->timeout = NULL;
116 async_notify(async, STATUS_TIMEOUT);
117 destroy_async(async);
120 struct async *create_async(struct object *obj, struct thread *thread,
123 struct async *async = (struct async *) malloc(sizeof(struct async));
126 set_error(STATUS_NO_MEMORY);
131 async->thread = (struct thread *)grab_object(thread);
132 async->overlapped = overlapped;
136 async->status = STATUS_PENDING;
137 async->timeout = NULL;
142 void async_add_timeout(struct async *async, int timeout)
146 gettimeofday( &async->when, 0 );
147 add_timeout( &async->when, timeout );
148 async->timeout = add_timeout_user( &async->when, async_callback, async );