Exemplo n.º 1
0
void 
EasyIocp::InitThreadPool()
{
	//初始化线程池
	int num = GetProcessorsNum();

	InitializeThreadpoolEnvironment(&tpCBE_);

	worksNum_ = num;
	ptpWorks_ = (PTP_WORK*)SysMalloc(sizeof(PTP_WORK) * worksNum_);
	workArgs_ = (EasyIocpStruct::WORK_ARG*)SysMalloc(sizeof(EasyIocpStruct::WORK_ARG) * worksNum_);
	if(!ptpWorks_ || !workArgs_) {
		print("EasyIocp::Construct: SysMalloc failed.");
	}
	assert(ptpWorks_ != NULL);
	assert(workArgs_ != NULL);

	for(int i = 0; i < worksNum_; ++i) {
		workArgs_[i].id = i;
		workArgs_[i].iocpModel = this;
		ptpWorks_[i] = CreateThreadpoolWork(TPCallBack, (PVOID)&workArgs_[i], &tpCBE_);
		SubmitThreadpoolWork(ptpWorks_[i]);
	}

	print("EasyIocp::InitThreadPool: init thread pool successfully. num: %d.", worksNum_);
}
Exemplo n.º 2
0
zOPER_EXPORT zLONG OPERATION
WRKS_Init( zPVOID *ppAnchor )
{
   T_WRKSANCHOR *pAnchor;

   pAnchor = SysMalloc( sizeof( T_WRKSANCHOR ) );
   if ( pAnchor == NULL )
      return( -1 );

   pAnchor->pFirstBlock = SysMalloc( sizeof( T_MEMBLOCK ) );
   if ( pAnchor->pFirstBlock == NULL )
   {
      SysFree( pAnchor );
      return( -1 );
   }

   pAnchor->pFirstBlock->pData = SysMalloc( WRKS_INIT_SIZE );
   if ( pAnchor->pFirstBlock->pData == NULL )
   {
      SysFree( pAnchor->pFirstBlock );
      SysFree( pAnchor );
      return( -1 );
   }

   pAnchor->pFirstBlock->lData = WRKS_INIT_SIZE;
   pAnchor->pFirstBlock->lDataUsed = 0;

   *ppAnchor = pAnchor;
   return( 0 );
}
Exemplo n.º 3
0
zOPER_EXPORT zLONG OPERATION
WRKS_Get( zPVOID pAnchor, zLONG lNeeded, zPVOID *ppData )
{
   T_MEMBLOCK *pBlock = ((T_WRKSANCHOR *) pAnchor)->pFirstBlock;
   T_MEMBLOCK *pLastBlock = NULL;
   zLONG      lAlloc;
   zPCHAR     pData;

   // go through chain of blocks
   while ( pBlock )
   {
      zLONG lFree = pBlock->lData - pBlock->lDataUsed;
      if ( lFree >= lNeeded )
      {
         // ok, we found a slot big enough
         *ppData = (pBlock->pData + pBlock->lDataUsed);
         pBlock->lDataUsed += lNeeded;
         return( 0 );
      }

      pLastBlock = pBlock;
      pBlock = pBlock->pNext;
   }

   // we did not find a fitting slot, allocate a new block
   lAlloc = WRKS_INIT_SIZE;
   if ( lNeeded * 2 > lAlloc )
      lAlloc = lNeeded * 2;

   if ( (pBlock = SysMalloc( sizeof( T_MEMBLOCK ) )) == NULL )
   {
      // Error allocating memory
      *ppData = NULL;
      return( -1 );
   }

   if ( (pData = SysMalloc( lAlloc )) == NULL )
   {
      // Error allocating memory
      SysFree( pBlock );
      *ppData = NULL;
      return( -1 );
   }

   // add to chain
   pLastBlock->pNext = pBlock;
   pBlock->pData = pData;
   pBlock->lData = lAlloc;
   pBlock->lDataUsed = lNeeded;
   *ppData = pData;
   return( 1 );
}
Exemplo n.º 4
0
ptr_t list_node_alloc_new(data_t *Master2Mem, data_t *Master2SysAlloc, data_t data, ptr_t nextNodePtr){
	ptr_t newNodePtr;
	struct list_node_t newNode;
	newNodePtr = SysMalloc(REQ_NODE_SIZE, Master2SysAlloc);
	newNode.data = data;
	newNode.next = nextNodePtr - newNodePtr;
	list_node_write(Master2Mem, newNodePtr, newNode);
	return newNodePtr;
}
Exemplo n.º 5
0
/* HashTable */
int *CreateHashTable(int NUM_OF_ENTRY){
	int *hdTable = SysMalloc(NUM_OF_ENTRY*sizeof(int));	
	int *hdList = NULL;
	int i;
	for(i = 0; i < NUM_OF_ENTRY; i++){
		WriteHashTable(hdTable, i, hdList);		
	}	
	return hdTable;
}
Exemplo n.º 6
0
/* Allocate New Node */
int *tree_node_alloc_new(data_t data){
	int *newNodePtr;
	newNodePtr = SysMalloc(NODE_REQ_SIZE);
	next_t offset = NULL_PTR - (int)newNodePtr;
	struct node_t newNode;
	newNode.data = data;
	newNode.left = offset;
	newNode.right = offset;
	newNode.height = 0; // should it be 0 or 1?
	tree_node_write(newNodePtr, newNode);
	return newNodePtr;
}
Exemplo n.º 7
0
int app(data_m *DataIn, data_m *saMaster){

	#pragma HLS INTERFACE s_axilite port=DataIn bundle=BUS_A
	#pragma HLS INTERFACE s_axilite port=return bundle=BUS_A

	#pragma HLS INTERFACE m_axi depth=1 port=saMaster offset=off

	int InputRequest;
	int pointer1, pointer2;
	int EventN;
	int ReturnValue;

	InputRequest = *DataIn + 1;

	pointer1 = SysMalloc(InputRequest, saMaster);
	SysFree(pointer1,saMaster);
	pointer2 = SysMalloc(InputRequest, saMaster);


	ReturnValue = pointer1  + pointer2;
	return ReturnValue;
}
Exemplo n.º 8
0
/* Allocate New Node */
int *list_node_alloc_new(int data, int *hdPtr){
	int *newNodePtr;
	newNodePtr = SysMalloc(sizeof(struct node_t));
	
	next_t offset;
	if(hdPtr == NULL){
		offset = NULL_PTR -(int)newNodePtr;
	}else{
		offset = hdPtr - newNodePtr;
	}	

	struct node_t newNode;
	newNode.data = data;
	newNode.next = offset;
	list_node_write(newNodePtr, newNode);
	
	return newNodePtr;
}
Exemplo n.º 9
0
Arquivo: zsp.c Projeto: momtx/meataxe
static int init_args()

{
    int i;

    SubspaceName = AppGetTextOption(App,"-b --basis",NULL);
    SubName = AppGetTextOption(App,"-s --subspace-action",NULL);
    QuotName = AppGetTextOption(App,"-q --quotient-action",NULL);
    OpName = AppGetTextOption(App,"-o --script",NULL);

    MaxDim = AppGetIntOption(App,"-d --dimension-limit",-1,1,100000000);
    MaxTries = AppGetIntOption(App,"-x --max-tries",-1,1,1000);
    TryOneVector = AppGetOption(App,"-1 --single-shot");
    TryLinearCombinations = AppGetOption(App,"-m --seed-generate");
    FindCyclicVector = AppGetOption(App,"-e --find-cyclic-vector");
    FindClosure = AppGetOption(App,"-c --combine");
    Standard = AppGetOption(App,"-t --standard-basis");

    opt_G = AppGetOption(App,"-G --gap");
    ngen = AppGetIntOption(App,"-g",-1,1,MAXGEN);
    SeedVecNo = AppGetIntOption(App,"-n",0,1,10000000);

    if (MaxDim != -1 && (FindClosure || FindCyclicVector))
    {
	MTX_ERROR("'-d' cannot be used together with '-c' or '-e'");
	return -1;
    }

    if (   FindClosure
	&& (FindCyclicVector || TryOneVector || TryLinearCombinations)
	)
    if (FindCyclicVector && FindClosure)
    {
	MTX_ERROR("'-c' cannot be combined with any of '-e', '-1', '-m'");
	return -1;
    }


    if (TryLinearCombinations && TryOneVector)
    {
	MTX_ERROR("Options '-n' and '-1' cannot be used together");
	return -1;
    }
    if (TryLinearCombinations && SeedVecNo > 0)
    {
	MTX_ERROR("Options '-m' and '-n' cannot be used together");
	return -1;
    }


    if (opt_G)
	MtxMessageLevel = -100;

    /* Process arguments (generator and seed names).
       --------------------------------------------- */
    if (ngen == -1)
    {
	ngen = 2;
	if (AppGetArguments(App,3,3) < 0)
	    return -1;
	GenName[0] = App->ArgV[0];
	GenName[1] = App->ArgV[1];
	SeedName =  App->ArgV[2];
    }
    else
    {
	char buf[200];
	if (AppGetArguments(App,2,2) < 0)
	    return -1;
	SeedName =  App->ArgV[1];
	for (i = 0; i < ngen; ++i)
	{
	    char *c;
	    sprintf(buf,"%s.%d",App->ArgV[0],i+1);
	    GenName[i] = c = SysMalloc(strlen(buf)+1);
	    strcpy(c,buf);
	}
    }

    return 0;
}