library/src/mmap/BP-MMapSlabAllocator.cc
// Attempts to free a slab entry.
Attempts to free a slab entry.
Attempts to free a slab entry .
BP_ERROR_T BP_SlabFree(P_BP_MMAP_SLAB_ALLOCATOR allocator, P_BP_MMAP_SLAB_ENTRY_HDR entry_ptr)
{
	if(!allocator)
		return ERR_FAILURE;
	if(!entry_ptr)
		return ERR_FAILURE;
	BP_SLAB_TABLE_LOCK_SEM(allocator->lock);
	if(!BP_FLAG_IS_SET(entry_ptr->flags, BP_MMAP_SLAB_ENTRY_INFO_IS_GROUP_TOP))
	{
		BP_SLAB_TABLE_UNLOCK_SEM(allocator->lock);
		return ERR_FAILURE;
	}
	BP_SlabAllocUpdateInfo(allocator, BP_TRUE);
	BP_BOOL has_next = BP_FALSE;
	P_BP_MMAP_SLAB_ENTRY_HDR last_hdr = NULL;
	 walk the entries and free (aka unmark/mark) entries
	BP_SLAB_ALLOCATOR_ITER_LOOP(allocator, entry_ptr)
	{
		 check flags are set
		if(BP_FLAG_IS_SET(allocator->curr_entry->flags, BP_MMAP_SLAB_ENTRY_INFO_NEXT_IS_GROUPED))
		{
			 printf("\n Chunk has next?");
			has_next = BP_TRUE;
		}
		if(!last_hdr)
		{
			last_hdr = allocator->curr_entry;
		}
		else
		{
			if(last_hdr == allocator->curr_entry)
				printf("\n DUPLICATE CHUNKS DETECTED DURING FREE, ERROR");
		}
		 zero out flags first
		allocator->curr_entry->flags = BP_MMAP_SLAB_ENTRY_INFO_NONE;
		 after the chunk is updated set the flag indicating that the chunk is available for use
		BP_SET_FLAG(allocator->curr_entry->flags, BP_MMAP_SLAB_ENTRY_INFO_AVAILABLE);
		 break if there is no next
		if(!has_next)
			break;
		 overide flag
		has_next = BP_FALSE;
		last_hdr = allocator->curr_entry;
	}
	 unlock allocator before exit
	BP_SLAB_TABLE_UNLOCK_SEM(allocator->lock);
	 return indicating success
	return ERR_SUCCESS;
}
BP_ERROR_T BP_SlabFree ( P_BP_MMAP_SLAB_ALLOCATOR allocator , P_BP_MMAP_SLAB_ENTRY_HDR entry_ptr ) { if ( ! allocator ) return ERR_FAILURE ; if ( ! entry_ptr ) return ERR_FAILURE ; BP_SLAB_TABLE_LOCK_SEM ( allocator -> lock ) ; if ( ! BP_FLAG_IS_SET ( entry_ptr -> flags , BP_MMAP_SLAB_ENTRY_INFO_IS_GROUP_TOP ) ) { BP_SLAB_TABLE_UNLOCK_SEM ( allocator -> lock ) ; return ERR_FAILURE ; } BP_SlabAllocUpdateInfo ( allocator , BP_TRUE ) ; BP_BOOL has_next = BP_FALSE ; P_BP_MMAP_SLAB_ENTRY_HDR last_hdr = NULL ; BP_SLAB_ALLOCATOR_ITER_LOOP ( allocator , entry_ptr ) { if ( BP_FLAG_IS_SET ( allocator -> curr_entry -> flags , BP_MMAP_SLAB_ENTRY_INFO_NEXT_IS_GROUPED ) ) { has_next = BP_TRUE ; } if ( ! last_hdr ) { last_hdr = allocator -> curr_entry ; } else { if ( last_hdr == allocator -> curr_entry ) printf ( " \n " ) ; } allocator -> curr_entry -> flags = BP_MMAP_SLAB_ENTRY_INFO_NONE ; BP_SET_FLAG ( allocator -> curr_entry -> flags , BP_MMAP_SLAB_ENTRY_INFO_AVAILABLE ) ; if ( ! has_next ) break ; has_next = BP_FALSE ; last_hdr = allocator -> curr_entry ; } BP_SLAB_TABLE_UNLOCK_SEM ( allocator -> lock ) ; return ERR_SUCCESS ; }
Attempts to free a slab entry.
Attempts to free a slab entry .
// ensure we have an allocator // lock the allocator before use // First check to make sure that the entry pointer // is the top of a group. // unlock the allocator // return indicating failure // update allocation info // set next to false // // walk the entries and free (aka unmark/mark) entries // check flags are set // printf("\n Chunk has next?"); // zero out flags first // after the chunk is updated set the flag indicating that the chunk is available for use // break if there is no next // overide flag // unlock allocator before exit // return indicating success