/* Allocates a dtr from the reserve array. If the reserve array is empty, it swaps the reserve and free arrays.  */
enum vxge_hw_status vxge_hw_channel_dtr_alloc(struct __vxge_hw_channel *channel, void **dtrh)
/* Allocates a dtr from the reserve array. If the reserve array is empty, it swaps the reserve and free arrays.  */
enum vxge_hw_status vxge_hw_channel_dtr_alloc(struct __vxge_hw_channel *channel, void **dtrh)
{
	void **tmp_arr;
	if (channel->reserve_ptr - channel->reserve_top > 0) {
_alloc_after_swap:
		*dtrh =	channel->reserve_arr[--channel->reserve_ptr];
		return VXGE_HW_OK;
	}
	if (channel->length - channel->free_ptr > 0) {
		tmp_arr	= channel->reserve_arr;
		channel->reserve_arr = channel->free_arr;
		channel->free_arr = tmp_arr;
		channel->reserve_ptr = channel->length;
		channel->reserve_top = channel->free_ptr;
		channel->free_ptr = channel->length;
		channel->stats->reserve_free_swaps_cnt++;
		goto _alloc_after_swap;
	}
	channel->stats->full_cnt++;
	*dtrh =	NULL;
	return VXGE_HW_INF_OUT_OF_DESCRIPTORS;
}