コード例 #1
0
ファイル: call_group.hpp プロジェクト: kostko/unisphere
  void call(const NodeIdentifier &destination,
            const std::string &method,
            const RequestType &request,
            std::function<void(const ResponseType&, const typename Channel::message_type &msg)> success,
            RpcResponseFailure failure = nullptr,
            const RpcCallOptions<Channel> &opts = RpcCallOptions<Channel>())
  {
    // Call group is stored in call handler closures and will be destroyed after all
    // handlers are completed
    auto self = this->shared_from_this();

    m_calls++;
    m_queue.push_back([=]() {
      m_engine.call<RequestType, ResponseType>(
        destination,
        method,
        request,
        m_strand.wrap([self, success](const ResponseType &rsp, const typename Channel::message_type &msg) {
          if (success)
            success(rsp, msg);
          self->checkCompletion();
        }),
        m_strand.wrap([self, failure](RpcErrorCode code, const std::string &msg) {
          if (failure)
            failure(code, msg);
          self->checkCompletion();
        }),
        opts
      );
    });
  }
コード例 #2
0
void loop(){
	if(!started){ 
		print("Program active\n\n",0); 
		started=true;
	};
	
	for(int i=0;i<11;i++){ // count over LED pairs
		if(i==0) { 
			if(cycleCount < 4){
				cycleCount++;
			} else reInit();	// reinit after 3 incomplete cycles
		};
		if(checkCompletion() == -1 && haltUntilFirstTouch) { i=0;} // stalls the sequence on position 1 until that is touched
		
		print("Pair ",0); print(i,0); print(" is on.\n",0);
		killLEDs();
		lightLEDpair(i);
				  
		for(int j=0;j<25;j++){ // split delays in about 10-20ms to have steady timing			
			if(fridgeUnlocked) unlock();
			
			checkNodes();
			int completedStep = checkSequence();
			
			if((completedStep >= 0) &&
			   (completedStep != previousCycle) &&
			   (touchLEDcorrespondence[completedStep] < i+1)) { // if the LEDs are ahead of the user, restart at the user's current position
			   
			    previousCycle = completedStep;
				i = touchLEDcorrespondence[completedStep];		// it seems if i=0 here the next loop is executed with i=1
				if(i == 0) revertTo0 = true;
				print("Reverted to pair ",0);print(i,0);print("\n",0);
				break;
			}
			previousCycle = completedStep;
			delay((LEDpairs[i][4]/25));
			
		}
		if(revertTo0){
			revertTo0 = false;
			break;	// break main for loop to get i=0
		}
		if(fridgeUnlocked){ 
			print("Successfully unlocked!\n\n",0);
			lightLEDpair(10);
			
			for(int j=0;j<3;j++){
				delay(2500);
				killLEDs();
				delay(1500);
				lightLEDpair(10);
			};
			
			delay(3000); 
			reInit(); 
			break;
		};
	}
}
コード例 #3
0
ファイル: banker.c プロジェクト: Slaughterfest1/cpsc315
/**
 * Creates a random request vector and requests it.
 *
 * @param process number
 */
void *requestResource( void *proc ) {

  // sleep for a random period
	sleep(1+(int)(10.0*(rand() / 10)));

	int Request[resources];
	int process = (int)proc;
	
	// generate a random request vector
	for(i=0; i<resources; i++) {
		Request[i] = rand() % Need[process][i];
		// this will always be less than what we need, so we dont have to check
		
		printf("Customer %d is requesting %d unit(s) from R%d.\n",process,Request[i],i);
	}
  
  /* uncomment this if we're not using checkCompletion() and allocate()
  for(i=0; i<resources; i++)
    if( Request[i] > Available[i])
      return; // this process has to wait

  for(i=0; i<resources; i++) {
	  Available[i] -= Request[i];
		Allocation[process][i] += Request[i];
		Need[process][i] -= Request[i];
	}
	*/

  // allocate the resource to the process
	if( allocate( process, Request) == TRUE ) {
		printf("Approved.\n");
		if( checkCompletion( process ) == TRUE ) {
			printf("\nProcess %d has completed!\n",process);
		  sleep(rand() % 10);
	  }
	} else {
		printf("Denied.\n");
		//wait.
		sleep(rand() % 10);
	}

  // exit the thread
	pthread_exit(NULL);

}