inline static void pool_push(http1_protocol_s* protocol) { if (protocol == NULL) return; spn_lock(&http1_pool.lock); protocol->request.metadata.next = http1_pool.pool; http1_pool.pool = protocol; spn_unlock(&http1_pool.lock); }
inline static http1_protocol_s* pool_pop() { http1_protocol_s* prot; spn_lock(&http1_pool.lock); prot = http1_pool.pool; if (prot) http1_pool.pool = prot->request.metadata.next; spn_unlock(&http1_pool.lock); return prot; }
/* ***************************************************************************** Writing commands ***************************************************************************** */ static void redis_pub_send(void *e, void *uuid) { redis_engine_s *r = e; callbacks_s *cb; spn_lock(&r->lock); if (fio_list_any(r->callbacks)) { cb = fio_node2obj(callbacks_s, node, r->callbacks.next); if (cb->sent == 0) { cb->sent = 1; sock_write2(.uuid = r->pub, .buffer = (uint8_t *)(cb + 1), .length = cb->len, .move = 1, .dealloc = SOCK_DEALLOC_NOOP); }
static void http1_init(void) { static spn_lock_i inner_lock = SPN_LOCK_INIT; spn_lock(&inner_lock); if (http1_pool.memory == NULL) { // Allocate the memory http1_pool.memory = mmap(NULL, HTTP1_POOL_MEMORY_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (http1_pool.memory == NULL) return; // setup `atexit` cleanup rutine atexit(http1_cleanup); // initialize pool void* pos = http1_pool.memory; while (pos < http1_pool.memory + (HTTP1_POOL_MEMORY_SIZE - HTTP1_PROTOCOL_SIZE)) { pool_push(pos); pos += HTTP1_PROTOCOL_SIZE; } } spn_unlock(&inner_lock); }