コード例 #1
0
ファイル: buffer.c プロジェクト: jnbek/cblog
/* bufrelease • decrease the reference count and free the buffer if needed */
void
bufrelease(struct buf *buf) {
	if (!buf || !buf->unit) return;
	buf->ref -= 1;
	if (buf->ref == 0) {
#ifdef TRACK_BUFFERS
		int i = 0;
		while (i < all_buffers.size)
			if (all_buffers.item[i] == buf)
				parr_remove(&all_buffers, i);
			else i += 1;
#endif
#ifdef TRACK_BUFFER_DEBUG
		int i = 0;
		struct buf_debug_data *bdd = all_buffers.base;
		while (i < all_buffers.size)
			if (bdd[i].buf == buf)
				arr_remove(&all_buffers, i);
			else i += 1;
#endif
#ifdef BUFFER_STATS
		buffer_stat_nb -= 1;
		buffer_stat_alloc_bytes -= buf->asize;
#endif
		free(buf->data);
		free(buf); } }
コード例 #2
0
ファイル: net.c プロジェクト: aido/picocoin
void nc_conns_gc(struct net_child_info *nci, bool free_all)
{
	clist *dead = NULL;
	unsigned int n_gc = 0;

	/* build list of dead connections */
	unsigned int i;
	for (i = 0; i < nci->conns->len; i++) {
		struct nc_conn *conn = parr_idx(nci->conns, i);
		if (free_all || conn->dead)
			dead = clist_prepend(dead, conn);
	}

	/* remove and free dead connections */
	clist *tmp = dead;
	while (tmp) {
		struct nc_conn *conn = tmp->data;
		tmp = tmp->next;

		parr_remove(nci->conns, conn);
		nc_conn_free(conn);
		n_gc++;
	}

	clist_free(dead);

	log_debug("net: gc'd %u connections", n_gc);
}
コード例 #3
0
ファイル: brd.c プロジェクト: gitter-badger/picocoin
static void nc_conns_gc(struct net_child_info *nci, bool free_all)
{
	clist *dead = NULL;
	unsigned int n_gc = 0;
        
	/*nr of dead connections*/
	size_t nr_dead = 0;

	/* build list of dead connections */
	unsigned int i;
	for (i = 0; i < nci->conns->len; i++) {
		struct nc_conn *conn = parr_idx(nci->conns, i);
		if (free_all || conn->dead)
			dead = clist_prepend(dead, conn);
	}
        
	nr_dead = clist_length( dead );
	
	if (nr_dead){
		LOG("Nr of dead connections:%d\n", nr_dead);
	}

	/* remove and free dead connections */
	clist *tmp = dead;
	while (tmp) {
		struct nc_conn *conn = tmp->data;
		tmp = tmp->next;

		parr_remove(nci->conns, conn);
		nc_conn_free(conn);
		n_gc++;
	}

	clist_free(dead);

	if (debugging)
		fprintf(plog, "net: gc'd %u connections\n", n_gc);
}