Calculate the timeout time once when the async is created.

This commit is contained in:
Mike McCormack 2001-01-07 21:46:17 +00:00 committed by Alexandre Julliard
parent c6316bc4ac
commit 21ea8a9107
1 changed files with 27 additions and 6 deletions

View File

@ -47,6 +47,7 @@ struct async
int count; int count;
int eventmask; int eventmask;
struct async *next; struct async *next;
struct timeval tv;
struct timeout_user *timeout; struct timeout_user *timeout;
struct wait_queue_entry wait; struct wait_queue_entry wait;
void *buffer; void *buffer;
@ -61,6 +62,7 @@ static int async_get_poll_events( struct object *obj );
static int async_get_fd( struct object *obj ); static int async_get_fd( struct object *obj );
static int async_get_info( struct object *obj, struct get_file_info_request *req ); static int async_get_info( struct object *obj, struct get_file_info_request *req );
static void async_poll_event( struct object *obj, int event ); static void async_poll_event( struct object *obj, int event );
static void overlapped_timeout (void *private);
static const struct object_ops async_ops = static const struct object_ops async_ops =
{ {
@ -95,8 +97,10 @@ static void async_destroy( struct object *obj )
assert( obj->ops == &async_ops ); assert( obj->ops == &async_ops );
if(ov->timeout) if(ov->timeout)
{
remove_timeout_user(ov->timeout); remove_timeout_user(ov->timeout);
ov->timeout = NULL; ov->timeout = NULL;
}
} }
struct async *get_async_obj( struct process *process, handle_t handle, unsigned int access ) struct async *get_async_obj( struct process *process, handle_t handle, unsigned int access )
@ -198,10 +202,17 @@ DECL_HANDLER(create_async)
ov->file = obj; ov->file = obj;
ov->buffer = req->buffer; ov->buffer = req->buffer;
ov->count = req->count; ov->count = req->count;
ov->tv.tv_sec = 0;
ov->tv.tv_usec = 0;
/* FIXME: this should be a function pointer */ /* FIXME: this should be a function pointer */
serial_async_setup(obj,ov); serial_async_setup(obj,ov);
if( ov->tv.tv_sec || ov->tv.tv_usec )
{
ov->timeout = add_timeout_user(&ov->tv, overlapped_timeout, ov);
}
ov->obj.ops->add_queue(&ov->obj,&ov->wait); ov->obj.ops->add_queue(&ov->obj,&ov->wait);
req->ov_handle = alloc_handle( current->process, ov, GENERIC_READ|GENERIC_WRITE, 0 ); req->ov_handle = alloc_handle( current->process, ov, GENERIC_READ|GENERIC_WRITE, 0 );
@ -216,6 +227,11 @@ static void async_poll_event( struct object *obj, int event )
/* queue an APC in the client thread to do our dirty work */ /* queue an APC in the client thread to do our dirty work */
ov->obj.ops->remove_queue(&ov->obj,&ov->wait); ov->obj.ops->remove_queue(&ov->obj,&ov->wait);
if(ov->timeout)
{
remove_timeout_user(ov->timeout);
ov->timeout = NULL;
}
/* FIXME: this should be a function pointer */ /* FIXME: this should be a function pointer */
event = serial_async_poll_event(obj,event); event = serial_async_poll_event(obj,event);
@ -230,6 +246,7 @@ static void overlapped_timeout (void *private)
struct async *ov = (struct async *) private; struct async *ov = (struct async *) private;
ov->obj.ops->remove_queue(&ov->obj,&ov->wait); ov->obj.ops->remove_queue(&ov->obj,&ov->wait);
ov->timeout = NULL;
thread_queue_apc(ov->thread, NULL, ov->func, APC_ASYNC, 1, 3, thread_queue_apc(ov->thread, NULL, ov->func, APC_ASYNC, 1, 3,
ov->client_overlapped,ov->buffer, 0); ov->client_overlapped,ov->buffer, 0);
@ -237,11 +254,11 @@ static void overlapped_timeout (void *private)
void async_add_timeout(struct async *ov, int timeout) void async_add_timeout(struct async *ov, int timeout)
{ {
struct timeval tv; if(timeout)
{
gettimeofday(&tv,0); gettimeofday(&ov->tv,0);
add_timeout(&tv,timeout); add_timeout(&ov->tv,timeout);
ov->timeout = add_timeout_user(&tv, overlapped_timeout, ov); }
} }
DECL_HANDLER(async_result) DECL_HANDLER(async_result)
@ -254,6 +271,10 @@ DECL_HANDLER(async_result)
if(ov->result == STATUS_PENDING) if(ov->result == STATUS_PENDING)
{ {
ov->obj.ops->add_queue(&ov->obj,&ov->wait); ov->obj.ops->add_queue(&ov->obj,&ov->wait);
if( (ov->tv.tv_sec || ov->tv.tv_usec) && !ov->timeout)
{
ov->timeout = add_timeout_user(&ov->tv, overlapped_timeout, ov);
}
} }
release_object( ov ); release_object( ov );
} }