mtcp/src/buf_ring.c
// buf ring must be size power of 2
buf ring must be size power of 2
buf ring must be size power of 2
struct buf_ring *
buf_ring_alloc(int count)
{
  assert((count&(count-1)) == 0);
	struct buf_ring *br;
#ifdef COMPILE_WITH_INTEL_SGX
	br = untrusted_malloc(sizeof(struct buf_ring) + count*sizeof(caddr_t));
#else
	br = malloc(sizeof(struct buf_ring) + count*sizeof(caddr_t));
#endif
	if (br == NULL)
		return (NULL);
	br->br_prod_size = br->br_cons_size = count;
	br->br_prod_mask = br->br_cons_mask = count-1;
	br->br_prod_head = br->br_cons_head = 0;
	br->br_prod_tail = br->br_cons_tail = 0;
	return (br);
}
struct buf_ring * buf_ring_alloc ( int count ) { assert ( ( count & ( count - 1 ) ) == 0 ) ; struct buf_ring * br ; #ifdef COMPILE_WITH_INTEL_SGX br = untrusted_malloc ( sizeof ( struct buf_ring ) + count * sizeof ( caddr_t ) ) ; #else br = malloc ( sizeof ( struct buf_ring ) + count * sizeof ( caddr_t ) ) ; #endif if ( br == NULL ) return ( NULL ) ; br -> br_prod_size = br -> br_cons_size = count ; br -> br_prod_mask = br -> br_cons_mask = count - 1 ; br -> br_prod_head = br -> br_cons_head = 0 ; br -> br_prod_tail = br -> br_cons_tail = 0 ; return ( br ) ; }
buf ring must be size power of 2
buf ring must be size power of 2