本文整理汇总了C++中delta_time函数的典型用法代码示例。如果您正苦于以下问题:C++ delta_time函数的具体用法?C++ delta_time怎么用?C++ delta_time使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了delta_time函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: nodes_gui_update_node_info
/**
* Update the row with the given nodeinfo. If row is -1 the row number
* is determined by the node_id contained in the gnet_node_info_t.
*/
static void
nodes_gui_update_node_info(gnet_node_info_t *n, gint row)
{
GtkCList *clist = GTK_CLIST(gui_main_window_lookup("clist_nodes"));
g_assert(n != NULL);
if (row == -1) {
row = gtk_clist_find_row_from_data(clist,
deconstify_gpointer(n->node_id));
}
if (row != -1) {
gchar ver_buf[64];
gnet_node_status_t status;
time_t now = tm_time();
if (guc_node_get_status(n->node_id, &status)) {
gtk_clist_set_text(clist, row, c_gnet_user_agent,
n->vendor ? lazy_utf8_to_locale(n->vendor) : "...");
gtk_clist_set_text(clist, row, c_gnet_loc,
deconstify_gchar(iso3166_country_cc(n->country)));
gm_snprintf(ver_buf, sizeof ver_buf, "%d.%d",
n->proto_major, n->proto_minor);
gtk_clist_set_text(clist, row, c_gnet_version, ver_buf);
if (status.status == GTA_NODE_CONNECTED)
gtk_clist_set_text(clist, row, c_gnet_connected,
short_uptime(delta_time(now, status.connect_date)));
if (status.up_date)
gtk_clist_set_text(clist, row, c_gnet_uptime,
status.up_date
? short_uptime(delta_time(now, status.up_date)) : "...");
gtk_clist_set_text(clist, row, c_gnet_info,
nodes_gui_common_status_str(&status));
}
} else {
g_warning("%s: no matching row found", G_GNUC_PRETTY_FUNCTION);
}
}
示例2: write_note_event
static int write_note_event (note_event *event, midi_spec *spec)
{
int len;
len = delta_time(event->dtime, spec->nticks, spec->fp);
putc(MIDI_NOTE_ON + event->channel, spec->fp);
putc(event->pitch, spec->fp);
putc(event->force, spec->fp);
len += 3;
/* use "running status" */
len += delta_time(event->duration, spec->nticks, spec->fp);
putc(event->pitch, spec->fp);
putc(0, spec->fp);
len += 2;
return len;
}
示例3: hal_waitUntil
void hal_waitUntil (u8_t time) {
u4_t delta = delta_time(time);
// From delayMicroseconds docs: Currently, the largest value that
// will produce an accurate delay is 16383.
while (delta > (16000 / US_PER_OSTICK)) {
delay(16);
delta -= (16000 / US_PER_OSTICK);
}
if (delta > 0)
delayMicroseconds(delta * US_PER_OSTICK);
}
示例4: aging_age
/**
* Return entry age in seconds, (time_delta_t) -1 if not found.
*/
time_delta_t
aging_age(const aging_table_t *ag, gconstpointer key)
{
struct aging_value *aval;
aging_check(ag);
aval = g_hash_table_lookup(ag->table, key);
return aval == NULL ?
(time_delta_t) -1 : delta_time(tm_time(), aval->last_insert);
}
示例5: stable_still_alive_probability
/**
* Given a node which was first seen at ``first_seen'' and last seen at
* ``last_seen'', return probability that node still be alive now.
*
* @param first_seen first time node was seen / created
* @param last_seen last time node was seen
*
* @return the probability that the node be still alive now.
*/
double
stable_still_alive_probability(time_t first_seen, time_t last_seen)
{
time_delta_t life;
time_delta_t elapsed;
life = delta_time(last_seen, first_seen);
if (life <= 0)
return 0.0;
elapsed = delta_time(tm_time(), last_seen);
/*
* Safety precaution: regardless of the past lifetime of the node, if
* we have not heard from it for more than STABLE_UPPER_THRESH, then
* consider it dead.
*/
return elapsed < STABLE_UPPER_THRESH ?
stable_alive_probability(life, elapsed) : 0.0;
}
示例6: aging_insert
/**
* Add value to the table.
*
* If it was already present, its lifetime is augmented by the aging delay.
*
* The key argument is freed immediately if there is a free routine for
* keys and the key was present in the table.
*
* The previous value is freed and replaced by the new one if there is
* an insertion conflict and the value pointers are different.
*/
void
aging_insert(aging_table_t *ag, const void *key, void *value)
{
gboolean found;
void *okey, *ovalue;
time_t now = tm_time();
struct aging_value *aval;
g_assert(ag->magic == AGING_MAGIC);
found = g_hash_table_lookup_extended(ag->table, key, &okey, &ovalue);
if (found) {
aval = ovalue;
g_assert(aval->key == okey);
if (aval->key != key && ag->kvfree != NULL) {
/*
* We discard the new and keep the old key instead.
* That way, we don't have to update the hash table.
*/
(*ag->kvfree)(deconstify_gpointer(key), aval->value);
}
g_assert(aval->cq_ev != NULL);
/*
* Value existed for this key, prolonge its life.
*/
aval->value = value;
aval->ttl -= delta_time(now, aval->last_insert);
aval->ttl += ag->delay;
aval->ttl = MAX(aval->ttl, 1);
aval->ttl = MIN(aval->ttl, INT_MAX / 1000);
aval->last_insert = now;
cq_resched(aval->cq_ev, 1000 * aval->ttl);
} else {
WALLOC(aval);
aval->value = value;
aval->key = deconstify_gpointer(key);
aval->ttl = ag->delay;
aval->ttl = MAX(aval->ttl, 1);
aval->ttl = MIN(aval->ttl, INT_MAX / 1000);
aval->last_insert = now;
aval->ag = ag;
aval->cq_ev = cq_insert(aging_cq, 1000 * aval->ttl, aging_expire, aval);
gm_hash_table_insert_const(ag->table, key, aval);
}
}
示例7: host_cache_allow_bypass
/*
* Avoid nodes being stuck helplessly due to completely stale caches.
* @return TRUE if an UHC may be contact, FALSE if it's not permissable.
*/
static gboolean
host_cache_allow_bypass(void)
{
static time_t last_try;
if (node_count() > 0)
return FALSE;
/* Wait at least 2 minutes after starting up */
if (delta_time(tm_time(), GNET_PROPERTY(start_stamp)) < 2 * 60)
return FALSE;
/*
* Allow again after 12 hours, useful after unexpected network outage
* or downtime.
*/
if (last_try && delta_time(tm_time(), last_try) < 12 * 3600)
return FALSE;
last_try = tm_time();
return TRUE;
}
示例8: knode_dead_probability_cmp
/**
* Comparison of two knodes based on their probability of being dead.
*/
int
knode_dead_probability_cmp(const void *a, const void *b)
{
const knode_t *k1 = a;
const knode_t *k2 = b;
double p1, p2;
double e;
p1 = knode_still_alive_probability(k1);
p2 = knode_still_alive_probability(k2);
/* Higher alive chances => lower dead probability */
e = p2 - p1;
if (e < 0.0)
e = -e;
if (e < 1e-15) {
time_delta_t d;
/*
* Probabilities of presence are comparable.
* The more ancient node is more likely to be alive.
* Otherwise, the one we heard from last is more likely to be alive.
*/
d = delta_time(k1->first_seen, k2->first_seen);
if (0 == d) {
d = delta_time(k1->last_seen, k2->last_seen);
return 0 == d ? 0 : d > 0 ? -1 : +1;
} else {
return d > 0 ? +1 : -1;
}
} else {
return p2 > p1 ? +1 : -1;
}
}
示例9: main
int main(int argc, char **argv) {
FILE *file_in = fopen(argv[1], "r");
char buff[256];
int i, serial_fd;
int waittime;
serial_fd = initiate_serial_port("/dev/ttyUSB0");
if (!file_in) {
fprintf(stderr, "Unable to open input file %s\n", argv[1]);
return -1;
}
gettimeofday(&time_d, NULL);
for (i = 0; i < 63; i++) {
fread(buff, 1, PACKET_SIZE, file_in);
write(serial_fd, buff, PACKET_SIZE);
if((waittime = ((1000000 / (8000 / PACKET_SIZE)) - delta_time())) > 0)
usleep(waittime);
fprintf(stderr, "sending some data\n");
}
for (;;) {
fread(buff, 1, PACKET_SIZE, file_in);
write(serial_fd, buff, PACKET_SIZE);
read(serial_fd, buff, PACKET_SIZE);
fwrite(buff, 1, PACKET_SIZE, stdout);
fflush(stdout);
if((waittime = ((1000000 / (8000 / PACKET_SIZE)) - delta_time())) > 0)
usleep(waittime);
}
return 0;
}
示例10: knode_can_recontact
/**
* Can the node which timed-out in the past be considered again as the
* target of an RPC, and therefore returned in k-closest lookups?
*/
bool
knode_can_recontact(const knode_t *kn)
{
time_t grace;
time_delta_t elapsed;
knode_check(kn);
if (!kn->rpc_timeouts)
return TRUE; /* Timeout condition was cleared */
grace = 1 << kn->rpc_timeouts;
elapsed = delta_time(tm_time(), kn->last_sent);
return elapsed > grace;
}
示例11: publisher_remove_expired
/**
* DBMW foreach iterator to remove expired DB keys.
* @return TRUE if entry must be deleted.
*/
static bool
publisher_remove_expired(void *u_key, void *value, size_t u_len, void *u_data)
{
const struct pubdata *pd = value;
(void) u_key;
(void) u_len;
(void) u_data;
/*
* Entries for which we should re-enqueue a publish request now
* have expired and can be deleted.
*/
return delta_time(tm_time(), pd->next_enqueue) >= 0;
}
示例12: hal_waitUntil
void hal_waitUntil (u8_t time) {
#ifdef ARDUINO
u4_t delta = delta_time(time);
// From delayMicroseconds docs: Currently, the largest value that
// will produce an accurate delay is 16383.
while (delta > (16000 / US_PER_OSTICK)) {
delay(16);
delta -= (16000 / US_PER_OSTICK);
}
if (delta > 0)
delayMicroseconds(delta * US_PER_OSTICK);
#else
fprintf(stderr, "Waiting until %u\n", time);
while(micros() < (((uint64_t) time) * US_PER_OSTICK));
#endif
}
示例13: aging_age
/**
* Return entry age in seconds, (time_delta_t) -1 if not found.
*/
time_delta_t
aging_age(const aging_table_t *ag, const void *key)
{
struct aging_value *aval;
time_delta_t age;
aging_check(ag);
aging_synchronize(ag);
aval = hikset_lookup(ag->table, key);
age = aval == NULL ?
(time_delta_t) -1 : delta_time(tm_time(), aval->last_insert);
aging_return(ag, age);
}
示例14: finalize
void *
finalize (void *hnd, c4snet_data_t * fltiles, int bs, int p)
{
struct timespec end;
tile * tiles = *((tile **) C4SNetGetData (fltiles));
if (clock_gettime(CLOCK_REALTIME, &end)) {
pexit("clock_gettime");
}
printf("Time for size %d x %d : %lf sec\n", bs * p, bs * p, delta_time(begin, end));
write_matrix(tiles, p, bs);
C4SNetOut (hnd, 1, C4SNetCreate (CTYPE_char, 5, "Done."));
C4SNetFree (fltiles);
return hnd;
}
示例15: stable_store_presence
/**
* Estimate probability of presence for a value published to some roots in
* a given time frame.
*
* @param d how many seconds in the future?
* @param rs the STORE lookup path, giving root candidates
* @param status the array of STORE status for each entry in the path
*
* @return an estimated probability of presence of the value in the network.
*/
double
stable_store_presence(time_delta_t d,
const lookup_rs_t *rs, const guint16 *status)
{
double q = 1.0;
size_t i;
size_t count = lookup_result_path_length(rs);
/*
* We may be called by publish callbacks invoked to clean up because
* the operation was cancelled. Maybe the DHT was disabled during the
* operation, meaning our data structures have been cleaned up? In that
* case, abort immediately.
*
* NOTE: this is not an assertion, it can happen in practice and needs to
* be explicitly checked for.
*/
if (NULL == db_lifedata) /* DHT disabled dynamically */
return 0.0;
/*
* The probability of presence is (1 - q) where q is the probability
* that the value be lost by all the nodes, i.e. that all the nodes
* to which the value was published to be gone in "d" seconds.
*/
for (i = 0; i < count; i++) {
if (status[i] == STORE_SC_OK) {
const knode_t *kn = lookup_result_nth_node(rs, i);
struct lifedata *ld = get_lifedata(kn->id);
if (NULL == ld) {
return 0.0; /* Cannot compute a suitable probability */
} else {
time_delta_t alive = delta_time(ld->last_seen, ld->first_seen);
double p = stable_alive_probability(alive, d);
q *= (1.0 - p); /* (1 - p) is proba this node will be gone */
}
}
}
return 1.0 - q;
}