2002-04-05 22:53:57 +00:00
|
|
|
/*
|
|
|
|
* Structures and static functions for handling asynchronous I/O.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Mike McCormack, Martin Wilck
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file declares static functions.
|
|
|
|
* It should only be included by those source files that implement async I/O requests.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __WINE_ASYNC_H
|
|
|
|
#define __WINE_ASYNC_H
|
|
|
|
|
2003-08-28 21:43:34 +00:00
|
|
|
#include <thread.h>
|
2003-09-05 23:08:26 +00:00
|
|
|
#include <ntstatus.h>
|
2003-08-28 21:43:34 +00:00
|
|
|
#include <wine/server.h>
|
|
|
|
#include <winternl.h>
|
2002-04-05 22:53:57 +00:00
|
|
|
|
|
|
|
struct async_private;
|
|
|
|
|
|
|
|
typedef void (*async_handler)(struct async_private *ovp);
|
2002-05-04 18:37:08 +00:00
|
|
|
typedef void (CALLBACK *async_call_completion_func)(ULONG_PTR data);
|
2002-04-05 22:53:57 +00:00
|
|
|
typedef DWORD (*async_get_count)(const struct async_private *ovp);
|
2002-04-14 19:34:57 +00:00
|
|
|
typedef void (*async_cleanup)(struct async_private *ovp);
|
2002-04-05 22:53:57 +00:00
|
|
|
|
|
|
|
typedef struct async_ops
|
|
|
|
{
|
|
|
|
async_get_count get_count;
|
|
|
|
async_call_completion_func call_completion;
|
2002-04-14 19:34:57 +00:00
|
|
|
async_cleanup cleanup;
|
2002-04-05 22:53:57 +00:00
|
|
|
} async_ops;
|
|
|
|
|
|
|
|
typedef struct async_private
|
|
|
|
{
|
2003-06-26 02:08:17 +00:00
|
|
|
struct async_ops* ops;
|
|
|
|
HANDLE handle;
|
|
|
|
HANDLE event;
|
|
|
|
int fd;
|
|
|
|
async_handler func;
|
|
|
|
int type;
|
|
|
|
IO_STATUS_BLOCK* iosb;
|
|
|
|
struct async_private* next;
|
|
|
|
struct async_private* prev;
|
2002-04-05 22:53:57 +00:00
|
|
|
} async_private;
|
|
|
|
|
|
|
|
/* All functions declared static for Dll separation purposes */
|
2003-06-26 02:08:17 +00:00
|
|
|
static void CALLBACK call_user_apc( ULONG_PTR arg1, ULONG_PTR arg2, ULONG_PTR arg3 )
|
|
|
|
{
|
|
|
|
PAPCFUNC func = (PAPCFUNC)arg1;
|
|
|
|
func( arg2 );
|
|
|
|
}
|
2002-04-05 22:53:57 +00:00
|
|
|
|
|
|
|
inline static void finish_async( async_private *ovp )
|
|
|
|
{
|
2003-06-26 02:08:17 +00:00
|
|
|
if (ovp->prev)
|
2002-04-05 22:53:57 +00:00
|
|
|
ovp->prev->next = ovp->next;
|
|
|
|
else
|
|
|
|
NtCurrentTeb()->pending_list = ovp->next;
|
|
|
|
|
2003-06-26 02:08:17 +00:00
|
|
|
if (ovp->next)
|
2002-04-05 22:53:57 +00:00
|
|
|
ovp->next->prev = ovp->prev;
|
|
|
|
|
|
|
|
ovp->next = ovp->prev = NULL;
|
|
|
|
|
2003-12-01 23:01:12 +00:00
|
|
|
wine_server_release_fd( ovp->handle, ovp->fd );
|
2003-06-26 02:08:17 +00:00
|
|
|
if ( ovp->event != INVALID_HANDLE_VALUE )
|
2002-04-05 22:53:57 +00:00
|
|
|
NtSetEvent( ovp->event, NULL );
|
|
|
|
|
2002-04-14 19:34:57 +00:00
|
|
|
if ( ovp->ops->call_completion )
|
2003-06-26 02:08:17 +00:00
|
|
|
NtQueueApcThread( GetCurrentThread(), call_user_apc,
|
|
|
|
(ULONG_PTR)ovp->ops->call_completion, (ULONG_PTR)ovp, 0 );
|
2002-04-14 19:34:57 +00:00
|
|
|
else
|
2003-06-26 02:08:17 +00:00
|
|
|
ovp->ops->cleanup( ovp );
|
2002-04-05 22:53:57 +00:00
|
|
|
}
|
|
|
|
|
2003-06-26 02:08:17 +00:00
|
|
|
inline static NTSTATUS __register_async( async_private *ovp, const DWORD status )
|
2002-04-05 22:53:57 +00:00
|
|
|
{
|
2003-06-26 02:08:17 +00:00
|
|
|
NTSTATUS ret;
|
2002-04-05 22:53:57 +00:00
|
|
|
|
|
|
|
SERVER_START_REQ( register_async )
|
|
|
|
{
|
|
|
|
req->handle = ovp->handle;
|
|
|
|
req->overlapped = ovp;
|
|
|
|
req->type = ovp->type;
|
|
|
|
req->count = ovp->ops->get_count( ovp );
|
|
|
|
req->status = status;
|
|
|
|
ret = wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
2003-06-26 02:08:17 +00:00
|
|
|
if (ret) ovp->iosb->u.Status = ret;
|
2002-04-14 19:34:57 +00:00
|
|
|
|
2003-06-26 02:08:17 +00:00
|
|
|
if ( ovp->iosb->u.Status != STATUS_PENDING )
|
|
|
|
finish_async(ovp);
|
2002-04-05 22:53:57 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-08-17 23:37:55 +00:00
|
|
|
inline static NTSTATUS register_old_async( async_private *ovp )
|
|
|
|
{
|
|
|
|
return __register_async(ovp, ovp->iosb->u.Status);
|
|
|
|
}
|
2002-04-05 22:53:57 +00:00
|
|
|
|
2003-06-26 02:08:17 +00:00
|
|
|
inline static NTSTATUS register_new_async( async_private *ovp )
|
2002-04-05 22:53:57 +00:00
|
|
|
{
|
2003-06-26 02:08:17 +00:00
|
|
|
ovp->iosb->u.Status = STATUS_PENDING;
|
2002-04-05 22:53:57 +00:00
|
|
|
|
|
|
|
ovp->next = NtCurrentTeb()->pending_list;
|
|
|
|
ovp->prev = NULL;
|
|
|
|
if ( ovp->next ) ovp->next->prev = ovp;
|
|
|
|
NtCurrentTeb()->pending_list = ovp;
|
|
|
|
|
|
|
|
return __register_async( ovp, STATUS_PENDING );
|
|
|
|
}
|
|
|
|
|
2003-06-26 02:08:17 +00:00
|
|
|
inline static NTSTATUS cancel_async( async_private *ovp )
|
2002-04-05 22:53:57 +00:00
|
|
|
{
|
|
|
|
/* avoid multiple cancellations */
|
2003-06-26 02:08:17 +00:00
|
|
|
if ( ovp->iosb->u.Status != STATUS_PENDING )
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
ovp->iosb->u.Status = STATUS_CANCELLED;
|
|
|
|
return __register_async( ovp, STATUS_CANCELLED );
|
2002-04-05 22:53:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* __WINE_ASYNC_H */
|