Ejemplo n.º 1
0
pointer _lwmem_get_next_block_internal
   ( 
      /* [IN] the td whose blocks are being looked for */
      TD_STRUCT_PTR  td_ptr,

      /* [IN] the block last obtained */
      pointer        in_block_ptr
   )
{
    KERNEL_DATA_STRUCT_PTR kernel_data;
    LWMEM_POOL_STRUCT_PTR lwmem_pool_ptr;
    LWMEM_BLOCK_STRUCT_PTR block_ptr = in_block_ptr;
    LWMEM_BLOCK_STRUCT_PTR free_ptr;
    
    _GET_KERNEL_DATA(kernel_data);
    
    if (block_ptr == NULL) {
        // first item, start on first item in first pool
        lwmem_pool_ptr = kernel_data->KERNEL_LWMEM_POOL;
        block_ptr = lwmem_pool_ptr->POOL_ALLOC_START_PTR;
    } else {
        // continued, get lwmem pool from provided in_block_ptr
        block_ptr = GET_LWMEMBLOCK_PTR(in_block_ptr);
        lwmem_pool_ptr = block_ptr->POOL;
        
        block_ptr = (LWMEM_BLOCK_STRUCT_PTR)((uchar_ptr)block_ptr + block_ptr->BLOCKSIZE);
    }
    
    _int_disable();

    do {
        free_ptr = lwmem_pool_ptr->POOL_FREE_LIST_PTR;
        
        while ((uchar_ptr)block_ptr < (uchar_ptr)lwmem_pool_ptr->POOL_ALLOC_END_PTR){
            if (block_ptr->U.S.TASK_NUMBER == TASK_NUMBER_FROM_TASKID(td_ptr->TASK_ID)) {
                /* check for block is not free block */
                while (free_ptr && free_ptr < block_ptr) {
                    free_ptr = free_ptr->U.NEXTBLOCK;
                }
                
                if (free_ptr != block_ptr) {
                    /* This block is owned by the target task and it's not free block*/
                    _int_enable();
                    
                    return((pointer)((uchar_ptr)block_ptr + sizeof(LWMEM_BLOCK_STRUCT)));
                }
            }
            block_ptr = (LWMEM_BLOCK_STRUCT_PTR)((uchar_ptr)block_ptr + block_ptr->BLOCKSIZE);
        }
        
        // continue in next lwmem pool
        lwmem_pool_ptr = (LWMEM_POOL_STRUCT_PTR)(lwmem_pool_ptr->LINK.NEXT);
        block_ptr = lwmem_pool_ptr->POOL_ALLOC_START_PTR;
    } while (lwmem_pool_ptr != kernel_data->KERNEL_LWMEM_POOL); // repeat until processed lwmem pool is not first pool (pool list is circular list)
    
    _int_enable();

    return(NULL);  
}
Ejemplo n.º 2
0
pointer _lwmem_get_next_block_internal
   ( 
      /* [IN] the td whose blocks are being looked for */
      TD_STRUCT_PTR  td_ptr,

      /* [IN] the block last obtained */
      pointer        in_block_ptr
   )
{ /* Body */
   KERNEL_DATA_STRUCT_PTR kernel_data;
   LWMEM_POOL_STRUCT_PTR lwmem_pool_ptr;
   LWMEM_BLOCK_STRUCT_PTR block_ptr = in_block_ptr;
   LWMEM_BLOCK_STRUCT_PTR free_ptr;
   
   _GET_KERNEL_DATA(kernel_data);

   lwmem_pool_ptr = kernel_data->KERNEL_LWMEM_POOL;
   if (block_ptr == NULL) {
      block_ptr = lwmem_pool_ptr->POOL_ALLOC_START_PTR;
   /* Start CR 338 */
   } else {
      block_ptr = GET_LWMEMBLOCK_PTR(in_block_ptr);
      block_ptr = (LWMEM_BLOCK_STRUCT_PTR)((uchar_ptr)block_ptr + 
         block_ptr->BLOCKSIZE);
   /* End CR 338 */
   } /* Endif */

    _int_disable();
    free_ptr = lwmem_pool_ptr->POOL_FREE_LIST_PTR;

    while ((uchar_ptr)block_ptr < (uchar_ptr)lwmem_pool_ptr->POOL_ALLOC_END_PTR){
        if (block_ptr->U.S.TASK_NUMBER == TASK_NUMBER_FROM_TASKID(td_ptr->TASK_ID)) {
            /* check for block is not free block */
            while (free_ptr && free_ptr < block_ptr) {
                free_ptr = free_ptr->U.NEXTBLOCK;
            }
            
            if (free_ptr != block_ptr) {
                /* This block is owned by the target task and it's not free block*/
                _int_enable();
            
                return((pointer)((uchar_ptr)block_ptr + sizeof(LWMEM_BLOCK_STRUCT)));
            }
        }
        block_ptr = (LWMEM_BLOCK_STRUCT_PTR)((uchar_ptr)block_ptr + block_ptr->BLOCKSIZE);
    }
    _int_enable();

    return(NULL);  
}