mirror of
https://github.com/libretro/RetroArch.git
synced 2026-11-22 01:33:23 -10:00
Screenshots, Bluetooth scans and Wi-Fi tasks were TASK_TYPE_BLOCKING, and the queue refuses any blocking task while another is running. A state save or load is one, so Load State pressed while any of them ran was dropped without a word: nothing happened until it was pressed again after the other task was through. A save's thumbnail, a full-size capture of a 4K output or a Bluetooth scan (up to ten seconds) held it off, which looked like states taking a very long time to load, at random and with every core. Each keeps one at a time among its own kind instead and no longer takes the blocking slot, so only another state task holds a save or load back: - a screenshot that writes a file takes a lock-free claim at the push and gives it back as it finishes; - a Bluetooth scan is refused while another is live, and its window's end moves into the scan from a file static; - a Wi-Fi task is refused while another Wi-Fi task is live. The content_load harness gains a state-load-latency lane: with threaded tasks and compressed states, Load State fired as the hotkey does must reach the core within 30 frames after a save, beside the save's thumbnail, beside a screenshot and after a video reinit. It fails on the old code. The screenshot lanes find their screenshot by its handler, not by its type. bluetooth_scan_test checks that a blocking task is taken during a scan and a second scan is not.
136 lines
4.4 KiB
C
136 lines
4.4 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/>.
|
|
*/
|
|
|
|
#include <stdint.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <compat/strl.h>
|
|
#include <retro_miscellaneous.h>
|
|
#include <string/stdstring.h>
|
|
#include <features/features_cpu.h>
|
|
|
|
#include "tasks_internal.h"
|
|
|
|
#include "../msg_hash.h"
|
|
#include "../bluetooth/bluetooth_driver.h"
|
|
|
|
/* The first step starts discovery; the task is then parked, so other
|
|
* tasks run in the meantime, and looked at every BLUETOOTH_SCAN_POLL_US
|
|
* until the driver says it has found all it will or the window,
|
|
* BLUETOOTH_SCAN_WINDOW_US, is out. The scan used to sleep through the
|
|
* window inside one call, holding the task thread - and every
|
|
* download, thumbnail and sync queued behind it - for ten seconds. A
|
|
* cancel ends the window early. */
|
|
typedef struct
|
|
{
|
|
struct bluetooth_hold *hold;
|
|
retro_time_t deadline; /* the window's end */
|
|
bool begun;
|
|
} task_bluetooth_scan_t;
|
|
|
|
static void task_bluetooth_scan_handler(retro_task_t *task)
|
|
{
|
|
task_bluetooth_scan_t *scan = (task_bluetooth_scan_t*)task->state;
|
|
|
|
if (!scan->begun)
|
|
{
|
|
driver_bluetooth_scan_begin(scan->hold);
|
|
scan->begun = true;
|
|
scan->deadline = cpu_features_get_time_usec()
|
|
+ BLUETOOTH_SCAN_WINDOW_US;
|
|
task_queue_park(task, BLUETOOTH_SCAN_POLL_US);
|
|
return;
|
|
}
|
|
|
|
/* The rest of the window waited out parked, looked at every
|
|
* BLUETOOTH_SCAN_POLL_US where the driver can say it has found all
|
|
* it will. A cancel wakes it and ends the window. */
|
|
if ( !(task_get_flags(task) & RETRO_TASK_FLG_CANCELLED)
|
|
&& !driver_bluetooth_scan_done(scan->hold))
|
|
{
|
|
retro_time_t now = cpu_features_get_time_usec();
|
|
/* the queue runs a parked task up to half a millisecond early:
|
|
* what is left within a millisecond of the end is not waited */
|
|
if (now + 1000 < scan->deadline)
|
|
{
|
|
retro_time_t wait = scan->deadline - now;
|
|
if (wait > BLUETOOTH_SCAN_POLL_US)
|
|
wait = BLUETOOTH_SCAN_POLL_US;
|
|
task_queue_park(task, wait);
|
|
return;
|
|
}
|
|
}
|
|
|
|
driver_bluetooth_scan_end(scan->hold);
|
|
driver_bluetooth_scan_release(scan->hold);
|
|
free(scan);
|
|
task->state = NULL;
|
|
|
|
task_set_progress(task, 100);
|
|
task_free_title(task);
|
|
task_set_title(task, strdup(msg_hash_to_str(MSG_BLUETOOTH_SCAN_COMPLETE)));
|
|
task_set_flags(task, RETRO_TASK_FLG_FINISHED, true);
|
|
}
|
|
|
|
static bool task_bluetooth_scan_finder(retro_task_t *task, void *user_data)
|
|
{
|
|
(void)user_data;
|
|
return task->handler == task_bluetooth_scan_handler
|
|
&& !(task_get_flags(task) & RETRO_TASK_FLG_FINISHED);
|
|
}
|
|
|
|
bool task_push_bluetooth_scan(retro_task_callback_t cb)
|
|
{
|
|
retro_task_t *task = task_init();
|
|
task_bluetooth_scan_t *scan;
|
|
task_finder_data_t find;
|
|
|
|
if (!task)
|
|
return false;
|
|
/* One scan at a time, among scans only: as a blocking task a scan,
|
|
* up to BLUETOOTH_SCAN_WINDOW_US long, turned away every state save
|
|
* and load pushed while it ran - Load State did nothing. */
|
|
find.func = task_bluetooth_scan_finder;
|
|
find.userdata = NULL;
|
|
if (task_queue_find(&find))
|
|
{
|
|
free(task);
|
|
return false;
|
|
}
|
|
if (!(scan = (task_bluetooth_scan_t*)calloc(1, sizeof(*scan))))
|
|
{
|
|
free(task);
|
|
return false;
|
|
}
|
|
|
|
task->type = TASK_TYPE_NONE;
|
|
task->state = scan;
|
|
task->handler = task_bluetooth_scan_handler;
|
|
task->callback = cb;
|
|
task->title = strdup(msg_hash_to_str(
|
|
MSG_SCANNING_BLUETOOTH_DEVICES));
|
|
|
|
/* taken here, on the frontend's thread, where the driver is
|
|
* stopped: the scan's thread cannot find it half gone */
|
|
scan->hold = driver_bluetooth_scan_hold();
|
|
if (task_queue_push(task))
|
|
return true;
|
|
|
|
driver_bluetooth_scan_release(scan->hold);
|
|
free(scan);
|
|
task_free_title(task);
|
|
free(task);
|
|
return false;
|
|
}
|