Commit c6ab933b authored by Bernhard Kölbl's avatar Bernhard Kölbl Committed by Alexandre Julliard

windows.media.speech: Make IAsyncAction concurrent.

parent 1438b1b6
......@@ -40,6 +40,11 @@ struct async_void
IAsyncActionCompletedHandler *handler;
async_action_callback callback;
TP_WORK *async_run_work;
IInspectable *invoker;
CRITICAL_SECTION cs;
AsyncStatus status;
HRESULT hr;
};
......@@ -116,6 +121,7 @@ HRESULT WINAPI async_void_put_Completed( IAsyncAction *iface, IAsyncActionComple
TRACE("iface %p, handler %p.\n", iface, handler);
EnterCriticalSection(&impl->cs);
if (impl->status == Closed)
hr = E_ILLEGAL_METHOD_CALL;
else if (impl->handler != HANDLER_NOT_SET)
......@@ -133,11 +139,15 @@ HRESULT WINAPI async_void_put_Completed( IAsyncAction *iface, IAsyncActionComple
IAsyncAction *action = &impl->IAsyncAction_iface;
AsyncStatus status = impl->status;
impl->handler = NULL; /* Prevent concurrent invoke. */
LeaveCriticalSection(&impl->cs);
IAsyncActionCompletedHandler_Invoke(handler, action, status);
IAsyncActionCompletedHandler_Release(handler);
return S_OK;
}
}
LeaveCriticalSection(&impl->cs);
return hr;
}
......@@ -149,9 +159,11 @@ HRESULT WINAPI async_void_get_Completed( IAsyncAction *iface, IAsyncActionComple
FIXME("iface %p, handler %p semi stub!\n", iface, handler);
EnterCriticalSection(&impl->cs);
if (impl->status == Closed)
hr = E_ILLEGAL_METHOD_CALL;
*handler = (impl->handler != HANDLER_NOT_SET) ? impl->handler : NULL;
LeaveCriticalSection(&impl->cs);
return hr;
}
......@@ -200,9 +212,11 @@ static HRESULT WINAPI async_void_info_get_Status( IAsyncInfo *iface, AsyncStatus
TRACE("iface %p, status %p.\n", iface, status);
EnterCriticalSection(&impl->cs);
if (impl->status == Closed)
hr = E_ILLEGAL_METHOD_CALL;
*status = impl->status;
LeaveCriticalSection(&impl->cs);
return hr;
}
......@@ -214,10 +228,12 @@ static HRESULT WINAPI async_void_info_get_ErrorCode( IAsyncInfo *iface, HRESULT
TRACE("iface %p, error_code %p.\n", iface, error_code);
EnterCriticalSection(&impl->cs);
if (impl->status == Closed)
*error_code = hr = E_ILLEGAL_METHOD_CALL;
else
*error_code = impl->hr;
LeaveCriticalSection(&impl->cs);
return hr;
}
......@@ -229,10 +245,12 @@ static HRESULT WINAPI async_void_info_Cancel( IAsyncInfo *iface )
TRACE("iface %p.\n", iface);
EnterCriticalSection(&impl->cs);
if (impl->status == Closed)
hr = E_ILLEGAL_METHOD_CALL;
else if (impl->status == Started)
impl->status = Canceled;
LeaveCriticalSection(&impl->cs);
return hr;
}
......@@ -244,10 +262,16 @@ static HRESULT WINAPI async_void_info_Close( IAsyncInfo *iface )
TRACE("iface %p.\n", iface);
EnterCriticalSection(&impl->cs);
if (impl->status == Started)
hr = E_ILLEGAL_STATE_CHANGE;
else if (impl->status != Closed)
{
CloseThreadpoolWork(impl->async_run_work);
impl->async_run_work = NULL;
impl->status = Closed;
}
LeaveCriticalSection(&impl->cs);
return hr;
}
......@@ -270,11 +294,40 @@ static const struct IAsyncInfoVtbl async_void_info_vtbl =
async_void_info_Close
};
HRESULT async_action_create( IAsyncAction **out )
static void CALLBACK async_void_run_cb(TP_CALLBACK_INSTANCE *instance, void *data, TP_WORK *work)
{
IAsyncAction *action = data;
struct async_void *impl = impl_from_IAsyncAction(action);
HRESULT hr;
hr = impl->callback(impl->invoker);
EnterCriticalSection(&impl->cs);
if (impl->status < Closed)
impl->status = FAILED(hr) ? Error : Completed;
impl->hr = hr;
if (impl->handler != NULL && impl->handler != HANDLER_NOT_SET)
{
IAsyncActionCompletedHandler*handler = impl->handler;
AsyncStatus status = impl->status;
impl->handler = NULL; /* Prevent concurrent invoke. */
LeaveCriticalSection(&impl->cs);
IAsyncActionCompletedHandler_Invoke(handler, action, status);
IAsyncActionCompletedHandler_Release(handler);
}
else LeaveCriticalSection(&impl->cs);
IAsyncAction_Release(action);
}
HRESULT async_action_create( IInspectable *invoker, async_action_callback callback, IAsyncAction **out )
{
struct async_void *impl;
TRACE("out %p.\n", out);
TRACE("invoker %p, callback %p, out %p.\n", invoker, callback, out);
if (!(impl = calloc(1, sizeof(*impl))))
{
......@@ -287,7 +340,23 @@ HRESULT async_action_create( IAsyncAction **out )
impl->ref = 1;
impl->handler = HANDLER_NOT_SET;
impl->status = Completed;
impl->callback = callback;
impl->status = Started;
if (!(impl->async_run_work = CreateThreadpoolWork(async_void_run_cb, &impl->IAsyncAction_iface, NULL)))
{
free(impl);
return HRESULT_FROM_WIN32(GetLastError());
}
if (invoker) IInspectable_AddRef((impl->invoker = invoker));
InitializeCriticalSection(&impl->cs);
impl->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": async_action.cs");
/* AddRef to keep the obj alive in the callback. */
IAsyncAction_AddRef(&impl->IAsyncAction_iface);
SubmitThreadpoolWork(impl->async_run_work);
*out = &impl->IAsyncAction_iface;
TRACE("created %p\n", *out);
......
......@@ -69,9 +69,10 @@ struct vector_iids
const GUID *view;
};
typedef HRESULT (WINAPI *async_action_callback)( IInspectable *invoker );
typedef HRESULT (WINAPI *async_operation_inspectable_callback)( IInspectable *invoker, IInspectable **result );
HRESULT async_action_create( IAsyncAction **out );
HRESULT async_action_create( IInspectable *invoker, async_action_callback callback, IAsyncAction **out );
HRESULT async_operation_inspectable_create( const GUID *iid, IInspectable *invoker, async_operation_inspectable_callback callback,
IAsyncOperation_IInspectable **out );
......
......@@ -244,10 +244,15 @@ static HRESULT WINAPI session_set_AutoStopSilenceTimeout( ISpeechContinuousRecog
return E_NOTIMPL;
}
static HRESULT WINAPI start_callback( IInspectable *invoker )
{
return S_OK;
}
static HRESULT WINAPI session_StartAsync( ISpeechContinuousRecognitionSession *iface, IAsyncAction **action )
{
FIXME("iface %p, action %p stub!\n", iface, action);
return async_action_create(action);
return async_action_create(NULL, start_callback, action);
}
static HRESULT WINAPI session_StartWithModeAsync( ISpeechContinuousRecognitionSession *iface,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment