void update_NPCs( NPC** _NPCs, int _NPCCount, bomb* _pBomb, map* _pMap ) { // loop through all NPCs int i; for ( i = 0; i < _NPCCount; i++ ) { // update NPC's coordinates atributes _NPCs[i]->right = _NPCs[i]->left + GC_block_size; _NPCs[i]->bottom = _NPCs[i]->top + GC_block_size; _NPCs[i]->i = ( ( (_NPCs[i]->top + GC_block_size/2) - GC_y_offset) / GC_block_size ); _NPCs[i]->j = ( (_NPCs[i]->left + GC_block_size/2) / GC_block_size ); // invoke NPC's artificial intelligence, but not every loop // delay the artificial intelligence, it mustn't run each loop if ( time_is_up( _NPCs[i]->AI_timer ) ) { //_NPCs[i]->p_NPC_AI( _pGame ); NPC_random_walk_AI( _NPCs[i], _pBomb, _NPCs, _NPCCount, _pMap ); reset_timer( _NPCs[i]->AI_timer ); } else { // delay the NPC's walk if ( time_is_up( _NPCs[i]->walk_timer ) ) { NPC_walk( _NPCs[i], _pBomb, _NPCs, _NPCCount, _pMap, _NPCs[i]->direction ); reset_timer( _NPCs[i]->walk_timer ); } } } }
int main(int argc, const char * argv[]){ clock_t begin = clock(); if(argc == 1){ // standard mode mpz_t numbers[NUMBERS]; list * calculatedFactors[NUMBERS]; int i; mpz_t y; mpz_init_set_ui(y, 1); for (i = 0; i < NUMBERS; i++){ mpz_init(numbers[i]); mpz_inp_str(numbers[i], stdin, 10); } for (i = 0; i < NUMBERS; i++) { reset_timer(); list* factors = createList(); factorize(factors, numbers[i],1, y); calculatedFactors[i] = factors; } for (i = 0; i < NUMBERS; i++){ printFactors(calculatedFactors[i]); } clock_t end = clock(); double tdiff = (((double) end) - ((double)begin)) / CLOCKS_PER_SEC; printf(", %f\n", tdiff); return 0; } else if(strcmp(argv[1], "interactive") == 0){ // interactive mode fprintf(stderr, "Interactive mode!\n"); mpz_t number; mpz_init(number); list * factors = NULL; mpz_t y; mpz_init_set_ui(y, 1); while (1) { mpz_inp_str(number, stdin, 10); reset_timer(); factors = createList(); factorize(factors, number, 1, y); TRACE("PRINTING FACTORS:\n"); printFactors(factors); } return 0; } return 1; }
void cancel_invite(struct sip_msg *cancel_msg, struct cell *t_cancel, struct cell *t_invite ) { #define CANCEL_REASON_SIP_487 \ "Reason: SIP;cause=487;text=\"ORIGINATOR_CANCEL\"" CRLF branch_bm_t cancel_bitmap; branch_bm_t dummy_bm; str reason; unsigned int i; struct hdr_field *hdr; cancel_bitmap=0; /* send back 200 OK as per RFC3261 */ reason.s = CANCELING; reason.len = sizeof(CANCELING)-1; t_reply( t_cancel, cancel_msg, 200, &reason ); reason.s = NULL; reason.len = 0; /* propagate the REASON flag ? */ if ( t_cancel->flags&T_CANCEL_REASON_FLAG ) { /* look for the Reason header */ if (parse_headers(cancel_msg, HDR_EOH_F, 0)<0) { LM_ERR("failed to parse all hdrs - ignoring Reason hdr\n"); } else { hdr = get_header_by_static_name(cancel_msg, "Reason"); if (hdr!=NULL) { reason.s = hdr->name.s; reason.len = hdr->len; } } } /* if no reason, use NORMAL CLEARING */ if (reason.s == NULL) { reason.s = CANCEL_REASON_SIP_487; reason.len = sizeof(CANCEL_REASON_SIP_487) - 1; } /* generate local cancels for all branches */ which_cancel(t_invite, &cancel_bitmap ); set_cancel_extra_hdrs( reason.s, reason.len); cancel_uacs(t_invite, cancel_bitmap ); set_cancel_extra_hdrs( NULL, 0); /* internally cancel branches with no received reply */ for (i=t_invite->first_branch; i<t_invite->nr_of_outgoings; i++) { if (t_invite->uac[i].last_received==0){ /* reset the "request" timers */ reset_timer(&t_invite->uac[i].request.retr_timer); reset_timer(&t_invite->uac[i].request.fr_timer); LOCK_REPLIES( t_invite ); relay_reply(t_invite,FAKED_REPLY,i,487,&dummy_bm); } } }
void cleanup_localcancel_timers( struct cell *t ) { int i; for (i=0; i<t->nr_of_outgoings; i++ ) { reset_timer( &t->uac[i].local_cancel.retr_timer ); reset_timer( &t->uac[i].local_cancel.fr_timer ); } }
void cleanup_uac_timers( struct cell *t ) { int i; /* reset FR/retransmission timers */ for (i=t->first_branch; i<t->nr_of_outgoings; i++ ) { reset_timer( &t->uac[i].request.retr_timer ); reset_timer( &t->uac[i].request.fr_timer ); } LM_DBG("RETR/FR timers reset\n"); }
/* returns 1 if everything was OK or -1 for error */ int t_release_transaction( struct cell *trans ) { set_kr(REQ_RLSD); reset_timer( & trans->uas.response.fr_timer ); reset_timer( & trans->uas.response.retr_timer ); cleanup_uac_timers( trans ); put_on_wait( trans ); return 1; }
/** * @brief 开始LED闪烁指示 * @param[in] unsigned int led * @param[in] unsigned short delay 闪烁的时间间隔,也就是闪烁频率,单位10ms * @note 注意此接口可以让几个LED同时按照各自不同的频率闪烁 */ void hw_platform_start_led_blink(unsigned int led,unsigned short delay) { int ret; hw_platform_led_ctrl(led,1); if (led == LED_RED) { if (current_led_state & LED_RED_ON_MASK) { current_led_state |= LED_RED_MASK; ret = reset_timer(led_timer_h[0],V_TIMER_MODE_PERIODIC,delay*10,led_red_blink_timer_hook); assert(ret == 0); } else { current_led_state |= (LED_RED_MASK | LED_RED_ON_MASK); led_timer_h[0] = start_timer(V_TIMER_MODE_PERIODIC,delay*10,led_red_blink_timer_hook); assert(led_timer_h[0] != 0); } } else if (led == LED_GREEN) { if (current_led_state & LED_GREEN_ON_MASK) { current_led_state |= LED_GREEN_MASK; ret = reset_timer(led_timer_h[2],V_TIMER_MODE_PERIODIC,delay*10,led_green_blink_timer_hook); assert(ret == 0); } else { current_led_state |= (LED_GREEN_MASK | LED_GREEN_ON_MASK); led_timer_h[2] = start_timer(V_TIMER_MODE_PERIODIC,delay*10,led_green_blink_timer_hook); assert(led_timer_h[2] != 0); } } else { if (current_led_state & LED_BLUE_ON_MASK) { current_led_state |= LED_BLUE_MASK; ret = reset_timer(led_timer_h[3],V_TIMER_MODE_PERIODIC,delay*10,LED_BLUE_blink_timer_hook); assert(ret == 0); } else { current_led_state |= (LED_BLUE_MASK | LED_BLUE_ON_MASK); led_timer_h[3] = start_timer(V_TIMER_MODE_PERIODIC,delay*10,LED_BLUE_blink_timer_hook); assert(led_timer_h[3] != 0); } } }
/* External functions */ Game* create_game(void) { int ii; Game* G = (Game*)calloc(1, sizeof(Game)); G->timer = create_timer(); G->graphics = create_graphics(); G->ui = create_ui(G->graphics); /* Set up camera */ G->camera = transform_zero; G->camera.orientation = quat_from_euler(0, -0.75f * kPi, 0); G->camera.position.x = 4.0f; G->camera.position.y = 2; G->camera.position.z = 7.5f; /* Load scene */ reset_timer(G->timer); G->scene = create_scene("lightHouse.obj"); G->sun_light.position = vec3_create(-4.0f, 5.0f, 2.0f); G->sun_light.color = vec3_create(1, 1, 1); G->sun_light.size = 35.0f; G->lights[0].color = vec3_create(1, 0, 0); G->lights[1].color = vec3_create(1, 1, 0); G->lights[2].color = vec3_create(0, 1, 0); G->lights[3].color = vec3_create(1, 0, 1); G->lights[4].color = vec3_create(0, 0, 1); G->lights[5].color = vec3_create(0, 1, 1); for(ii=0;ii<NUM_LIGHTS;++ii) { float x = (20.0f/NUM_LIGHTS) * ii - 8.0f; G->lights[ii].color = vec3_create(_rand_float(), _rand_float(), _rand_float()); G->lights[ii].color = vec3_normalize(G->lights[ii].color); if(ii % 2) G->lights[ii].position = vec3_create(x, _rand_float()*3 + 2.0f, 0.0f); else G->lights[ii].position = vec3_create(0.0f, _rand_float()*3 + 2.0f, x); G->lights[ii].size = 5; } get_model(G->scene, 3)->material->specular_color = vec3_create(0.5f, 0.5f, 0.5f); get_model(G->scene, 3)->material->specular_coefficient = 1.0f; G->dynamic_lights = 1; reset_timer(G->timer); return G; }
void m58846_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) { if (id != 0) return; // timer 1: 7-bit fixed counter (manual specifically says 127) if (++m_tmr_count[0] == 127) { m_tmr_count[0] = 0; m_irqflag[1] = true; m_possible_irq = true; } // timer 2: 8-bit user defined counter with auto-reload if (m_v & 8 && ++m_tmr_count[1] == 0) { m_tmr_count[1] = m_tmr_reload; m_irqflag[2] = true; m_possible_irq = true; m_port_t ^= 1; m_write_t(m_port_t); } // schedule next timeout reset_timer(); }
status_t _auto_switch_start(void) { uint32_t duration = 0; int32_t pic_switch_duration = 0; /*if(pic_switch_timer) { printf("[PIC] play_pic_auto_switch_start pic_switch_timer is already created\n"); return GXCORE_ERROR; }*/ pic_switch_duration = pmpset_get_int(PMPSET_PIC_SWITCH_DURATION); // TODO: 时间暂时推迟下,解码时间太长 if(PMPSET_PIC_SWITCH_DURATION_3s == pic_switch_duration)duration = 3000; else if(PMPSET_PIC_SWITCH_DURATION_5s == pic_switch_duration)duration = 5000; else if(PMPSET_PIC_SWITCH_DURATION_7s == pic_switch_duration)duration = 7000; else if(PMPSET_PIC_SWITCH_DURATION_10s== pic_switch_duration)duration = 10000; if(0 != reset_timer(pic_switch_timer)) { pic_switch_timer = create_timer(_auto_switch_pic, (int)duration, NULL, TIMER_REPEAT); } return GXCORE_SUCCESS; }
void app_pic_update_timer_reset(void) { if (reset_timer(sp_PicUpdateTimer) != 0) { sp_PicUpdateTimer = create_timer(picasa_pic_update_timeout, 500, NULL, TIMER_REPEAT); } }
/* * * xsocks UDP Response * +------+----------+----------+----------+ * | ATYP | DST.ADDR | DST.PORT | DATA | * +------+----------+----------+----------+ * | 1 | Variable | 2 | Variable | * +------+----------+----------+----------+ * */ static void server_recv_cb(uv_udp_t *handle, ssize_t nread, const uv_buf_t *buf, const struct sockaddr *addr, unsigned flags) { if (nread > 0) { struct client_context *client = handle->data; reset_timer(client); int mlen = nread - PRIMITIVE_BYTES; uint8_t *m = (uint8_t *)buf->base; int rc = crypto_decrypt(m, (uint8_t *)buf->base, nread); if (rc) { logger_log(LOG_ERR, "invalid packet"); goto err; } memmove(m, m + addrlen, mlen - addrlen); mlen -= addrlen; forward_to_client(client, m , mlen); } else { goto err; } return; err: free(buf->base); }
int main() { test_setup(); perf_start(); for (int i = 0; i < NUM_ITER; ++i) { test_clear(); reset_timer(); start_timer(); test_run(i); stop_timer(); samples[i] = get_time(); } perf_stop(); int check = test_check(); printf("Correct: %d\n", check); for (int i = 0; i < NUM_ITER; ++i) printf("TS[%d]: %d\n", i, samples[i]); perf_print_all(); return 0; }
void mb3773_device::device_start() { m_watchdog_timer = machine().scheduler().timer_alloc( FUNC(watchdog_timeout), this ); reset_timer(); save_item( NAME(m_ck) ); }
void run_n(size_t n) { d_num_iterations = n; reset_timer(); start_timer(); d_benchmark.get_func()(this); stop_timer(); }
void app_picasa_feeds_update_timer_reset(void) { if (reset_timer(sp_PicasaFeedsUpdateTimer) != 0) { sp_PicasaFeedsUpdateTimer = create_timer(picasa_feeds_update_timer_timeout, 1000, NULL, TIMER_ONCE); } }
static void remote_recv_cb(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) { struct remote_context *remote; struct client_context *client; remote = stream->data; client = remote->client; if (nread > 0) { reset_timer(remote); uv_read_stop(&remote->handle.stream); int clen = nread + PRIMITIVE_BYTES; uint8_t *c = remote->buf + HEADER_BYTES; int rc = crypto_encrypt(c, (uint8_t*)buf->base, nread); if (!rc) { forward_to_client(client, c, clen); } else { logger_log(LOG_ERR, "invalid tcp packet"); close_client(client); close_remote(remote); } } else if (nread < 0){ if (nread != UV_EOF) { logger_log(LOG_ERR, "receive from %s failed: %s", client->target_addr, uv_strerror(nread)); } close_client(client); close_remote(remote); } }
static void client_recv_cb(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) { struct client_context *client = stream->data; struct remote_context *remote = client->remote; int clen; if (nread > 0) { reset_timer(remote); uv_read_stop(&client->handle.stream); switch (client->stage) { case XSTAGE_HANDSHAKE: if (verify_methods(buf->base, nread)) { handshake(client); } else { logger_log(LOG_ERR, "invalid method packet"); close_client(client); close_remote(remote); } break; case XSTAGE_REQUEST: if (verify_request(buf->base, nread)) { request_start(client, buf->base); } else { logger_log(LOG_ERR, "invalid request packet"); close_client(client); close_remote(remote); } break; case XSTAGE_FORWARD: clen = nread + PRIMITIVE_BYTES; uint8_t *c = client->buf + HEADER_BYTES; int rc = crypto_encrypt(c, (uint8_t*)buf->base, nread); if (rc) { logger_log(LOG_ERR, "encrypt failed"); close_client(client); close_remote(remote); } forward_to_remote(remote, c, clen); break; default: break; } } else if (nread < 0) { if (nread != UV_EOF) { char addrbuf[INET6_ADDRSTRLEN + 1] = {0}; uint16_t port = ip_name(&client->addr, addrbuf, sizeof addrbuf); logger_log(LOG_ERR, "receive from %s:%d failed: %s", addrbuf, port, uv_strerror(nread)); } close_client(client); close_remote(remote); } }
UP_STATUS ICACHE_FLASH_ATTR uploadable_page_put(const char *data, unsigned int data_len) { if(mBuffer == NULL) return UP_STATUS_WRONG_CALL; if(mFlashingSector > UPLOADABLE_PAGE_END_SECTOR) return UP_STATUS_OVERFLOW; reset_timer(); ETS_INTR_LOCK(); while(data_len) { uint32_t tocopy = (data_len > (SPI_FLASH_SEC_SIZE - mBufferPos)) ? (SPI_FLASH_SEC_SIZE - mBufferPos): data_len; os_memcpy(&mBuffer[mBufferPos], data, tocopy); mBufferPos += tocopy; data_len -= tocopy; data += tocopy; if(mBufferPos == SPI_FLASH_SEC_SIZE) { SpiFlashOpResult res = flash_data(); mBufferPos = 0; if(res != SPI_FLASH_RESULT_OK) { ETS_INTR_UNLOCK(); dhdebug("Error while writing page at 0x%X", mFlashingSector * SPI_FLASH_SEC_SIZE); return UP_STATUS_INTERNAL_ERROR; } } } ETS_INTR_UNLOCK(); return UP_STATUS_OK; }
static void setup_timer(mfp_timer_t * const ptimer, int idx, bogoc68_t bogoc) { ptimer->def = timer_def[idx&3]; ptimer->tdr_res = 256; ptimer->tdr_cur = ptimer->tdr_res; reset_timer(ptimer, bogoc); }
static void end_scroll() { if(scrollmenu!=NULL){ reset_timer(); scrollmenu=NULL; } }
/* * * xsocks UDP Response * +------+----------+----------+----------+ * | ATYP | DST.ADDR | DST.PORT | DATA | * +------+----------+----------+----------+ * | 1 | Variable | 2 | Variable | * +------+----------+----------+----------+ * */ static void server_recv_cb(uv_udp_t *handle, ssize_t nread, const uv_buf_t *buf, const struct sockaddr *addr, unsigned flags) { if (nread > 0) { struct client_context *client = handle->data; reset_timer(client); int mlen = nread - PRIMITIVE_BYTES; uint8_t *m = (uint8_t *)buf->base; int rc = crypto_decrypt(m, (uint8_t *)buf->base, nread); if (rc) { logger_log(LOG_ERR, "invalid packet"); dump_hex(buf->base, nread, "server recv"); goto err; } m -= 3; mlen += 3; memcpy(m, "\x0\x0\x0", 3); // RSV + FRAG forward_to_client(client, m , mlen); return; } else { goto err; } err: free(buf->base - 3); }
void app_pic_play_timer_reset(void) { if (reset_timer(sp_PicPlayTimer) != 0) { sp_PicPlayTimer = create_timer(picasa_pic_play_timeout, 5000, NULL, TIMER_ONCE); } }
void resolv_start(const char *hostname, uint16_t port, void (*client_cb)(struct sockaddr *, void *), void (*free_cb)(void *), void *data) { /* * Wrap c-ares's call back in our own */ struct resolv_query *query = ss_malloc(sizeof(struct resolv_query)); memset(query, 0, sizeof(struct resolv_query)); query->port = port; query->client_cb = client_cb; query->response_count = 0; query->responses = NULL; query->data = data; query->free_cb = free_cb; query->requests[0] = AF_INET; query->requests[1] = AF_INET6; ares_gethostbyname(default_ctx.channel, hostname, AF_INET, dns_query_v4_cb, query); ares_gethostbyname(default_ctx.channel, hostname, AF_INET6, dns_query_v6_cb, query); reset_timer(); }
void client_accept_cb(uv_stream_t *server, int status) { struct client_context *client = new_client(); struct remote_context *remote = new_remote(idle_timeout); client->remote = remote; remote->client = client; uv_timer_init(server->loop, remote->timer); uv_tcp_init(server->loop, &client->handle.tcp); uv_tcp_init(server->loop, &remote->handle.tcp); int rc = uv_accept(server, &client->handle.stream); if (rc == 0) { int namelen = sizeof client->addr; uv_tcp_getpeername(&client->handle.tcp, &client->addr, &namelen); reset_timer(remote); // start timer connect_to_remote(remote); } else { logger_log(LOG_ERR, "accept error: %s", uv_strerror(rc)); close_client(client); close_remote(remote); } }
void youtube_play_update_timer_reset(void) { if (reset_timer(sp_YoutubePlayUpdateTimer) != 0) { sp_YoutubePlayUpdateTimer = create_timer(youtube_play_update, 1000, NULL, TIMER_REPEAT); } }
void mb3773_device::device_start() { m_watchdog_timer = timer_alloc(); reset_timer(); save_item( NAME(m_ck) ); }
/*===========================================================================* * do_setalarm * *===========================================================================*/ int do_setalarm(struct proc * caller, message * m_ptr) { /* A process requests a synchronous alarm, or wants to cancel its alarm. */ long exp_time; /* expiration time for this alarm */ int use_abs_time; /* use absolute or relative time */ timer_t *tp; /* the process' timer structure */ clock_t uptime; /* placeholder for current uptime */ /* Extract shared parameters from the request message. */ exp_time = m_ptr->ALRM_EXP_TIME; /* alarm's expiration time */ use_abs_time = m_ptr->ALRM_ABS_TIME; /* flag for absolute time */ if (! (priv(caller)->s_flags & SYS_PROC)) return(EPERM); /* Get the timer structure and set the parameters for this alarm. */ tp = &(priv(caller)->s_alarm_timer); tmr_arg(tp)->ta_int = caller->p_endpoint; tp->tmr_func = cause_alarm; /* Return the ticks left on the previous alarm. */ uptime = get_monotonic(); if ((tp->tmr_exp_time != TMR_NEVER) && (uptime < tp->tmr_exp_time) ) { m_ptr->ALRM_TIME_LEFT = (tp->tmr_exp_time - uptime); } else { m_ptr->ALRM_TIME_LEFT = 0; } /* Finally, (re)set the timer depending on the expiration time. */ if (exp_time == 0) { reset_timer(tp); } else { tp->tmr_exp_time = (use_abs_time) ? exp_time : exp_time + get_monotonic(); set_timer(tp, tp->tmr_exp_time, tp->tmr_func); } return(OK); }
/* Configure a free-running, auto-wrap counter with no prescaler */ int timer_init(void) { writel(MTU_CRn_ENA | MTU_CRn_PRESCALE_1 | MTU_CRn_32BITS, CONFIG_SYS_TIMERBASE + MTU_CR(0)); reset_timer(); return 0; }
subscriber_t *memstore_ipc_subscriber_create(ngx_int_t originator_slot, ngx_str_t *chid, void* foreign_chanhead) { sub_data_t *d; d = ngx_alloc(sizeof(*d), ngx_cycle->log); if(d == NULL) { ERR("couldn't allocate memstore subscriber data"); return NULL; } assert(originator_slot != memstore_slot()); subscriber_t *sub = internal_subscriber_create("memstore-ipc", d); internal_subscriber_set_enqueue_handler(sub, (callback_pt )sub_enqueue); internal_subscriber_set_dequeue_handler(sub, (callback_pt )sub_dequeue); internal_subscriber_set_respond_message_handler(sub, (callback_pt )sub_respond_message); internal_subscriber_set_respond_status_handler(sub, (callback_pt )sub_respond_status); sub->destroy_after_dequeue = 1; d->sub = sub; d->chid = chid; d->originator = originator_slot; assert(foreign_chanhead != NULL); d->foreign_chanhead = foreign_chanhead; d->owner = memstore_slot(); ngx_memzero(&d->timeout_ev, sizeof(d->timeout_ev)); d->timeout_ev.handler = timeout_ev_handler; d->timeout_ev.data = d; d->timeout_ev.log = ngx_cycle->log; reset_timer(d); DBG("%p created memstore subscriber created with privdata %p", d->sub, d); return sub; }