Commit 6effc986 authored by David Reid's avatar David Reid

Move async notifications into the main library.

parent 2bd5ddd6
...@@ -5845,6 +5845,53 @@ MA_API ma_result ma_fence_wait(ma_fence* pFence); /* Wait for counter to r ...@@ -5845,6 +5845,53 @@ MA_API ma_result ma_fence_wait(ma_fence* pFence); /* Wait for counter to r
/*
Notification callback for asynchronous operations.
*/
typedef void ma_async_notification;
typedef struct
{
void (* onSignal)(ma_async_notification* pNotification);
} ma_async_notification_callbacks;
MA_API ma_result ma_async_notification_signal(ma_async_notification* pNotification);
/*
Simple polling notification.
This just sets a variable when the notification has been signalled which is then polled with ma_async_notification_poll_is_signalled()
*/
typedef struct
{
ma_async_notification_callbacks cb;
ma_bool32 signalled;
} ma_async_notification_poll;
MA_API ma_result ma_async_notification_poll_init(ma_async_notification_poll* pNotificationPoll);
MA_API ma_bool32 ma_async_notification_poll_is_signalled(const ma_async_notification_poll* pNotificationPoll);
/*
Event Notification
This uses an ma_event. If threading is disabled (MA_NO_THREADING), initialization will fail.
*/
typedef struct
{
ma_async_notification_callbacks cb;
#ifndef MA_NO_THREADING
ma_event e;
#endif
} ma_async_notification_event;
MA_API ma_result ma_async_notification_event_init(ma_async_notification_event* pNotificationEvent);
MA_API ma_result ma_async_notification_event_uninit(ma_async_notification_event* pNotificationEvent);
MA_API ma_result ma_async_notification_event_wait(ma_async_notification_event* pNotificationEvent);
MA_API ma_result ma_async_notification_event_signal(ma_async_notification_event* pNotificationEvent);
/************************************************************************************************************************************************************ /************************************************************************************************************************************************************
...@@ -11655,6 +11702,135 @@ MA_API ma_result ma_fence_wait(ma_fence* pFence) ...@@ -11655,6 +11702,135 @@ MA_API ma_result ma_fence_wait(ma_fence* pFence)
} }
MA_API ma_result ma_async_notification_signal(ma_async_notification* pNotification)
{
ma_async_notification_callbacks* pNotificationCallbacks = (ma_async_notification_callbacks*)pNotification;
if (pNotification == NULL) {
return MA_INVALID_ARGS;
}
if (pNotificationCallbacks->onSignal == NULL) {
return MA_NOT_IMPLEMENTED;
}
pNotificationCallbacks->onSignal(pNotification);
return MA_INVALID_ARGS;
}
static void ma_async_notification_poll__on_signal(ma_async_notification* pNotification)
{
((ma_async_notification_poll*)pNotification)->signalled = MA_TRUE;
}
MA_API ma_result ma_async_notification_poll_init(ma_async_notification_poll* pNotificationPoll)
{
if (pNotificationPoll == NULL) {
return MA_INVALID_ARGS;
}
pNotificationPoll->cb.onSignal = ma_async_notification_poll__on_signal;
pNotificationPoll->signalled = MA_FALSE;
return MA_SUCCESS;
}
MA_API ma_bool32 ma_async_notification_poll_is_signalled(const ma_async_notification_poll* pNotificationPoll)
{
if (pNotificationPoll == NULL) {
return MA_FALSE;
}
return pNotificationPoll->signalled;
}
static void ma_async_notification_event__on_signal(ma_async_notification* pNotification)
{
ma_async_notification_event_signal((ma_async_notification_event*)pNotification);
}
MA_API ma_result ma_async_notification_event_init(ma_async_notification_event* pNotificationEvent)
{
if (pNotificationEvent == NULL) {
return MA_INVALID_ARGS;
}
pNotificationEvent->cb.onSignal = ma_async_notification_event__on_signal;
#ifndef MA_NO_THREADING
{
ma_result result;
result = ma_event_init(&pNotificationEvent->e);
if (result != MA_SUCCESS) {
return result;
}
return MA_SUCCESS;
}
#else
{
return MA_NOT_IMPLEMENTED; /* Threading is disabled. */
}
#endif
}
MA_API ma_result ma_async_notification_event_uninit(ma_async_notification_event* pNotificationEvent)
{
if (pNotificationEvent == NULL) {
return MA_INVALID_ARGS;
}
#ifndef MA_NO_THREADING
{
ma_event_uninit(&pNotificationEvent->e);
return MA_SUCCESS;
}
#else
{
return MA_NOT_IMPLEMENTED; /* Threading is disabled. */
}
#endif
}
MA_API ma_result ma_async_notification_event_wait(ma_async_notification_event* pNotificationEvent)
{
if (pNotificationEvent == NULL) {
return MA_INVALID_ARGS;
}
#ifndef MA_NO_THREADING
{
return ma_event_wait(&pNotificationEvent->e);
}
#else
{
return MA_NOT_IMPLEMENTED; /* Threading is disabled. */
}
#endif
}
MA_API ma_result ma_async_notification_event_signal(ma_async_notification_event* pNotificationEvent)
{
if (pNotificationEvent == NULL) {
return MA_INVALID_ARGS;
}
#ifndef MA_NO_THREADING
{
return ma_event_signal(&pNotificationEvent->e);
}
#else
{
return MA_NOT_IMPLEMENTED; /* Threading is disabled. */
}
#endif
}
/************************************************************************************************************************************************************ /************************************************************************************************************************************************************
************************************************************************************************************************************************************* *************************************************************************************************************************************************************
...@@ -1102,49 +1102,6 @@ typedef struct ma_resource_manager_data_source ma_resource_manager_data_sou ...@@ -1102,49 +1102,6 @@ typedef struct ma_resource_manager_data_source ma_resource_manager_data_sou
/*
Notification callback for asynchronous operations.
*/
typedef void ma_async_notification;
typedef struct
{
void (* onSignal)(ma_async_notification* pNotification);
} ma_async_notification_callbacks;
MA_API ma_result ma_async_notification_signal(ma_async_notification* pNotification);
/*
Simple polling notification.
This just sets a variable when the notification has been signalled which is then polled with ma_async_notification_poll_is_signalled()
*/
typedef struct
{
ma_async_notification_callbacks cb;
ma_bool32 signalled;
} ma_async_notification_poll;
MA_API ma_result ma_async_notification_poll_init(ma_async_notification_poll* pNotificationPoll);
MA_API ma_bool32 ma_async_notification_poll_is_signalled(const ma_async_notification_poll* pNotificationPoll);
/*
Event Notification
*/
typedef struct
{
ma_async_notification_callbacks cb;
ma_event e;
} ma_async_notification_event;
MA_API ma_result ma_async_notification_event_init(ma_async_notification_event* pNotificationEvent);
MA_API ma_result ma_async_notification_event_uninit(ma_async_notification_event* pNotificationEvent);
MA_API ma_result ma_async_notification_event_wait(ma_async_notification_event* pNotificationEvent);
MA_API ma_result ma_async_notification_event_signal(ma_async_notification_event* pNotificationEvent);
/* /*
Pipeline notifications used by the resource manager. Made up of both an async notification and a fence, both of which are optionally. Pipeline notifications used by the resource manager. Made up of both an async notification and a fence, both of which are optionally.
*/ */
...@@ -4561,103 +4518,6 @@ MA_API void ma_splitter_node_uninit(ma_splitter_node* pSplitterNode, const ma_al ...@@ -4561,103 +4518,6 @@ MA_API void ma_splitter_node_uninit(ma_splitter_node* pSplitterNode, const ma_al
#define MA_RESOURCE_MANAGER_PAGE_SIZE_IN_MILLISECONDS 1000 #define MA_RESOURCE_MANAGER_PAGE_SIZE_IN_MILLISECONDS 1000
#endif #endif
MA_API ma_result ma_async_notification_signal(ma_async_notification* pNotification)
{
ma_async_notification_callbacks* pNotificationCallbacks = (ma_async_notification_callbacks*)pNotification;
if (pNotification == NULL) {
return MA_INVALID_ARGS;
}
if (pNotificationCallbacks->onSignal == NULL) {
return MA_NOT_IMPLEMENTED;
}
pNotificationCallbacks->onSignal(pNotification);
return MA_INVALID_ARGS;
}
static void ma_async_notification_poll__on_signal(ma_async_notification* pNotification)
{
((ma_async_notification_poll*)pNotification)->signalled = MA_TRUE;
}
MA_API ma_result ma_async_notification_poll_init(ma_async_notification_poll* pNotificationPoll)
{
if (pNotificationPoll == NULL) {
return MA_INVALID_ARGS;
}
pNotificationPoll->cb.onSignal = ma_async_notification_poll__on_signal;
pNotificationPoll->signalled = MA_FALSE;
return MA_SUCCESS;
}
MA_API ma_bool32 ma_async_notification_poll_is_signalled(const ma_async_notification_poll* pNotificationPoll)
{
if (pNotificationPoll == NULL) {
return MA_FALSE;
}
return pNotificationPoll->signalled;
}
static void ma_async_notification_event__on_signal(ma_async_notification* pNotification)
{
ma_async_notification_event_signal((ma_async_notification_event*)pNotification);
}
MA_API ma_result ma_async_notification_event_init(ma_async_notification_event* pNotificationEvent)
{
ma_result result;
if (pNotificationEvent == NULL) {
return MA_INVALID_ARGS;
}
pNotificationEvent->cb.onSignal = ma_async_notification_event__on_signal;
result = ma_event_init(&pNotificationEvent->e);
if (result != MA_SUCCESS) {
return result;
}
return MA_SUCCESS;
}
MA_API ma_result ma_async_notification_event_uninit(ma_async_notification_event* pNotificationEvent)
{
if (pNotificationEvent == NULL) {
return MA_INVALID_ARGS;
}
ma_event_uninit(&pNotificationEvent->e);
return MA_SUCCESS;
}
MA_API ma_result ma_async_notification_event_wait(ma_async_notification_event* pNotificationEvent)
{
if (pNotificationEvent == NULL) {
return MA_INVALID_ARGS;
}
return ma_event_wait(&pNotificationEvent->e);
}
MA_API ma_result ma_async_notification_event_signal(ma_async_notification_event* pNotificationEvent)
{
if (pNotificationEvent == NULL) {
return MA_INVALID_ARGS;
}
return ma_event_signal(&pNotificationEvent->e);
}
MA_API ma_resource_manager_pipeline_notifications ma_resource_manager_pipeline_notifications_init(void) MA_API ma_resource_manager_pipeline_notifications ma_resource_manager_pipeline_notifications_init(void)
{ {
ma_resource_manager_pipeline_notifications notifications; ma_resource_manager_pipeline_notifications notifications;
......
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