Add rarch_main_data_pending_scan_finished and other mechanisms

so that the call to menu_environment_cb gets made on main thread
This commit is contained in:
twinaphex 2015-07-09 02:31:46 +02:00
parent 12ca517cf7
commit 1c406bc098
4 changed files with 58 additions and 27 deletions

View File

@ -66,7 +66,10 @@ static void adapter_thread(void *data)
{ {
uint8_t send_command_buf[4096]; uint8_t send_command_buf[4096];
struct libusb_adapter *adapter = (struct libusb_adapter*)data; struct libusb_adapter *adapter = (struct libusb_adapter*)data;
libusb_hid_t *hid = adapter->hid; libusb_hid_t *hid = adapter ? adapter->hid : NULL;
if (!adapter)
return;
while (!adapter->quitting) while (!adapter->quitting)
{ {
@ -100,21 +103,21 @@ static void libusb_hid_device_send_control(void *data,
{ {
struct libusb_adapter *adapter = (struct libusb_adapter*)data; struct libusb_adapter *adapter = (struct libusb_adapter*)data;
if (adapter) if (!adapter)
{ return;
slock_lock(adapter->send_control_lock);
if (fifo_write_avail(adapter->send_control_buffer) >= size + sizeof(size)) slock_lock(adapter->send_control_lock);
{
fifo_write(adapter->send_control_buffer, &size, sizeof(size)); if (fifo_write_avail(adapter->send_control_buffer) >= size + sizeof(size))
fifo_write(adapter->send_control_buffer, data_buf, size); {
} fifo_write(adapter->send_control_buffer, &size, sizeof(size));
else fifo_write(adapter->send_control_buffer, data_buf, size);
{
RARCH_WARN("adapter write buffer is full, cannot write send control\n");
}
slock_unlock(adapter->send_control_lock);
} }
else
{
RARCH_WARN("adapter write buffer is full, cannot write send control\n");
}
slock_unlock(adapter->send_control_lock);
} }
static void libusb_hid_device_add_autodetect(unsigned idx, static void libusb_hid_device_add_autodetect(unsigned idx,
@ -142,7 +145,7 @@ static void libusb_get_description(struct libusb_device *device,
libusb_get_config_descriptor(device, 0, &config); libusb_get_config_descriptor(device, 0, &config);
for(i=0; i < (int)config->bNumInterfaces; i++) for (i = 0; i < (int)config->bNumInterfaces; i++)
{ {
const struct libusb_interface *inter = &config->interface[i]; const struct libusb_interface *inter = &config->interface[i];
@ -189,13 +192,16 @@ static int add_adapter(void *data, struct libusb_device *dev)
{ {
int rc; int rc;
struct libusb_device_descriptor desc; struct libusb_device_descriptor desc;
const char *device_name = NULL;
struct libusb_adapter *old_head = NULL; struct libusb_adapter *old_head = NULL;
struct libusb_hid *hid = (struct libusb_hid*)data; struct libusb_hid *hid = (struct libusb_hid*)data;
const char *device_name = NULL;
struct libusb_adapter *adapter = (struct libusb_adapter*) struct libusb_adapter *adapter = (struct libusb_adapter*)
calloc(1, sizeof(struct libusb_adapter)); calloc(1, sizeof(struct libusb_adapter));
if (!adapter || !hid) if (!adapter)
return -1;
if (!hid)
{ {
free(adapter); free(adapter);
RARCH_ERR("Allocation of adapter failed.\n"); RARCH_ERR("Allocation of adapter failed.\n");
@ -264,7 +270,8 @@ static int add_adapter(void *data, struct libusb_device *dev)
} }
adapter->slot = pad_connection_pad_init(hid->slots, adapter->slot = pad_connection_pad_init(hid->slots,
device_name, desc.idVendor, desc.idProduct, adapter, &libusb_hid_device_send_control); device_name, desc.idVendor, desc.idProduct,
adapter, &libusb_hid_device_send_control);
if (adapter->slot == -1) if (adapter->slot == -1)
goto error; goto error;
@ -433,7 +440,8 @@ static bool libusb_hid_joypad_rumble(void *data, unsigned pad,
return pad_connection_rumble(&hid->slots[pad], pad, effect, strength); return pad_connection_rumble(&hid->slots[pad], pad, effect, strength);
} }
static int16_t libusb_hid_joypad_axis(void *data, unsigned port, uint32_t joyaxis) static int16_t libusb_hid_joypad_axis(void *data,
unsigned port, uint32_t joyaxis)
{ {
libusb_hid_t *hid = (libusb_hid_t*)data; libusb_hid_t *hid = (libusb_hid_t*)data;
int16_t val = 0; int16_t val = 0;
@ -443,14 +451,16 @@ static int16_t libusb_hid_joypad_axis(void *data, unsigned port, uint32_t joyaxi
if (AXIS_NEG_GET(joyaxis) < 4) if (AXIS_NEG_GET(joyaxis) < 4)
{ {
val = pad_connection_get_axis(&hid->slots[port], port, AXIS_NEG_GET(joyaxis)); val = pad_connection_get_axis(&hid->slots[port],
port, AXIS_NEG_GET(joyaxis));
if (val >= 0) if (val >= 0)
val = 0; val = 0;
} }
else if(AXIS_POS_GET(joyaxis) < 4) else if(AXIS_POS_GET(joyaxis) < 4)
{ {
val = pad_connection_get_axis(&hid->slots[port], port, AXIS_POS_GET(joyaxis)); val = pad_connection_get_axis(&hid->slots[port],
port, AXIS_POS_GET(joyaxis));
if (val <= 0) if (val <= 0)
val = 0; val = 0;
@ -465,7 +475,8 @@ static void libusb_hid_free(void *data)
while(adapters.next) while(adapters.next)
if (remove_adapter(hid, adapters.next->device) == -1) if (remove_adapter(hid, adapters.next->device) == -1)
RARCH_ERR("could not remove device %p\n", adapters.next->device); RARCH_ERR("could not remove device %p\n",
adapters.next->device);
if (hid->poll_thread) if (hid->poll_thread)
{ {
@ -489,7 +500,8 @@ static void poll_thread(void *data)
while (!hid->quit) while (!hid->quit)
{ {
struct timeval timeout = {0}; struct timeval timeout = {0};
libusb_handle_events_timeout_completed(NULL, &timeout, &hid->quit); libusb_handle_events_timeout_completed(NULL,
&timeout, &hid->quit);
} }
} }

View File

@ -266,6 +266,13 @@ void rarch_main_data_iterate(void)
rarch_main_data_nbio_image_upload_iterate(false); rarch_main_data_nbio_image_upload_iterate(false);
#endif #endif
#ifdef HAVE_MENU
#ifdef HAVE_LIBRETRODB
if (rarch_main_data_db_pending_scan_finished())
menu_environment_cb(MENU_ENVIRON_RESET_HORIZONTAL_LIST, NULL);
#endif
#endif
if (data_runloop_msg[0] != '\0') if (data_runloop_msg[0] != '\0')
{ {
rarch_main_msg_queue_push(data_runloop_msg, 1, 10, true); rarch_main_msg_queue_push(data_runloop_msg, 1, 10, true);

View File

@ -52,6 +52,17 @@ typedef struct db_handle
static db_handle_t *db_ptr; static db_handle_t *db_ptr;
static bool pending_scan_finished;
bool rarch_main_data_db_pending_scan_finished(void)
{
if (!pending_scan_finished)
return false;
pending_scan_finished = false;
return true;
}
#ifdef HAVE_LIBRETRODB #ifdef HAVE_LIBRETRODB
#ifdef HAVE_ZLIB #ifdef HAVE_ZLIB
@ -434,9 +445,7 @@ void rarch_main_data_db_iterate(bool is_thread)
else else
{ {
rarch_main_msg_queue_push_new(MSG_SCANNING_OF_DIRECTORY_FINISHED, 0, 180, true); rarch_main_msg_queue_push_new(MSG_SCANNING_OF_DIRECTORY_FINISHED, 0, 180, true);
#ifdef HAVE_MENU pending_scan_finished = true;
menu_environment_cb(MENU_ENVIRON_RESET_HORIZONTAL_LIST, NULL);
#endif
db->status = DATABASE_STATUS_FREE; db->status = DATABASE_STATUS_FREE;
} }
break; break;
@ -498,7 +507,8 @@ void rarch_main_data_db_uninit(void)
void rarch_main_data_db_init(void) void rarch_main_data_db_init(void)
{ {
db_ptr = (db_handle_t*)calloc(1, sizeof(*db_ptr)); db_ptr = (db_handle_t*)calloc(1, sizeof(*db_ptr));
pending_scan_finished = false;
} }
bool rarch_main_data_db_is_active(void) bool rarch_main_data_db_is_active(void)

View File

@ -77,6 +77,8 @@ void rarch_main_data_nbio_image_upload_iterate(bool is_thread);
#ifdef HAVE_LIBRETRODB #ifdef HAVE_LIBRETRODB
#ifdef HAVE_MENU #ifdef HAVE_MENU
void rarch_main_data_db_iterate(bool is_thread); void rarch_main_data_db_iterate(bool is_thread);
bool rarch_main_data_db_pending_scan_finished(void);
#endif #endif
void rarch_main_data_db_init_msg_queue(void); void rarch_main_data_db_init_msg_queue(void);