struct vector vector_new() { struct vector v = { v.data = cv_malloc(VECTOR_BASIC_SIZE * sizeof(void*)), v.size = 0, v.capacity = VECTOR_BASIC_SIZE, }; return v; }
struct connection *conn_create(struct context *ctx) { struct connection *conn; if ((conn = TAILQ_FIRST(&ctx->conns)) != NULL && conn->fd == -1) { LOG(DEBUG, "connection get cache"); TAILQ_REMOVE(&ctx->conns, conn, next); ctx->mstats.free_conns--; } else { conn = cv_malloc(sizeof(struct connection)); } conn_init(conn, ctx); ctx->mstats.conns++; return conn; }
struct conn_info *conn_info_create(struct context *ctx) { struct conn_info *info; if (!STAILQ_EMPTY(&ctx->free_conn_infoq)) { info = STAILQ_FIRST(&ctx->free_conn_infoq); STAILQ_REMOVE_HEAD(&ctx->free_conn_infoq, next); ctx->mstats.free_conn_info--; } else { info = cv_malloc(sizeof(struct conn_info)); // init iov here memset(&info->iov, 0, sizeof(info->iov)); } conn_info_init(info); ctx->mstats.conn_info++; return info; }
static struct mbuf *mbuf_create(struct context *ctx) { struct mbuf *mbuf; uint8_t *buf; if (!TAILQ_EMPTY(&ctx->free_mbufq)) { mbuf = TAILQ_FIRST(&ctx->free_mbufq); TAILQ_REMOVE(&ctx->free_mbufq, mbuf, next); ctx->mstats.free_buffers--; } else { buf = (uint8_t*)cv_malloc(config.bufsize); if (buf == NULL) { return NULL; } mbuf = (struct mbuf *)(buf + ctx->mbuf_offset); } return mbuf; }