Added a few stub implementations.
[wine/hacks.git] / include / async.h
blobcb1e67c134831ccab4b46017517a55344bca53fb
1 /*
2 * Structures and static functions for handling asynchronous I/O.
4 * Copyright (C) 2002 Mike McCormack, Martin Wilck
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * This file declares static functions.
23 * It should only be included by those source files that implement async I/O requests.
26 #ifndef __WINE_ASYNC_H
27 #define __WINE_ASYNC_H
29 #include <thread.h>
30 #include <wine/server.h>
31 #include <winternl.h>
33 struct async_private;
35 typedef void (*async_handler)(struct async_private *ovp);
36 typedef void (CALLBACK *async_call_completion_func)(ULONG_PTR data);
37 typedef DWORD (*async_get_count)(const struct async_private *ovp);
38 typedef void (*async_cleanup)(struct async_private *ovp);
40 typedef struct async_ops
42 async_get_count get_count;
43 async_call_completion_func call_completion;
44 async_cleanup cleanup;
45 } async_ops;
47 typedef struct async_private
49 struct async_ops* ops;
50 HANDLE handle;
51 HANDLE event;
52 int fd;
53 async_handler func;
54 int type;
55 IO_STATUS_BLOCK* iosb;
56 struct async_private* next;
57 struct async_private* prev;
58 } async_private;
60 /* All functions declared static for Dll separation purposes */
61 static void CALLBACK call_user_apc( ULONG_PTR arg1, ULONG_PTR arg2, ULONG_PTR arg3 )
63 PAPCFUNC func = (PAPCFUNC)arg1;
64 func( arg2 );
67 inline static void finish_async( async_private *ovp )
69 if (ovp->prev)
70 ovp->prev->next = ovp->next;
71 else
72 NtCurrentTeb()->pending_list = ovp->next;
74 if (ovp->next)
75 ovp->next->prev = ovp->prev;
77 ovp->next = ovp->prev = NULL;
79 close(ovp->fd);
80 if ( ovp->event != INVALID_HANDLE_VALUE )
81 NtSetEvent( ovp->event, NULL );
83 if ( ovp->ops->call_completion )
84 NtQueueApcThread( GetCurrentThread(), call_user_apc,
85 (ULONG_PTR)ovp->ops->call_completion, (ULONG_PTR)ovp, 0 );
86 else
87 ovp->ops->cleanup( ovp );
90 inline static NTSTATUS __register_async( async_private *ovp, const DWORD status )
92 NTSTATUS ret;
94 SERVER_START_REQ( register_async )
96 req->handle = ovp->handle;
97 req->overlapped = ovp;
98 req->type = ovp->type;
99 req->count = ovp->ops->get_count( ovp );
100 req->status = status;
101 ret = wine_server_call( req );
103 SERVER_END_REQ;
105 if (ret) ovp->iosb->u.Status = ret;
107 if ( ovp->iosb->u.Status != STATUS_PENDING )
108 finish_async(ovp);
110 return ret;
113 #define register_old_async(ovp) \
114 __register_async(ovp, ovp->iosb->u.Status);
116 inline static NTSTATUS register_new_async( async_private *ovp )
118 ovp->iosb->u.Status = STATUS_PENDING;
120 ovp->next = NtCurrentTeb()->pending_list;
121 ovp->prev = NULL;
122 if ( ovp->next ) ovp->next->prev = ovp;
123 NtCurrentTeb()->pending_list = ovp;
125 return __register_async( ovp, STATUS_PENDING );
128 inline static NTSTATUS cancel_async( async_private *ovp )
130 /* avoid multiple cancellations */
131 if ( ovp->iosb->u.Status != STATUS_PENDING )
132 return STATUS_SUCCESS;
133 ovp->iosb->u.Status = STATUS_CANCELLED;
134 return __register_async( ovp, STATUS_CANCELLED );
137 #endif /* __WINE_ASYNC_H */