コード例 #1
0
uint32_t  			ApexResourceProvider::releaseResource(const char* nameSpace, const char* name)
{
	uint32_t ret = 0;

	PX_ASSERT(nameSpace);
	PX_ASSERT(name);
	uint32_t nsIndex = getNSIndex(createNameSpaceInternal(nameSpace, true));
	if (nsIndex < mNameSpaces.size())
	{
		ResID id = mNameSpaces[nsIndex]->getOrCreateID(name, nameSpace);
		PX_ASSERT(id < mResources.size());
		if (id < mResources.size())
		{
			ApexResourceProvider::resource& res = mResources[id];
			if (res.valueIsSet)
			{
				ret = (uint32_t)res.refCount - 1;
				releaseResource(id);
			}
		}
	}


	return ret;
}
コード例 #2
0
void ResourceManager::issueInstruction(
    const InstrDesc &Desc,
    SmallVectorImpl<std::pair<ResourceRef, double>> &Pipes) {
  for (const std::pair<uint64_t, ResourceUsage> &R : Desc.Resources) {
    const CycleSegment &CS = R.second.CS;
    if (!CS.size()) {
      releaseResource(R.first);
      continue;
    }

    assert(CS.begin() == 0 && "Invalid {Start, End} cycles!");
    if (!R.second.isReserved()) {
      ResourceRef Pipe = selectPipe(R.first);
      use(Pipe);
      BusyResources[Pipe] += CS.size();
      // Replace the resource mask with a valid processor resource index.
      const ResourceState &RS = *Resources[Pipe.first];
      Pipe.first = RS.getProcResourceID();
      Pipes.emplace_back(
          std::pair<ResourceRef, double>(Pipe, static_cast<double>(CS.size())));
    } else {
      assert((countPopulation(R.first) > 1) && "Expected a group!");
      // Mark this group as reserved.
      assert(R.second.isReserved());
      reserveResource(R.first);
      BusyResources[ResourceRef(R.first, R.first)] += CS.size();
    }
  }
}
コード例 #3
0
ファイル: UIOperationEvent.cpp プロジェクト: AlexanderVgn/EMV
void UIOperationEvent::releaseAllResources()
{
	if (stringValue)
	{
		releaseResource((void**)&stringValue);
		length = -1;
	}
}
コード例 #4
0
ファイル: player_sid.cpp プロジェクト: jweinberg/scummvm
void Player_SID::stopSound_intern(int soundResID) { // $5093
	for (int i = 0; i < 7; ++i) {
		if (soundResID == _soundQueue[i]) {
			_soundQueue[i] = -1;
		}
	}
	var481A = -1;
	releaseResource(soundResID);
}
コード例 #5
0
int gcm::patchRun(vector<SLR_ST_Skeleton> vSkeletonData, vector<Mat> vDepthData, vector<IplImage*> vColorData, 
				  int *rankIndex, double *rankScore)
{
	int kernelFeatureDim = NClass*NTrainSample;
	//clock_t startT=clock();
	oriData2Feature(vSkeletonData, vDepthData, vColorData);
	//cout<<"=======Time========="<<clock()-startT<<endl;
 	gcmSubspace();

	x[0].index = 0;
	for (int j=0; j<kernelFeatureDim; j++)
	{
		subMatrix(subFeaAll_model, subFea1, 0, featureDim, j*subSpaceDim, subSpaceDim);
		x[j+1].value = myGcmKernel.Frobenius(subFea1, gcm_subspace, featureDim, subSpaceDim);
		x[j+1].index=j+1;
	}
	x[kernelFeatureDim+1].index=-1;

	//int testID = svm_predict_probability(myModel, x, prob_estimates);
	int testID_noPro = svm_predict(myModel, x);

	int testID = svm_predict_probability(myModel_candi, x, prob_estimates);

	//Sort and get the former 5 ranks. 
	vector<scoreAndIndex> rank;
	for (int i=0; i<myModel->nr_class; i++)
	{
		scoreAndIndex temp;
		temp.index = myModel->label[i];
		temp.score = prob_estimates[i];
		rank.push_back(temp);
	}
	sort(rank.begin(),rank.end(),comp);

	
	rankIndex[0] = testID_noPro;
	rankScore[0] = 1.0;
	int candiN = 0;
	//for (int i=1; i<5; i++)
	int seqCandiN = 1;
	while(seqCandiN<5)
	{
		if (rank[candiN].index == testID_noPro)
		{
			candiN++;
			continue;
		}
		rankIndex[seqCandiN] = rank[candiN].index;
		rankScore[seqCandiN] = rank[candiN].score;
		candiN++;
		seqCandiN++;
	}
	releaseResource();
	return rankIndex[0];
}
コード例 #6
0
void ResourceManager::cycleEvent(SmallVectorImpl<ResourceRef> &ResourcesFreed) {
  for (std::pair<ResourceRef, unsigned> &BR : BusyResources) {
    if (BR.second)
      BR.second--;
    if (!BR.second) {
      // Release this resource.
      const ResourceRef &RR = BR.first;

      if (countPopulation(RR.first) == 1)
        release(RR);

      releaseResource(RR.first);
      ResourcesFreed.push_back(RR);
    }
  }

  for (const ResourceRef &RF : ResourcesFreed)
    BusyResources.erase(RF);
}
コード例 #7
0
ファイル: tc11_mutex.c プロジェクト: bnuh/munsailbot
static void taskC0(uint8_t idxTask)
{
    uint32_t cnt = 0;
    
    while(true)  
    {
        /* Wait until we get the resource. */
        getResource();
    
        /* Being here, we can be sure to have the resource. Use it. */
        Serial.print("This is task "); Serial.print(idxTask);
        
        /* The ownership of the resource needs to be independent of the status of the
           tasks. To prove this we suspend the task deliberately in the middle of some
           output operation and we use the blocking Arduino function delay that long, that
           we have a high probability of running into a round robin task switch before
           delay returned. */
        Serial.print(": "); Serial.print(++cnt);
        Serial.print(" loops. Thi");
        rtos_delay(TIME_IN_MS(12));
        Serial.print("s line of console output is interrupted by seve");
        delay(31/*ms*/);
        Serial.print("ral task de-activations. ");
        Serial.print("Now the resource Serial is released by task ");
        Serial.println(idxTask);
        
        /* In the original test case tc09, demonstrating the implementation of a
           pseudo-mutex, we had written: "Give other tasks a chance to get the resource.
           After the call of release, we must not immediately cycle around, otherwise the
           chance is high, that we get it immediately again since most of the concurrent
           tasks have the same priority. Suspend deliberately (but as short as possible),
           so that other tasks of the same priority class can become active."
             Using a true mutex, this becomes obsolete. The call of releaseResource returns
           the mutex, which is in the same atomic instance passed on to one of the
           concurrent, waiting, suspended other tasks. If that is a task of same priority it
           still holds true, that it won't interrupt the running task, but two statements
           later, in its next loop, this running task will try to aqcuire the resource
           again but the mutex is not available and it'll then be suspended. */
        releaseResource();
        //rtos_delay(0);
    }
} /* End of taskC0 */
コード例 #8
0
ファイル: tc11_mutex.c プロジェクト: bnuh/munsailbot
static void taskT0_C1(uint16_t initCondition)
{
#define TASK_TIME_T0_C1_MS  21

    uint32_t cnt = 0;
    
    /* The task inspects the results of the interrupt on a regular base. */
    do
    {
        /* Wait until we get the resource. */
        getResource();
    
        /* Being here, we can be sure to have the resource. Use it. */
        
        /* The ownership of the resource needs to be independent of the status of the
           tasks. To prove this we suspend the task deliberately in the middle of some
           output operation and we use the blocking Arduino function delay that long, that
           we have a high probability of running into a round robin task switch before
           delay returned. */
        Serial.print("This is task T0_C1");
        Serial.print(": "); Serial.print(++cnt);
        Serial.print(" loops. This line of conso");
        rtos_delay(TIME_IN_MS(7));
        Serial.print("le output is interr");
        delay(3/*ms*/);
        Serial.print("upted by several task de-activations");
        Serial.println(". Now the resource is released again");

        /* Give other tasks a chance to get the resource. */
        releaseResource();
        
        /* Here, no other task will already use the acquired resource: All concurrent tasks
           are of lower priority. One of them will have become due but not active yet. The
           while condition will now make this task inactive and the already due other one
           active. */
    }
    while(rtos_suspendTaskTillTime(TIME_IN_MS(TASK_TIME_T0_C1_MS)));

#undef TASK_TIME_T0_C1_MS
} /* End of taskT0_C1 */
コード例 #9
0
ファイル: player_sid.cpp プロジェクト: jweinberg/scummvm
void Player_SID::releaseResourceUnk(int resIndex) { // $50A4
	var481A = -1;
	releaseResource(resIndex);
}
コード例 #10
0
ファイル: player_sid.cpp プロジェクト: jweinberg/scummvm
void Player_SID::releaseResourceBySound(int resID) { // $5088
	var481A = 1;
	releaseResource(resID);
}
コード例 #11
0
void RenderResourceStorage< GLRenderer, CubeTexture, uint >::refreshResource( const CubeTexture* obj, uint& textureID ) const
{
   releaseResource( textureID );
   textureID = createResource( obj );
}
コード例 #12
0
void *customer(void* customerID)
{
	int processID = *(int*)customerID;

	while(1)
	{
		//request random number of resources
		sleep(1);
		int requestVector[resourceTypeQuan];

		//Because i is global variable, we should lock from here
		//lock mutex for accessing global variable and printf
		pthread_mutex_lock(&mutex);
		//initialize requestVector
		for(i = 0; i < resourceTypeQuan; i++)
		{
			if(needMatrix[processID][i] != 0)
			{
				requestVector[i] = rand() % needMatrix[processID][i];
			}
			else
			{
				requestVector[i] = 0;
			}
		}


		printf("Customer %d is trying to request resources:\n",processID);
		printReqOrRelVector(requestVector);
		//requestResource() will still return -1 when it fail and return 0 when succeed in allocate, like textbook says
		//altough I put the error message output part in the requestResource function
		requestResource(processID,requestVector);
		//unlock
		pthread_mutex_unlock(&mutex);
	
		//release random number of resources		
		sleep(1);
		int releaseVector[resourceTypeQuan];
		//Because i is global variable, we should lock from here
		//lock mutex for accessing global variable and printf
		pthread_mutex_lock(&mutex);
		//initialize releaseVector
		for(i = 0; i < resourceTypeQuan; i++)
		{
			if(allocMatrix[processID][i] != 0)
			{
				releaseVector[i] = rand() % allocMatrix[processID][i];
			}
			else
			{
				releaseVector[i] = 0;
			}
		}
		printf("Customer %d is trying to release resources:\n",processID);
		printReqOrRelVector(releaseVector);
		//releaseResource() will still return -1 when it fail and return 0 when succeed in allocate, like textbook says
		//altough I put the error message output part in the releaseResource function
		releaseResource(processID,releaseVector);
		//unlock
		pthread_mutex_unlock(&mutex);
	}
}
コード例 #13
0
ファイル: smaugProcess.c プロジェクト: BernardYuan/smaugworld
int main(void) {
    initialize();
    srand(time(NULL));

    int SHEEP_INTERVAL = 0;
    int COW_INTERVAL = 0;
    int THIEF_INTERVAL = 0;
    int HUNTER_INTERVAL = 0;

    long long sheep_time = 0;
    long long cow_time = 0;
    long long thief_time = 0;
    long long hunter_time = 0;

    int sheepSleepTime = 0;
    int cowSleepTime = 0;
    int thiefPathTime = 0;
    int hunterPathTime = 0;

    //========================================================
    printf("Input the Sheep Interval:");
    scanf("%d", &SHEEP_INTERVAL);
    printf("Input the maximum time that a sheep grazes:");
    scanf("%d", &sheepSleepTime);
    //=======================================================
    printf("Input the Cow Interval:");
    scanf("%d", &COW_INTERVAL);
    printf("Input the maximum time that a cow grazes:");
    scanf("%d", &cowSleepTime);
    //=======================================================
    printf("Input the Thief Interval:");
    scanf("%d", &THIEF_INTERVAL);
    printf("Input the maximum time that a thief looks for the path:");
    scanf("%d", &thiefPathTime);
    //========================================================
    printf("Input the Hunter Interval:");
    scanf("%d", &HUNTER_INTERVAL);
    printf("Input the maximum time that a hunter looks for the path:");
    scanf("%d", &hunterPathTime);
    //========================================================

    sheep_time += SHEEP_INTERVAL;
    cow_time += COW_INTERVAL;
    thief_time += THIEF_INTERVAL;
    hunter_time += HUNTER_INTERVAL;
    int genflag = 0; // the flag tells what to generate

    long long elapsetime = 0;
    long long lastelapsetime = 0;
    struct timeval lasttime;
    struct timeval curtime;
    gettimeofday(&lasttime, NULL);

    //produce smaug
    pid_t result = fork();
    if (result < 0) {
        printf("fork error\n");
        exit(1);
    }
    if (result == 0) {
        smaug();
    }
    else {
        pid_t r;
        while (1) {
            gettimeofday(&curtime, NULL);
            elapsetime += (curtime.tv_sec - lasttime.tv_sec) * 1000000 + (curtime.tv_usec - lasttime.tv_usec);
//	        pid_t localpid = getpid();
            //printf("In process: %d Elapsed time: %lld\n", localpid,elapsetime);
//            if(elapsetime - lastelapsetime >= 500000)
            lasttime = curtime;

            if (checkTermination()) {

                printf("****************************terminating in parent process**************************************************\n");

                terminateSimulation();
                int status;
                // block till all children exits
                waitpid(-1, &status, 0);
                printf("****************************In main: all children have exited\n");
                releaseResource();
                exit(0);
            }

            if (elapsetime > sheep_time) {
                genflag = 0;
                sheep_time += SHEEP_INTERVAL;
                r = fork();
                if (r == 0) break;
            }

            if (elapsetime > cow_time) {
                genflag = 1;
                cow_time += COW_INTERVAL;
                r = fork();
                if (r == 0) break;
            }

            if (elapsetime > thief_time) {
                genflag = 2;
                thief_time += THIEF_INTERVAL;
                r = fork();
                if (r == 0) break;
            }

            if (elapsetime > hunter_time) {
                genflag = 3;
                hunter_time += HUNTER_INTERVAL;
                r = fork();
                if (r == 0) break;
            }
        }
        //=============================================================
        if (genflag == 0) sheep(rand() % sheepSleepTime);
        else if (genflag == 1) cow(rand() % cowSleepTime);
        else if (genflag == 2) thief(rand() % thiefPathTime);
        else if (genflag == 3) hunter(rand() % hunterPathTime);
        exit(0);
    }
}
コード例 #14
0
ファイル: tetrimino.cpp プロジェクト: hjqqq/tetrimino
Tetrimino::~Tetrimino(){
    releaseResource();
    TTF_Quit();
    IMG_Quit();
    SDL_Quit();
}
コード例 #15
0
void *test_func(void *_arg)
{
  TestArg *arg = (TestArg*)_arg;
  int what = 0, *value = NULL, last = 0;
  ResourceQueue *rq_p = NULL;
  int error = NO_ERROR;

  assert(arg != NULL);

  rq_p = arg->rq_p;

  what = arg->thread_no%3;

  for (int i = 0; i < 100; ++i) {
    switch (what) {
    case 0:
      error = requestResource(rq_p, RQ_REQUEST_READ, (void**)&value);
      if (error != NO_ERROR) {
        printf("Thread %d: request %d fail.\n", arg->thread_no, RQ_REQUEST_READ);
        break;
      }

      assert(value != NULL);

      last = *value;

      (void)releaseResource(rq_p);

      break;
    case 1:
      error = requestResource(rq_p, RQ_REQUEST_WRITE, (void**)&value);
      if (error != NO_ERROR) {
        printf("Thread %d: request %d for -- fail.\n", arg->thread_no, RQ_REQUEST_WRITE);
        break;
      }

      assert(value != NULL);

      last = --*value;

      (void)releaseResource(rq_p);

      break;
    case 2:
      error = requestResource(rq_p, RQ_REQUEST_WRITE, (void**)&value);
      if (error != NO_ERROR) {
        printf("Thread %d: request %d for ++ fail.\n", arg->thread_no, RQ_REQUEST_WRITE);
        break;
      }

      assert(value != NULL);

      last = ++*value;

      (void)releaseResource(rq_p);

      break;
    default:
      break;
    }

    //printf("--Thread %d: the value of i is %d.\n", arg->thread_no, last);
  }

  printf("Thread %d: the value of i is %d.\n", arg->thread_no, last);

  return 0;
}