Example #1
0
void
dsm_get_meta
(
  dsm_item_type * item_ptr,
  void * meta_ptr,
  uint32 size
)
{
  dsm_pool_mgmt_table_type *table;

  ASSERT( item_ptr != NULL && meta_ptr != NULL );
  ASSERT( DSM_POOL_ITEM_SIZE(item_ptr->pool_id) == 0 );

#ifdef FEATURE_DSM_MEM_CHK_EXPENSIVE_ALWAYS_VERIFY_PACKET
  dsmi_verify_packet(item_ptr);
#endif /* FEATURE_DSM_MEM_CHK_EXPENSIVE_ALWAYS_VERIFY_PACKET */

#ifdef FEATURE_DSM_MEM_CHK
  dsmi_verify_pool_id(item_ptr->pool_id);
#endif

  table = (dsm_pool_mgmt_table_type *)item_ptr->pool_id;
  ASSERT( table->pad_size >= size && size > 0 );
  
  memcpy( meta_ptr, (uint8*)(item_ptr) - size, size);

} /* dsm_get_meta */
/*===========================================================================

FUNCTION dsmutili_new_packet

DESCRIPTION
    Based on the dsm_size_requested, this function will allocate a dsm items
    which can hold 'dsm_size_requested'.
    This function will do necessary chaining of DSM items if requested size
    doesnt fit in one DSM item.
    
    Total Size of the DSM chain is expected to be equal or greater than
    requested size.

DEPENDENCIES
    None

PARAMETERS
  pool_id - DSM Pool from which new item should be allocated

  dsm_size_requested - requested size of the buffer

RETURN VALUE
  Chain of DSM pointers w/ empty payload such that total size of chain is 
  equal to or greater than dsm_size_requested. It returns NULL if it fails 
  to allocate requested size.

SIDE EFFECTS
  Caller of this function is expected to have necessary handling whenever this
  function returns chain of DSM items.

===========================================================================*/
dsm_item_type *dsmutili_new_packet
(
  dsm_mempool_id_type pool_id,
  uint32 dsm_size_requested,
  const char * file,
  uint32 line
)
{
  dsm_item_type *head_dsm_ptr = NULL, *tail_dsm_ptr = NULL;
  dsm_item_type *allocated_dsm_ptr = NULL;
  int16 remaining_size = (int16) dsm_size_requested;
  uint16 allocated_dsm_size = DSM_POOL_ITEM_SIZE(pool_id);

  while (remaining_size > 0)
  {
    if (NULL == (allocated_dsm_ptr = dsmi_new_buffer(pool_id, file, line)))
    {
      /* No free DSM items are available in a given pool id,
         exit out of the loop */
      break;
    }

    if (remaining_size != (int16) dsm_size_requested)
    {
      tail_dsm_ptr->pkt_ptr = allocated_dsm_ptr;
      tail_dsm_ptr = allocated_dsm_ptr;
    }
    else
    {
      head_dsm_ptr = allocated_dsm_ptr;
      tail_dsm_ptr = allocated_dsm_ptr;
    }

    /* update remaining size */
    remaining_size -= allocated_dsm_size;
  }

  /* check whether a given pool has run out of the free items.
     If yes, then free any allocated dsm items */
  if (NULL != allocated_dsm_ptr)
  {
    return(head_dsm_ptr);
  }
  else
  {
    dsm_free_packet(&head_dsm_ptr);
    head_dsm_ptr = NULL;
    return(head_dsm_ptr);
  }
}
Example #3
0
void
dsmi_set_meta
(
  dsm_item_type * item_ptr,
  void * meta_ptr,
  uint32 size,
  const char * file,
  uint32 line
)
{
  
  dsm_pool_mgmt_table_type *table;

  ASSERT( item_ptr != NULL && meta_ptr != NULL );
  ASSERT( DSM_POOL_ITEM_SIZE(item_ptr->pool_id) == 0 );

#ifdef FEATURE_DSM_MEM_CHK_EXPENSIVE_ALWAYS_VERIFY_PACKET
  dsmi_verify_packet(item_ptr);
#endif /* FEATURE_DSM_MEM_CHK_EXPENSIVE_ALWAYS_VERIFY_PACKET */

#ifdef FEATURE_DSM_MEM_CHK
  dsmi_verify_pool_id(item_ptr->pool_id);
#endif

#ifdef FEATURE_DSM_MEM_CHK_QUEUE_CACHE_LENGTH
  ASSERT(item_ptr->enqueued_packet_length == 0);
#endif

  table = (dsm_pool_mgmt_table_type *)item_ptr->pool_id;
  ASSERT( table->pad_size >= size && size > 0 );
  
  memcpy( (uint8*)(item_ptr) - size,  meta_ptr, size );

#ifdef FEATURE_DSM_MEM_CHK
  dsmi_touch_item(item_ptr, file, line);
#endif /* FEATURE_DSM_MEM_CHK */
  
} /* dsm_set_meta */