• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ delta_time函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中delta_time函数的典型用法代码示例。如果您正苦于以下问题:C++ delta_time函数的具体用法?C++ delta_time怎么用?C++ delta_time使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了delta_time函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
    }
}
开发者ID:qgewfg,项目名称:gtk-gnutella,代码行数:48,代码来源:nodes.c


示例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;
}
开发者ID:HelioGuilherme66,项目名称:gretl,代码行数:19,代码来源:audio.c


示例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);
}
开发者ID:mikenz,项目名称:LoRa-LMIC-1.51,代码行数:11,代码来源:hal.cpp


示例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);
}
开发者ID:Haxe,项目名称:gtk-gnutella,代码行数:14,代码来源:aging.c


示例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;
}
开发者ID:MrJoe,项目名称:gtk-gnutella,代码行数:30,代码来源:stable.c


示例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);
	}
}
开发者ID:Haxe,项目名称:gtk-gnutella,代码行数:64,代码来源:aging.c


示例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;
}
开发者ID:Haxe,项目名称:gtk-gnutella,代码行数:27,代码来源:hosts.c


示例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;
	}
}
开发者ID:MrJoe,项目名称:gtk-gnutella,代码行数:40,代码来源:knode.c


示例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;
}
开发者ID:slaeshjag,项目名称:kiruna,代码行数:36,代码来源:serial-test.c


示例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;
}
开发者ID:MrJoe,项目名称:gtk-gnutella,代码行数:20,代码来源:knode.c


示例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;
}
开发者ID:Eppo791906066,项目名称:gtk-gnutella,代码行数:20,代码来源:publisher.c


示例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
}
开发者ID:things-nyc,项目名称:testnode-arm-cortex-mbed-lmic-1.5,代码行数:16,代码来源:hal.cpp


示例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);
}
开发者ID:Eppo791906066,项目名称:gtk-gnutella,代码行数:19,代码来源:aging.c


示例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;
}
开发者ID:zayac,项目名称:cholesky,代码行数:17,代码来源:deblockboxes.c


示例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;
}
开发者ID:Haxe,项目名称:gtk-gnutella,代码行数:55,代码来源:stable.c


示例16: bogons_check

/**
 * Check the given IP against the entries in the bogus IP database.
 *
 * @returns TRUE if found, and FALSE if not.
 */
bool
bogons_check(const host_addr_t ha)
{
	if G_UNLIKELY(NULL == bogons_db)
		return FALSE;

	/*
	 * If the bogons file is too ancient, there is a risk it may flag an
	 * IP as bogus whereas it is no longer reserved.  IPv4 address shortage
	 * makes that likely.
	 *		--RAM, 2010-11-07
	 */

	if (delta_time(tm_time(), bogons_mtime) > 15552000)	/* ~6 months */
		return !host_addr_is_routable(ha);

	return 0 != iprange_get_addr(bogons_db, ha);
}
开发者ID:qgewfg,项目名称:gtk-gnutella,代码行数:23,代码来源:bogons.c


示例17: g2_build_add_uptime

/**
 * Add the servent update as a "UP" child to the root.
 */
static void
g2_build_add_uptime(g2_tree_t *t)
{
	time_delta_t uptime;
	char payload[8];
	int n;
	g2_tree_t *c;

	/*
	 * The uptime will typically be small, hence it is encoded as a variable
	 * length little-endian value, with trailing zeros removed.  Usually
	 * only 2 or 3 bytes will be necesssary to encode the uptime (in seconds).
	 */

	uptime = delta_time(tm_time(), GNET_PROPERTY(start_stamp));
	n = vlint_encode(uptime, payload);

	c = g2_tree_alloc_copy("UP", payload, n);	/* No trailing 0s */
	g2_tree_add_child(t, c);
}
开发者ID:Eppo791906066,项目名称:gtk-gnutella,代码行数:23,代码来源:build.c


示例18: udp_tx_desc_expired

/**
 * Remove expired messages (eslist iterator).
 *
 * @return TRUE if message has expired and was freed up.
 */
static bool
udp_tx_desc_expired(void *data, void *udata)
{
	struct udp_tx_desc *txd = data;
	udp_sched_t *us = udata;

	udp_sched_check(us);
	udp_tx_desc_check(txd);

	if (delta_time(tm_time(), txd->expire) > 0) {
		udp_sched_log(1, "%p: expiring mb=%p (%d bytes) prio=%u",
			us, txd->mb, pmsg_size(txd->mb), pmsg_prio(txd->mb));

		if (txd->cb->add_tx_dropped != NULL)
			(*txd->cb->add_tx_dropped)(txd->tx->owner, 1);	/* Dropped in TX */

		return udp_tx_desc_drop(data, udata);			/* Returns TRUE */
	}

	return FALSE;
}
开发者ID:luciomarinelli,项目名称:gtk-gnutella,代码行数:26,代码来源:udp_sched.c


示例19: aging_gc

/**
 * Periodic garbage collecting routine.
 */
static bool
aging_gc(void *obj)
{
	aging_table_t *ag = obj;
	time_t now = tm_time();
	struct aging_value *aval;

	aging_check(ag);

	aging_synchronize(ag);

	g_assert(elist_count(&ag->list) == hikset_count(ag->table));

	while (NULL != (aval = elist_head(&ag->list))) {
		if (delta_time(now, aval->last_insert) <= ag->delay)
			break;			/* List is sorted, oldest items first */
		hikset_remove(ag->table, aval->key);
		aging_free(aval, ag);
	}

	aging_return(ag, TRUE);			/* Keep calling */
}
开发者ID:Eppo791906066,项目名称:gtk-gnutella,代码行数:25,代码来源:aging.c


示例20: natpmp_update

/**
 * Update internal information about the NAT-PMP gateway upon reception
 * of an RPC reply.
 */
static void
natpmp_update(natpmp_t *np, unsigned sssoe)
{
	time_delta_t d;
	unsigned conservative_sssoe;

	natpmp_check(np);

	d = delta_time(tm_time(), np->last_update);
	conservative_sssoe = uint_saturate_add(np->sssoe, 7 * d / 8);

	if (sssoe < conservative_sssoe && conservative_sssoe - sssoe > 1) {
		np->rebooted = TRUE;
		if (GNET_PROPERTY(natpmp_debug) > 1) {
			g_debug("NATPMP new SSSOE=%u < conservative SSSOE=%u, %s rebooted",
				sssoe, conservative_sssoe, host_addr_to_string(np->gateway));
		}
	}

	np->last_update = tm_time();
	np->sssoe = sssoe;
}
开发者ID:MrJoe,项目名称:gtk-gnutella,代码行数:26,代码来源:natpmp.c



注:本文中的delta_time函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ delwin函数代码示例发布时间:2022-05-30
下一篇:
C++ delta函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap