示例#1
0
/*
* delete_node: Remove a free block pointer from a segregated list. If
* necessary, adjust pointers in predecessor and successor blocks
* or reset the list head.
*/
static void delete_node(void *ptr) {
int list = 0;
size_t size = GET_SIZE(HEAD(ptr));
/* Select segregated list */
while ((list < LISTS - 1) && (size > 1)) {
size >>= 1;
list++;
}
if (PRED(ptr) != NULL) {
if (SUCC(ptr) != NULL) {
SET_PTR(SUCC_PTR(PRED(ptr)), SUCC(ptr));
SET_PTR(PRED_PTR(SUCC(ptr)), PRED(ptr));
} else {
SET_PTR(SUCC_PTR(PRED(ptr)), NULL);
free_lists[list] = PRED(ptr);
}
} else {
if (SUCC(ptr) != NULL) {
SET_PTR(PRED_PTR(SUCC(ptr)), NULL);
} else {
free_lists[list] = NULL;
}
}
return;
}
/* {{{ proto XmlResults execute() 
 */
PHP_DBXML_METHOD_BEGIN(XmlIndexLookup, execute)
{
  zval *zqc,*zt;
  long flags = 0;
  PHP_DBXML_STUFFED_THIS(XmlIndexLookup);

#define SET_PTR(expr)  \
  XmlQueryContext c = php_dbxml_get_XmlQueryContext_object_pointer(zqc TSRMLS_CC); \
  XmlResults r = expr; \
  object_init_ex(return_value, php_dbxml_XmlResults_ce); \
  php_dbxml_set_XmlResults_object_pointer(return_value, r TSRMLS_CC);

  if (SUCCESS == zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC,
      "O|l", &zqc, php_dbxml_XmlQueryContext_ce, &flags)) {

    SET_PTR(This.execute(c, flags));
    php_dbxml_set_XmlResults_object_pointer(return_value, r TSRMLS_CC);
  } else if (SUCCESS == zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC,
      "OO", &zt, php_dbxml_XmlTransaction_ce, &zqc, php_dbxml_XmlQueryContext_ce, &flags)) {

    XmlTransaction t = php_dbxml_get_XmlTransaction_object_pointer(zt TSRMLS_CC);
    SET_PTR(This.execute(t, c, flags));	  
  } else {
    WRONG_PARAM_COUNT;
  } 
} PHP_DBXML_METHOD_END()
/*
 * delete_node: Remove a free block pointer from a segregated list. If
 *              necessary, adjust pointers in predecessor and successor blocks
 *              or reset the list head.
 */
static void delete_node(void *ptr) {
  //int list = 0;
  size_t size = GET_SIZE(HDRP(ptr));

  /* Select segregated list */
 /* while ((list < LISTS - 1) && (size > 1)) {
    size >>= 1;
    list++;
  }*/
 
  if (PRED(ptr) != NULL) {
    if (SUCC(ptr) != NULL) {
      SET_PTR(SUCC_PTR(PRED(ptr)), SUCC(ptr));
      SET_PTR(PRED_PTR(SUCC(ptr)), PRED(ptr));
    } else {
      SET_PTR(SUCC_PTR(PRED(ptr)), NULL);
     // free_lists[list] = PRED(ptr);
    }
  } else {
    //intptr_t header1 = header + SUCC(ptr);
    if (SUCC(ptr) != NULL) {
      SET_PTR(PRED_PTR(SUCC(ptr)), NULL);
      head = SUCC(ptr);
    } else {
      head = 0;
     // free_lists[list] = NULL;
    }
  }

  return;
}
示例#4
0
/*
* insert_node - Insert a block pointer into a segregated list. Lists are
* segregated by byte size, with the n-th list spanning byte
* sizes 2^n to 2^(n+1)-1. Each individual list is sorted by
* pointer address in ascending order.
*/
static void insert_node(void *ptr, size_t size) {
int list = 0;
void *search_ptr = ptr;
void *insert_ptr = NULL;
/* Select segregated list */
while ((list < LISTS - 1) && (size > 1)) {
size >>= 1;
list++;
}
/* Select location on list to insert pointer while keeping list
organized by byte size in ascending order. */
search_ptr = free_lists[list];
while ((search_ptr != NULL) && (size > GET_SIZE(HEAD(search_ptr)))) {
insert_ptr = search_ptr;
search_ptr = PRED(search_ptr);
}
/* Set predecessor and successor */
if (search_ptr != NULL) {
if (insert_ptr != NULL) {
SET_PTR(PRED_PTR(ptr), search_ptr);
SET_PTR(SUCC_PTR(search_ptr), ptr);
SET_PTR(SUCC_PTR(ptr), insert_ptr);
SET_PTR(PRED_PTR(insert_ptr), ptr);
} else {
SET_PTR(PRED_PTR(ptr), search_ptr);
SET_PTR(SUCC_PTR(search_ptr), ptr);
SET_PTR(SUCC_PTR(ptr), NULL);
/* Add block to appropriate list */
free_lists[list] = ptr;
}
} else {
if (insert_ptr != NULL) {
SET_PTR(PRED_PTR(ptr), NULL);
SET_PTR(SUCC_PTR(ptr), insert_ptr);
SET_PTR(PRED_PTR(insert_ptr), ptr);
} else {
SET_PTR(PRED_PTR(ptr), NULL);
SET_PTR(SUCC_PTR(ptr), NULL);
/* Add block to appropriate list */
free_lists[list] = ptr;
}
}
return;
}
示例#5
0
static void insert_node(void *ptr, size_t size) {
    int list = 0;
    void *search_ptr = ptr;
    void *insert_ptr = NULL;
    
    // Select segregated list 
    while ((list < LISTLIMIT - 1) && (size > 1)) {
        size >>= 1;
        list++;
    }
    
    // Keep size ascending order and search
    search_ptr = segregated_free_lists[list];
    while ((search_ptr != NULL) && (size > GET_SIZE(HDRP(search_ptr)))) {
        insert_ptr = search_ptr;
        search_ptr = PRED(search_ptr);
    }
    
    // Set predecessor and successor 
    if (search_ptr != NULL) {
        if (insert_ptr != NULL) {
            SET_PTR(PRED_PTR(ptr), search_ptr);
            SET_PTR(SUCC_PTR(search_ptr), ptr);
            SET_PTR(SUCC_PTR(ptr), insert_ptr);
            SET_PTR(PRED_PTR(insert_ptr), ptr);
        } else {
            SET_PTR(PRED_PTR(ptr), search_ptr);
            SET_PTR(SUCC_PTR(search_ptr), ptr);
            SET_PTR(SUCC_PTR(ptr), NULL);
            segregated_free_lists[list] = ptr;
        }
    } else {
        if (insert_ptr != NULL) {
            SET_PTR(PRED_PTR(ptr), NULL);
            SET_PTR(SUCC_PTR(ptr), insert_ptr);
            SET_PTR(PRED_PTR(insert_ptr), ptr);
        } else {
            SET_PTR(PRED_PTR(ptr), NULL);
            SET_PTR(SUCC_PTR(ptr), NULL);
            segregated_free_lists[list] = ptr;
        }
    }
    
    return;
}
示例#6
0
UINT CFrontEnd::uiBuildOCLKernels()
{
  //allocate the required memory
  size_t           uiReqQueueSize  = OCL_REQ_QUEUE_SIZE*sizeof(TQueuedRequest); 
  size_t           uiNodePoolSize  = OCL_NODE_POOL_SIZE*sizeof(TLLNode); 
  size_t           uiHashTableSize = OCL_HASH_TABLE_SIZE*sizeof(TLLNode); 
  size_t           uiMiscDataSize  = sizeof(TMiscData);
  
  size_t           uiSVMSize = uiReqQueueSize  + 
                               uiNodePoolSize  + 
                               uiHashTableSize +
                               uiMiscDataSize;
  
  cl_svm_mem_flags tSVMFlags = CL_MEM_READ_WRITE |
                               CL_MEM_SVM_FINE_GRAIN_BUFFER;
                               //CL_MEM_SVM_ATOMICS;
  
  pSVMBuf     = (void *)clSVMAlloc(pOclContext->oclContext,
				   tSVMFlags,
				   uiSVMSize,
				   0);
  if(pSVMBuf == NULL)
    {
      std::cout << "SVMAlloc failed." << std::endl;
      return HTS_NOT_OK;
    }
  
  //allocate different svm pointers
  pOclReqQueue = (TQueuedRequest *)pSVMBuf; 
  pHashTable   = (TLLNode*)((char *)pOclReqQueue + uiReqQueueSize);
  pNodePool    = (TLLNode*)((char *)pHashTable   + uiHashTableSize);
  pMiscData    = (TMiscData*)((char *)pNodePool  + uiNodePoolSize);

  //make node pool and hash table to be same
  pNodePool    = pHashTable;
  
  //initialize svm buffers -- Hash table 
  for(UINT i = 0; i < OCL_HASH_TABLE_SIZE; ++i) 
    {
	  for(UINT j = 0; j < OCL_WG_SIZE; j++)
		  pNodePool[i].pE[j] = 0 ;
      pNodePool[i].uiNext = 0; 
    }

  pMiscData->uiHeadIndex = OCL_HASH_TABLE_SIZE; 

  cl_uint uiStartIndex = OCL_HASH_TABLE_SIZE;
  cl_uint uiEndIndex   = OCL_HASH_TABLE_SIZE + OCL_NODE_POOL_SIZE -1;  

  for(cl_uint i = uiStartIndex; i < uiEndIndex; ++i) 
    {
      /* set the pointer to next and also set free bit */
      cl_uint j = SET_PTR(i+1);
      j         = SET_FBIT(j);   
      pNodePool[i].uiNext = j;
    }  
  pNodePool[uiEndIndex].uiNext = 0;
  
  //create the program
  std::string sourceStr;
  cl_uint iStatus     = (cl_int)(uiConvertToString(FILENAME, sourceStr));
  const char *source  = sourceStr.c_str();
  size_t sourceSize[] = {strlen(source)};
  
  oclProgram = clCreateProgramWithSource(pOclContext->oclContext,
					 1,
					 &source,
					 sourceSize,
					 NULL);

 
  std::cout << "building program" << std::endl;

  const char* options = "-I. -cl-std=CL2.0";
  iStatus = clBuildProgram(oclProgram,
			   1,
			   pOclContext->pOclDevices,
			   options,
			   NULL,
			   NULL);
				 
  if(iStatus != CL_SUCCESS)
    {
      //get the build error
      size_t uiBuildLogSize;
      clGetProgramBuildInfo(oclProgram,
			    pOclContext->pOclDevices[0],
			    CL_PROGRAM_BUILD_LOG,
			    0,
			    NULL,
			    &uiBuildLogSize);

      char *pBuildLog = (char *)malloc(uiBuildLogSize*sizeof(char));

      clGetProgramBuildInfo(oclProgram,
			    pOclContext->pOclDevices[0],
			    CL_PROGRAM_BUILD_LOG,
			    uiBuildLogSize,
			    (void *)pBuildLog,
			    NULL);


      std::cout << "failed to build program." << std::endl;
      std::cout << "BUILD LOG---" << std::endl;
      std::cout << pBuildLog << std::endl;
      std::cout << "------------" << std::endl;
      return HTS_NOT_OK;
    }

  /* create kernels */
  std::cout << "creating kernels" << std::endl;  
  oclKernel = clCreateKernel(oclProgram,
			     "HTSTopKernel",
			     NULL);  
  
  return HTS_OK;
}
示例#7
0
文件: salloc.c 项目: ahamid/sartoris
void *salloc(int id, int type)
{	
	if(ammount[type] == max_ammount[type]) 
		return NULL;
		
	if(type == SALLOC_TSK || type == SALLOC_THR || type == SALLOC_SMO)
	{		
		switch(type)
		{
			case SALLOC_TSK:
				if(TST_PTR(id,tsk)) return NULL;
				break;
			case SALLOC_THR:				
				if(TST_PTR(id,thr)) return NULL;
				break;
			case SALLOC_SMO:
				if(TST_PTR(id,smo)) return NULL;
				break;
			default:
				break;		
		}

		// allocate index first, for csalloc is not always atomic
		if(!index_alloc(id, ALLOC2IDX(type)))
			return NULL;
		
		ammount[type]++; // increment now, for atomicity might be broken on csalloc

		void * ptr = csalloc(SALLOC2CONT_TYPE(type)); 

		if(ptr == NULL)
		{
			ammount[type]--;
			index_free(id, ALLOC2IDX(type));
			return NULL;
		}

		switch(type)
		{
			case SALLOC_TSK:
				SET_PTR(id,tsk,ptr);
				break;
			case SALLOC_THR:
				SET_PTR(id,thr,ptr);
				break;
			case SALLOC_SMO:
				SET_PTR(id,smo,ptr);
				break;
			default:
				break;		
		}

		return ptr;
	}
	else
	{
		// messages and ports wont have an ID
		ammount[type]++; // increment now, for atomicity might be broken on csalloc

		void *ptr = csalloc(SALLOC2CONT_TYPE(type));	

		if(ptr == NULL)
			ammount[type]--;

		return ptr;
	}
}
static void insert_node(void *ptr, size_t size) {
 // int list = 0;
  //void *search_ptr = ptr;
  //void *insert_ptr = NULL;
  char *bp;
  if ( head!= 0) {
	  bp = head;
	  SET_PTR(PRED_PTR(bp), ptr);
	  SET_PTR(SUCC_PTR(ptr), bp);      
	  SET_PTR(PRED_PTR(ptr), NULL);
      head = ptr; 
  } else {
	  head = ptr;
      SET_PTR(SUCC_PTR(ptr), NULL);
      SET_PTR(PRED_PTR(ptr), NULL);
      //(SUCC(ptr), NULL);
      //PUT(PRED(ptr), NULL);
	  //PUT(PRED_PTR(ptr),NULL);
	  //PUT(SUCC_PTR(ptr),NULL);
  }

      

  /* Select segregated list */
 /* while ((list < LISTS - 1) && (size > 1)) {
    size >>= 1;
    list++;
  }*/

  /* Select location on list to insert pointer while keeping list
     organized by byte size in ascending order. */
 /* search_ptr = free_lists[list];
  while ((search_ptr != NULL) && (size > GET_SIZE(HEAD(search_ptr)))) {
    insert_ptr = search_ptr;
    search_ptr = PRED(search_ptr);
  }

  // Set predecessor and successor 
  if (search_ptr != NULL) {
    if (insert_ptr != NULL) {
      SET_PTR(PRED_PTR(ptr), search_ptr);
      SET_PTR(SUCC_PTR(search_ptr), ptr);
      SET_PTR(SUCC_PTR(ptr), insert_ptr);
      SET_PTR(PRED_PTR(insert_ptr), ptr);
    } else {
      SET_PTR(PRED_PTR(ptr), search_ptr);
      SET_PTR(SUCC_PTR(search_ptr), ptr);
      SET_PTR(SUCC_PTR(ptr), NULL);

      // Add block to appropriate list 
      free_lists[list] = ptr;
    }
  } else {
    if (insert_ptr != NULL) {
      SET_PTR(PRED_PTR(ptr), NULL);
      SET_PTR(SUCC_PTR(ptr), insert_ptr);
      SET_PTR(PRED_PTR(insert_ptr), ptr);
    } else {
      SET_PTR(PRED_PTR(ptr), NULL);
      SET_PTR(SUCC_PTR(ptr), NULL);

      // Add block to appropriate list 
      free_lists[list] = ptr;
    }
  } */

  return;
}