static void at_task_run_no_bytes(struct at_info *ati) { if (AT_RX_STATE_URC == ati->rx_state) { /* * Then we are waiting for the rest of a URC response. * Ensure that we have not passed the URC timeout period. * Honestly, we should NEVER really get here, or if we do, * we should never timeout on a URC. Doing so likely * indicates a bug in usage or architecture. */ if (is_timed_out(ati->timing.urc_start_ms, AT_URC_TIMEOUT_MS)) { pr_warning("[at] Timed out in a URC!?!. " "Should never happen. Likely a bug.\r\n"); return complete_urc(ati, AT_RSP_STATUS_TIMEOUT); } } else if (AT_CMD_STATE_IN_PROGRESS == ati->cmd_state) { /* * If here, then we received no data, but a command is in * progress. In this case, ensure that the command hasn't * reached its timeout period. */ if (is_timed_out(ati->timing.cmd_start_ms, ati->cmd_ip->timeout_ms)) { printk(dbg_lvl, "[at] Command timed out\r\n"); return complete_cmd(ati, AT_RSP_STATUS_TIMEOUT); } } /* * If here, then either we are not in the correct state or nothing * has timed out. Move along. */ }
bool encoder::process() { guard g(m_lock); if (curr_state() == STATE_FULL) { if (is_timed_out(FLAGS_encoder_timeout*5)) { inc("blocked timeouts"); LOG(ERROR) << "Encoder " << m_coder << ": Timed out while blocked"; enc_notify(); return true; } return false; } /* check if decoder is ready to be reused */ if (curr_state() == STATE_DONE) return true; /* check if decoder is timed out */ if (is_timed_out()) { LOG(ERROR) << "Encoder " << m_coder << ": Timed out (rank " << m_plain_pkt_count << ", state " << static_cast<int>(curr_state()) << ")"; dispatch_event(EVENT_TIMEOUT); inc("timeouts"); if (m_plain_pkt_count == this->symbols()) enc_notify(); } return false; }
/** * Keeps an eye on the at command state. If we are in the quiet period, this * method will keep an eye on the time so that we will change state back to * the READY state once the timeout has expired. */ void at_task_quiet_period_handler(struct at_info *ati) { if (AT_CMD_STATE_QUIET == ati->cmd_state && is_timed_out(ati->timing.quiet_start_ms, ati->dev_cfg.quiet_period_ms)) ati->cmd_state = AT_CMD_STATE_READY; }
/*! Delete entries from the hash */ static void *hash_test_shrink(void *d) { const struct hash_test *data = d; int i; for (i = 1; i < data->preload; ++i) { char *obj = ht_new(-i); char *from_ao2; if (obj == NULL) { return "Allocation failed"; } from_ao2 = ao2_find(data->to_be_thrashed, obj, OBJ_UNLINK | OBJ_POINTER); ao2_ref(obj, -1); if (from_ao2) { ao2_ref(from_ao2, -1); } else { return "Could not find object to delete"; } if (is_timed_out(data)) { return "Shrink timed out"; } } return NULL; }
/*! Continuously iterate through all the entries in the hash */ static void *hash_test_count(void *d) { const struct hash_test *data = d; int count = 0; int last_count = 0; while (count < data->max_grow) { last_count = count; count = 0; ao2_callback(data->to_be_thrashed, OBJ_MULTIPLE, increment_count, &count); if (last_count == count) { /* Allow other threads to run. */ sched_yield(); } else if (last_count > count) { /* Make sure the ao2 container never shrinks */ return "ao2 container unexpectedly shrank"; } if (is_timed_out(data)) { return "Count timed out"; } } /* Successfully iterated over all of the expected elements */ return NULL; }
static void failover_periodic_cb(void *context_) { struct failover_context *context = context_; char *curr_peer = NULL; char *prev_peer = NULL; if (rconn_is_connected(context->remote_rconn)) return; if (!is_timed_out(context->peers[context->index], context->settings->max_backoff)) { return; } rconn_disconnect(context->remote_rconn); prev_peer = (char *)context->settings->controller_names[context->index]; context->index = (context->index + 1) % context->settings->num_controllers; curr_peer = (char *)context->settings->controller_names[context->index]; rconn_connect(context->remote_rconn, context->settings->controller_names[context->index]); context->peers[context->index]->epoch = time_now(); VLOG_INFO("Switching over to %s, from %s", curr_peer, prev_peer); }
/*! Delete entries from the hash */ static void *hash_test_shrink(void *d) { const struct hash_test *data = d; int i; for (i = 1; i < data->preload; ++i) { char *obj = ht_new(-i); char *from_hashtab; int deleted; if (obj == NULL) { return "Allocation failed"; } from_hashtab = ast_hashtab_remove_object_via_lookup(data->to_be_thrashed, obj); deleted = from_hashtab != NULL; ht_delete(obj); ht_delete(from_hashtab); if (!deleted) { return "could not delete object"; } if (is_timed_out(data)) { return "Shrink timed out"; } } return NULL; }
bool decoder::process() { if (curr_state() == STATE_DONE) return true; if (is_timed_out() && !this->is_complete() && !this->is_partial_complete()) { LOG(ERROR) << "Decoder " << m_coder << ": Timed out (rank " << this->rank() << ")"; inc("incomplete timeouts"); dispatch_event(EVENT_TIMEOUT); return false; } if (is_timed_out()) { dispatch_event(EVENT_TIMEOUT); return false; } if (curr_state() == STATE_WAIT && packet_timed_out()) { if (this->is_partial_complete()) return false; double req_budget = source_budget(1, 254, 254, m_e3); VLOG(LOG_GEN) << "Decoder " << m_coder << ": Request more data (rank " << this->rank() << ", seq " << m_req_seq << ")"; for (; req_budget >= 0; req_budget--) send_request(m_req_seq); m_req_seq++; update_packet_timestamp(); return false; } return false; }
bool recoder::process() { /* check if done coding */ if (curr_state() == STATE_DONE) return true; /* check if timed out */ if (is_timed_out()) { VLOG(LOG_GEN) << "Recoder " << m_coder << ": Timed out"; dispatch_event(EVENT_TIMEOUT); return false; } return false; }
/*! /brief Grow the hash data as specified */ static void *hash_test_grow(void *d) { struct hash_test *data = d; int i; for (i = 0; i < data->max_grow; ++i) { char *obj; if (is_timed_out(data)) { return "Growth timed out"; } obj = ht_new(i); if (obj == NULL) { return "Allocation failed"; } ast_hashtab_insert_immediate(data->to_be_thrashed, obj); ast_atomic_fetchadd_int(&data->grow_count, 1); } return NULL; }
/*! /brief Grow the hash data as specified */ static void *hash_test_grow(void *d) { struct hash_test *data = d; int i; for (i = 0; i < data->max_grow; ++i) { char *ht; if (is_timed_out(data)) { printf("Growth timed out at %d\n", i); return "Growth timed out"; } ht = ht_new(i); if (ht == NULL) { return "Allocation failed"; } ao2_link(data->to_be_thrashed, ht); ao2_ref(ht, -1); ast_atomic_fetchadd_int(&data->grow_count, 1); } return NULL; }
/*! Randomly lookup data in the hash */ static void *hash_test_lookup(void *d) { struct hash_test *data = d; int max; unsigned seed = time(NULL); /* ast_atomic_fetchadd_int provide a memory fence so that the optimizer doesn't * optimize away reads. */ while ((max = ast_atomic_fetchadd_int(&data->grow_count, 0)) < data->max_grow) { int i; char *obj; char *from_ao2; if (is_timed_out(data)) { return "Lookup timed out"; } if (max == 0) { /* No data yet; yield and try again */ sched_yield(); continue; } /* Randomly lookup one object from the hash */ i = rand_r(&seed) % max; obj = ht_new(i); if (obj == NULL) { return "Allocation failed"; } from_ao2 = ao2_find(data->to_be_thrashed, obj, OBJ_POINTER); ao2_ref(obj, -1); ao2_ref(from_ao2, -1); if (from_ao2 == NULL) { return "Key unexpectedly missing"; } } return NULL; }
/*! Continuously iterate through all the entries in the hash */ static void *hash_test_count(void *d) { const struct hash_test *data = d; int count = 0; int last_count = 0; while (count < data->max_grow) { struct ast_hashtab_iter *it = ast_hashtab_start_write_traversal(data->to_be_thrashed); char *ht = ast_hashtab_next(it); last_count = count; count = 0; while (ht) { /* only count keys added by grow thread */ if (strncmp(ht, "key0", 4) == 0) { ++count; } ht = ast_hashtab_next(it); } ast_hashtab_end_traversal(it); if (last_count == count) { /* Give other threads ample chance to run, note that using sched_yield here does not * provide enough of a chance and can cause this thread to starve others. */ usleep(1); } else if (last_count > count) { /* Make sure the hashtable never shrinks */ return "hashtab unexpectedly shrank"; } if (is_timed_out(data)) { return "Count timed out"; } } /* Successfully iterated over all of the expected elements */ return NULL; }