void cos_init(void *arg) { int c, accept_fd, ret; long eid; char *init_str = cos_init_args(), *create_str; int lag, nthds, prio; cvect_init_static(&evts); cvect_init_static(&tor_from); cvect_init_static(&tor_to); lock_static_init(&sc_lock); sscanf(init_str, "%d:%d:%d", &lag, &nthds, &prio); printc("lag: %d, nthds:%d, prio:%d\n", lag, nthds, prio); create_str = strstr(init_str, "/"); assert(create_str); eid = evt_get(); ret = c = from_tsplit(cos_spd_id(), td_root, create_str, strlen(create_str), TOR_ALL, eid); if (ret <= td_root) BUG(); accept_fd = c; evt_add(c, eid); /* event loop... */ while (1) { struct tor_conn tc; int t; long evt; memset(&tc, 0, sizeof(struct tor_conn)); evt = evt_wait_all(); t = evt_torrent(evt); if (t > 0) { tc.feid = evt; tc.from = t; if (t == accept_fd) { tc.to = 0; accept_new(accept_fd); } else { tc.to = tor_get_to(t, &tc.teid); assert(tc.to > 0); from_data_new(&tc); } } else { t *= -1; tc.teid = evt; tc.to = t; tc.from = tor_get_from(t, &tc.feid); assert(tc.from > 0); to_data_new(&tc); } cos_mpd_update(); } }
void cos_init(void *arg) { int c, accept_fd, ret; long eid; cvect_init_static(&evts); cvect_init_static(&tor_from); cvect_init_static(&tor_to); eid = evt_get(); c = net_create_tcp_connection(cos_spd_id(), cos_get_thd_id(), eid); if (c < 0) BUG(); ret = net_bind(cos_spd_id(), c, 0, 200); if (ret < 0) BUG(); ret = net_listen(cos_spd_id(), c, 255); if (ret < 0) BUG(); accept_fd = c; evt_add(c, eid); while (1) { struct tor_conn tc; int t; long evt; memset(&tc, 0, sizeof(struct tor_conn)); printc("waiting...\n"); evt = evt_grp_wait(cos_spd_id()); t = evt_torrent(evt); if (t > 0) { tc.feid = evt; tc.from = t; if (t == accept_fd) { tc.to = 0; printc("accepting event.\n"); accept_new(accept_fd); } else { tc.to = tor_get_to(t); assert(tc.to > 0); printc("data from net.\n"); from_data_new(&tc); } } else { t *= -1; tc.teid = evt; tc.to = t; tc.from = tor_get_from(t); assert(tc.from > 0); printc("data from torrent.\n"); to_data_new(&tc); } cos_mpd_update(); } }
static int init(void) { int cnt = 0; #ifdef LWIP_STATS int stats_cnt = 0; #endif lock_static_init(&net_lock); /* printc("netlock id %d\n", net_lock.lock_id); */ NET_LOCK_TAKE(); torlib_init(); net_conn_init(); cos_net_create_netif_thd(); init_lwip(); NET_LOCK_RELEASE(); /* Start the tcp timer */ while (1) { /* Sleep for a quarter of seconds as prescribed by lwip */ NET_LOCK_TAKE(); if (++cnt == 4) { #ifdef TEST_TIMING timing_output(); #endif } #ifdef LWIP_STATS if (++stats_cnt == 20) { stats_cnt = 0; stats_display(); } #endif tcp_tmr(); NET_LOCK_RELEASE(); timed_event_block(cos_spd_id(), 25); /* expressed in ticks currently */ /* printc("use timer to tcp debug thread here...\n"); */ cos_mpd_update(); } prints("net: Error -- returning from init!!!"); BUG(); return 0; }
static void start_timer_thread(void) { spdid_t spdid = cos_spd_id(); unsigned int tick_freq; INIT_LIST(&events, next, prev); events.thread_id = 0; INIT_LIST(&periodic, next, prev); periodic.thread_id = 0; cos_vect_init_static(&thd_evts); cos_vect_init_static(&thd_periodic); sched_timeout_thd(spdid); tick_freq = sched_tick_freq(); assert(tick_freq == 100); ticks = sched_timestamp(); /* currently timeouts are expressed in ticks, so we don't need this */ // usec_per_tick = USEC_PER_SEC/tick_freq; cyc_per_tick = sched_cyc_per_tick(); // printc("cyc_per_tick = %lld\n", cyc_per_tick); /* When the system boots, we have no pending waits */ assert(EMPTY_LIST(&events, next, prev)); sched_block(spdid, 0); /* Wait for events, then act on expired events. Loop. */ while (1) { event_time_t next_wakeup; cos_mpd_update(); /* update mpd config given this * thread is now in this component * (no dependency if we are in the * same protection domain as the * scheduler) */ ticks = sched_timestamp(); if (sched_component_take(spdid)) { prints("fprr: scheduler lock failed!!!"); BUG(); } event_expiration(ticks); next_wakeup = next_event_time(); /* Are there no pending events??? */ if (TIMER_NO_EVENTS == next_wakeup) { if (sched_component_release(spdid)) { prints("fprr: scheduler lock release failed!!!"); BUG(); } sched_block(spdid, 0); } else { unsigned int wakeup; assert(next_wakeup > ticks); wakeup = (unsigned int)(next_wakeup - ticks); if (sched_component_release(spdid)) { prints("fprr: scheduler lock release failed!!!"); BUG(); } sched_timeout(spdid, wakeup); } } }