/* Thread: player */ void worker_execute(void (*cb)(void *), void *cb_arg, size_t arg_size, int delay) { struct worker_arg *cmdarg; void *argcpy; DPRINTF(E_DBG, L_MAIN, "Got worker execute request\n"); cmdarg = calloc(1, sizeof(struct worker_arg)); if (!cmdarg) { DPRINTF(E_LOG, L_MAIN, "Could not allocate worker_arg\n"); return; } argcpy = malloc(arg_size); if (!argcpy) { DPRINTF(E_LOG, L_MAIN, "Out of memory\n"); free(cmdarg); return; } memcpy(argcpy, cb_arg, arg_size); cmdarg->cb = cb; cmdarg->cb_arg = argcpy; cmdarg->delay = delay; commands_exec_async(cmdbase, execute, cmdarg); }
void filescanner_trigger_fullrescan(void) { if (scanning) { DPRINTF(E_INFO, L_SCAN, "Scan already running, ignoring request to trigger a new init scan\n"); return; } commands_exec_async(cmdbase, filescanner_fullrescan, NULL); }
void library_fullrescan() { if (scanning) { DPRINTF(E_INFO, L_LIB, "Scan already running, ignoring request to trigger a new full rescan\n"); return; } scanning = true; // TODO Guard "scanning" with a mutex commands_exec_async(cmdbase, fullrescan, NULL); }
/* * Trigger for sending the DATABASE event * * Needs to be called, if an update to the database (library tables) occurred. The DATABASE event * is emitted with the delay 'library_update_wait'. It is safe to call this function from any thread. */ void library_update_trigger(short update_events) { short *events; int ret; pthread_t current_thread = pthread_self(); if (pthread_equal(current_thread, tid_library)) { // We are already running in the library thread, it is safe to directly call update_trigger update_trigger(&update_events, &ret); } else { events = malloc(sizeof(short)); *events = update_events; commands_exec_async(cmdbase, update_trigger, events); } }
/* * Execute the function 'func' with the given argument 'arg' in the library thread. * * The pointer passed as argument is freed in the library thread after func returned. * * @param func The function to be executed * @param arg Argument passed to func * @return 0 if triggering the function execution succeeded, -1 on failure. */ int library_exec_async(command_function func, void *arg) { return commands_exec_async(cmdbase, func, arg); }