library/src/mmap/BP-MMapSlabAllocator.cc
// attempt to checkout entries.  This should only ever be called via BP_SlabAlloc.  SlabAlloc
// locks the allocator by itself, which prevents the need for this routine to lock anything.  That
// said, don't use this routine unsafely w/o locks if you implement it in your own code.
attempt to checkout entries.  This should only ever be called via BP_SlabAlloc.  SlabAlloc
locks the allocator by itself, which prevents the need for this routine to lock anything.  That
said, don't use this routine unsafely w/o locks if you implement it in your own code.
attempt to checkout entries . This should only ever be called via BP_SlabAlloc . SlabAlloc locks the allocator by itself which prevents the need for this routine to lock anything . That said don ' t use this routine unsafely w / o locks if you implement it in your own code .
BP_ERROR_T BP_SlabAllocCheckoutEntries
(
	P_BP_MMAP_SLAB_ALLOCATOR allocator,
	P_BP_MMAP_SLAB_ENTRY_HDR start_entry,
	size_t                   entry_n
)
{
	if(!allocator)
		return ERR_FAILURE;
	if(!start_entry)
		return ERR_FAILURE;
	if(!entry_n)
		return ERR_FAILURE;
	BP_BOOL first_entry = BP_FALSE;
	size_t total_marked_n = 0;
	BP_SLAB_ALLOCATOR_ITER_LOOP(allocator, start_entry)
	{
		if(!BP_FLAG_IS_SET(allocator->curr_entry->flags, BP_MMAP_SLAB_ENTRY_INFO_AVAILABLE))
			return ERR_FAILURE;
		allocator->curr_entry->flags = BP_MMAP_SLAB_ENTRY_INFO_NONE;
		BP_SET_FLAG(allocator->curr_entry->flags, BP_MMAP_SLAB_ENTRY_INFO_IN_USE);
		if(first_entry == BP_FALSE)
		{
			first_entry = BP_TRUE;
			BP_SET_FLAG(allocator->curr_entry->flags, BP_MMAP_SLAB_ENTRY_INFO_IS_GROUP_TOP);
			if(entry_n > 1)
			{
				BP_SET_FLAG(allocator->curr_entry->flags, BP_MMAP_SLAB_ENTRY_INFO_NEXT_IS_GROUPED);
			}
		}
		else
		{
			BP_SET_FLAG(allocator->curr_entry->flags, BP_MMAP_SLAB_ENTRY_INFO_IN_USE);
			BP_SET_FLAG(allocator->curr_entry->flags, BP_MMAP_SLAB_ENTRY_INFO_PREV_IS_GROUPED);
			if((total_marked_n+1) < entry_n)
			{
				BP_SET_FLAG(allocator->curr_entry->flags, BP_MMAP_SLAB_ENTRY_INFO_NEXT_IS_GROUPED);
			}
		}
		total_marked_n++;
		if(total_marked_n == entry_n)
			break;
	}
	return ERR_SUCCESS;
}
BP_ERROR_T BP_SlabAllocCheckoutEntries ( P_BP_MMAP_SLAB_ALLOCATOR allocator , P_BP_MMAP_SLAB_ENTRY_HDR start_entry , size_t entry_n ) { if ( ! allocator ) return ERR_FAILURE ; if ( ! start_entry ) return ERR_FAILURE ; if ( ! entry_n ) return ERR_FAILURE ; BP_BOOL first_entry = BP_FALSE ; size_t total_marked_n = 0 ; BP_SLAB_ALLOCATOR_ITER_LOOP ( allocator , start_entry ) { if ( ! BP_FLAG_IS_SET ( allocator -> curr_entry -> flags , BP_MMAP_SLAB_ENTRY_INFO_AVAILABLE ) ) return ERR_FAILURE ; allocator -> curr_entry -> flags = BP_MMAP_SLAB_ENTRY_INFO_NONE ; BP_SET_FLAG ( allocator -> curr_entry -> flags , BP_MMAP_SLAB_ENTRY_INFO_IN_USE ) ; if ( first_entry == BP_FALSE ) { first_entry = BP_TRUE ; BP_SET_FLAG ( allocator -> curr_entry -> flags , BP_MMAP_SLAB_ENTRY_INFO_IS_GROUP_TOP ) ; if ( entry_n > 1 ) { BP_SET_FLAG ( allocator -> curr_entry -> flags , BP_MMAP_SLAB_ENTRY_INFO_NEXT_IS_GROUPED ) ; } } else { BP_SET_FLAG ( allocator -> curr_entry -> flags , BP_MMAP_SLAB_ENTRY_INFO_IN_USE ) ; BP_SET_FLAG ( allocator -> curr_entry -> flags , BP_MMAP_SLAB_ENTRY_INFO_PREV_IS_GROUPED ) ; if ( ( total_marked_n + 1 ) < entry_n ) { BP_SET_FLAG ( allocator -> curr_entry -> flags , BP_MMAP_SLAB_ENTRY_INFO_NEXT_IS_GROUPED ) ; } } total_marked_n ++ ; if ( total_marked_n == entry_n ) break ; } return ERR_SUCCESS ; }
attempt to checkout entries.
attempt to checkout entries .
// ensure we have an allocator // set if this is the first entry // number of chunks marked for checkout // iterate from the start entry // the allocator entry must be available for checkout // remove any lingering flags // mark the entry in use // mark the first entry as top if it's the top entry // set the flag // since this is the first entry, mark as group top // set next group flag if necessary // mark entry as in use // mark previous as grouped // exit if we hit our cap // increment the total number of marked items // exit if we hit our cap // return indicating success