Files
RetroArch/tasks/task_notify.h
Rob Loach 62d5954fbc mcp: answer tools once their work is through
A tool whose work runs over later frames answers when that work is
through, with what came of it, or with its name, ERROR and the reason:
LOAD_CONTENT, START_CORE, CLOSE_CONTENT and UNLOAD_CORE once the load or
close ends; LOAD_STATE_SLOT and SAVE_STATE_SLOT once the state is
applied or written; PLAY_REPLAY_SLOT, RECORD_REPLAY, SEEK_REPLAY and the
replay checkpoint tools once the replay has started or the seek or
checkpoint has run; SET_SHADER once the preset has compiled; AI_SERVICE
with the service's text. A line-based interface keeps the answers it
had.

The waiting is one shape, task_notify_t (tasks/task_notify.h), held by
the work's owner: the content load, the save and load tasks, the movie
tasks, the deferred shader load and the translation service. State and
replay work a command starts runs from a main-thread task, outside the
core's own input poll. The command interfaces outlive a content load,
remade only when their settings change, and what arrives during a load
waits for it.

samples/tasks/content_load gains lanes for the state-slot, replay, seek and
content replies; samples/network/mcp_server follows.

Closes #19702
2026-10-05 11:33:27 +02:00

58 lines
1.7 KiB
C

/* RetroArch - A frontend for libretro.
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __TASK_NOTIFY_H
#define __TASK_NOTIFY_H
#include <stddef.h>
#include <retro_common_api.h>
#include <retro_inline.h>
#include <queues/task_queue.h>
RETRO_BEGIN_DECLS
/* A caller waiting to be told that some work is through, as a task
* callback is: once, with error set if it failed. */
typedef struct task_notify
{
retro_task_callback_t cb;
void *user_data;
} task_notify_t;
/* Tells the caller waiting on @n, if any. Cleared first, so that the
* callback may wait on @n again. */
static INLINE void task_notify_fire(task_notify_t *n, void *task_data,
const char *error)
{
retro_task_callback_t cb = n->cb;
n->cb = NULL;
if (cb)
cb(NULL, task_data, n->user_data, error);
}
/* Has @cb wait on @n; a caller already waiting is told it was
* superseded. */
static INLINE void task_notify_set(task_notify_t *n,
retro_task_callback_t cb, void *user_data)
{
task_notify_fire(n, NULL, "Superseded by another request.");
n->cb = cb;
n->user_data = user_data;
}
RETRO_END_DECLS
#endif