Example #1
0
//--------------------------------------------------------------------------
void VeResource::LoadAsync() noexcept
{
	if (m_eState == LOADED)
	{
		Hold();
	}
	else
	{
		m_eState = LOADING;
		UpdateState();
	}
	ve_res_mgr.CacheFile(m_kName, m_spGroup, [this](
		VeResourceManager::FileCachePtr spCache) noexcept
	{
		if (spCache)
		{
			LoadImpl(spCache);
		}
		else
		{
			if (m_eState == LOADED)
			{
				Free();
			}
			else
			{
				m_eState = UNLOADED;
				UpdateState();
			}
			OnResLoadFailed(ERR_FILE_NOT_FOUND);
		}
	});
}
Example #2
0
File: 72.c Project: 13436120/Cgames
int Railroad(int p[], int n, int k)
{// k个缓冲铁轨,车厢初始排序为p [1:n]
	// 如果重排成功,返回1,否则返回0
	// 如果内存不足,则引发异常NoMem 。
	//创建与缓冲铁轨对应的堆栈
	SeqStack *H;
	int NowOut = 1; //下一次要输出的车厢
	int minH =n+1; //缓冲铁轨中编号最小的车厢
	int minS,i; //minH号车厢对应的缓冲铁轨
	H=(SeqStack*)calloc((k+1),sizeof(SeqStack)*(k+1));
	//车厢重排
	for (i = 1; i<= n; i++)
		if (p[i] == NowOut) {// 直接输出t
			printf("移动车厢%d从出口到入口",p[i]);
			NowOut++;
			//从缓冲铁轨中输出
			while (minH == NowOut) {
				Output(&minH, &minS, H, k, n);
				NowOut++;
			}
		}
		else {// 将p[i] 送入某个缓冲铁轨
			if (!Hold(p[i], &minH, &minS, H, k, n))
				return 0;
		}
		return 1;
}
Example #3
0
bool Railroad(int p[], int n, int k)
{// k track rearrangement of car order p[1:n].
 // Return true if successful, false if impossible.
 // Throw NoMem exception if inadequate space.

   // create queues for holding tracks
   LinkedQueue<int> *H;
   H = new LinkedQueue<int> [k];
   k--; // keep track k open for direct moves

   int NowOut = 1;   // next car to output
   int minH = n+1;   // smallest car in a track
   int minQ;         // track with car minH

   // rearrange cars
   for (int i = 1; i <= n; i++)
      if (p[i] == NowOut) {// send straight out
         cout << "Move car " << p[i] <<
                 " from input to output" << endl;
         NowOut++;

         // output from holding tracks
         while (minH == NowOut) {
            Output(minH, minQ, H, k, n);
   	    NowOut++;
            }
         }
      else {// put car p[i] in a holding track
         if (!Hold(p[i], minH, minQ, H, k))
         return false;}

   return true;
}
void
ClientLayerManager::Mutated(Layer* aLayer)
{
  LayerManager::Mutated(aLayer);

  NS_ASSERTION(InConstruction() || InDrawing(), "wrong phase");
  mForwarder->Mutated(Hold(aLayer));
}
Example #5
0
State * TeleKarma::DoAction(Action * a, State * s)
{
	if (a == NULL) return s;
	State * result = s;
	// process "global" (turn-independent) actions independant of turn #
	switch (a->id) {
		case ACTION_QUIT:
			result = Quit(a, s);
			break;
		case ACTION_PLAY_SOUND:
			result = PlaySound(a, s);
			break;
		case ACTION_SEND_TONE:
			result = SendTone(a, s);
			break;
		default:
			// process turn-independent actions if applicable
			if (a->turn == s->turn) {
				switch (a->id) {
					case ACTION_INITIALIZE:
						result = Initialize(a, s);
						break;
					case ACTION_REGISTER:
						result = Register(a, s);
						break;
					case ACTION_DIAL:
						result = Dial(a, s);
						break;
					case ACTION_HOLD:
						result = Hold(a, s);
						break;
					case ACTION_AUTOHOLD:
						result = AutoHold(a, s);
						break;
					case ACTION_MUTE:
						result = MuteAutoHold(a, s);
						break;
					case ACTION_RETRIEVE:
						result = Retrieve(a, s);
						break;
					case ACTION_DISCONNECT:
						result = Disconnect(a, s);
						break;
					default:
						// simply ignore unknown actions
						// (and global actions)
						break;
				}
			} else {
				if (s != NULL) {
					result = SetState(new State(s->id, s->turn, STATUS_TURN_MISMATCH));
				}
			}
			break;
	}
	delete a;
	return result;
}
void
ClientLayerManager::SetRoot(Layer* aLayer)
{
  if (mRoot != aLayer) {
    // Have to hold the old root and its children in order to
    // maintain the same view of the layer tree in this process as
    // the parent sees.  Otherwise layers can be destroyed
    // mid-transaction and bad things can happen (v. bug 612573)
    if (mRoot) {
      Hold(mRoot);
    }
    mForwarder->SetRoot(Hold(aLayer));
    NS_ASSERTION(aLayer, "Root can't be null");
    NS_ASSERTION(aLayer->Manager() == this, "Wrong manager");
    NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
    mRoot = aLayer;
  }
}
Example #7
0
//Description: Picks up code on PORTD and executes the function corresponding to the code
//Return:		error code of 0 for no error
int TreadAxisDecode()
{
	unsigned char cmd = 0;
	cmd = PIND;
	if(FORWARD == (cmd & TREAD_MASK))
		Forwards();
	else if(BACKWARD == (cmd & TREAD_MASK))
		Backwards();
	else if(LEFT == (cmd & TREAD_MASK))
		Left();
	else if(RIGHT == (cmd & TREAD_MASK))
		Right();
	else if(HALT == (cmd & TREAD_MASK))
		Hold();
	else
		Hold();
	return 0;
}
void CasmReader::readTextOrBinary(charstring Filename,
                                  std::shared_ptr<SymbolTable> EnclosingScope,
                                  std::shared_ptr<SymbolTable> AlgSymtab) {
  if (AlgSymtab) {
    std::shared_ptr<Queue> Binary = std::make_shared<ReadBackedQueue>(
        std::make_shared<FileReader>(Filename));
    // Mark the beginning of the stream, so that it doesn't loose the page.
    ReadCursor Hold(Binary);
    if (hasBinaryHeader(Binary, AlgSymtab))
      return readBinary(Binary, AlgSymtab, EnclosingScope);
  }
  if (std::string(Filename) == "-")
    // Can't reread from stdin, so fail!
    foundErrors();
  else
    readText(Filename, EnclosingScope);
}
Example #9
0
void CMyControl::Poll()
{
	super::Poll();

#if defined(HOLD_PIN) && defined(RESUME_PIN)

	if (IsHold())
	{
		if (_resume.IsOn())
		{
			Resume();
		}
	} 
	else if (_hold.IsOn())
	{
		Hold();
	}
#endif
}
Example #10
0
static uintptr_t CPROC HandleTaskOutput(PTHREAD thread )
{
	PTASK_INFO task = (PTASK_INFO)GetThreadParam( thread );
	{
		task->pOutputThread = thread;
		// read input from task, montiro close and dispatch TaskEnd Notification also.
		{
			PHANDLEINFO phi = &task->hStdOut;
			PTEXT pInput = SegCreate( 4096 );
			int done, lastloop;
			Hold( task );
			done = lastloop = FALSE;
			do
			{
				uint32_t dwRead, dwAvail;
				if( done )
					lastloop = TRUE;
#ifdef _WIN32
				//while(  )
				{

#else
					while( CanRead( phi->handle ) )
#endif
					{
						if( task->flags.log_input )
							lprintf( WIDE( "Go to read task's stdout." ) );
#ifdef _WIN32
						if( !task->flags.process_ended &&
							 ReadFile( phi->handle
										, GetText( pInput ), (DWORD)(GetTextSize( pInput ) - 1)
										, (LPDWORD)&dwRead, NULL ) )  //read the  pipe
						{
#else
							dwRead = read( phi->handle
											 , GetText( pInput )
											 , GetTextSize( pInput ) - 1 );
							if( !dwRead )
							{
#ifdef _DEBUG
												//lprintf( WIDE( "Ending system thread because of broke pipe! %d" ), errno );
#endif
#ifdef WIN32
								continue;
#else
												//lprintf( WIDE( "0 read = pipe failure." ) );
								break;
#endif
							}
#endif
							if( task->flags.log_input )
								lprintf( WIDE( "got read on task's stdout: %d" ), dwRead );
							if( task->flags.bSentIoTerminator )
							{
								if( dwRead > 1 )
									dwRead--;
								else
								{
									if( task->flags.log_input )
										lprintf( WIDE( "Finished, no more data, task has ended; no need for once more around" ) );
									lastloop = 1;
									break; // we're done; task ended, and we got an io terminator on XP
								}
							}
							//lprintf( WIDE( "result %d" ), dwRead );
							GetText( pInput )[dwRead] = 0;
							pInput->data.size = dwRead;
							//LogBinary( GetText( pInput ), GetTextSize( pInput ) );
							if( task->OutputEvent )
							{
								task->OutputEvent( task->psvEnd, task, GetText( pInput ), GetTextSize( pInput ) );
							}
							pInput->data.size = 4096;
#ifdef _WIN32
						}
						else
						{
							DWORD dwError = GetLastError();
							if( ( dwError == ERROR_OPERATION_ABORTED ) && task->flags.process_ended )
							{
								if( PeekNamedPipe( phi->handle, NULL, 0, NULL, (LPDWORD)&dwAvail, NULL ) )
								{
									if( dwAvail > 0 )
									{
										lprintf( WIDE( "caught data" ) );
										// there is still data in the pipe, just that the process closed
										// and we got the sync even before getting the data.
									}
									else
										break;
								}
							}
						}
#endif
					}
#ifdef _WIN32
				}
#endif
				//allow a minor time for output to be gathered before sending
				// partial gathers...
				if( task->flags.process_ended )
#ifdef _WIN32
				{
					// Ending system thread because of process exit!
					done = TRUE;
				}
#else
				//if( !dwRead )
				//	break;
				if( task->pid == waitpid( task->pid, NULL, WNOHANG ) )
				{
					Log( WIDE( "Setting done event on system reader." ) );
					done = TRUE; // do one pass to make sure we completed read
				}
				else
				{
					//lprintf( WIDE( "process active..." ) );
					Relinquish();
				}
#endif
			}
			while( !lastloop );
#ifdef _DEBUG
			if( lastloop )
			{
				//DECLTEXT( msg, WIDE( "Ending system thread because of process exit!" ) );
				//EnqueLink( phi->pdp->&ps->Command->Output, &msg );
			}
			else
			{
				//DECLTEXT( msg, WIDE( "Guess we exited from broken pipe" ) );
				//EnqueLink( phi->pdp->&ps->Command->Output, &msg );
			}
#endif
			LineRelease( pInput );
#ifdef _WIN32
			CloseHandle( task->hReadIn );
			CloseHandle( task->hReadOut );
			CloseHandle( task->hWriteIn );
			CloseHandle( task->hWriteOut );
			//lprintf( WIDE( "Closing process handle %p" ), task->pi.hProcess );
			phi->hThread = 0;
#else
			//close( phi->handle );
			close( task->hStdIn.pair[1] );
			close( task->hStdOut.pair[0] );
         //close( task->hStdErr.pair[0] );
#define INVALID_HANDLE_VALUE -1
#endif
			if( phi->handle == task->hStdIn.handle )
				task->hStdIn.handle = INVALID_HANDLE_VALUE;
			phi->handle = INVALID_HANDLE_VALUE;
			task->pOutputThread = NULL;

			Release( task );
			//WakeAThread( phi->pdp->common.Owner );
			return 0xdead;
		}
	}
}
Example #11
0
void Indication() {
    switch(App.Status) {
        case stIdle:
        case stSignReset:
            SwitchOffEverything();
            chThdSleepMilliseconds(9);
        break;

        case stAardSrc:
        case stIgniSrc:
        case stKvenSrc:
        case stIrdenSrc:
        case stGelioSrc:
            SwitchOffEverything();
            Vibro.On(VIBRO_SOURCE);
            chThdSleepMilliseconds(9);
        break;

        case stAardForce:
        case stIgniForce:
        case stKvenForce:
        case stIrdenForce:
        case stGelioForce:
            SwitchOffEverything();
            Vibro.On(VIBRO_FORCE);
            chThdSleepMilliseconds(9);
        break;

        // Aard
        case stAardExec: Exec(&BlueLed); App.Status = stAardHold; break;
        case stAardHold: Hold(&BlueLed); break;
        // Igni
        case stIgniExec: Exec(&RedLed); App.Status = stIgniHold; break;
        case stIgniHold: Hold(&RedLed); break;
        // Kven
        case stKvenExec: Exec(&YellowLed); App.Status = stKvenHold; break;
        case stKvenHold: Hold(&YellowLed); break;
        // Irden
        case stIrdenExec: Exec(&GreenLed); App.Status = stIrdenHold; break;
        case stIrdenHold: Hold(&GreenLed); break;
        // Gelio
        case stGelioExec: Exec(&WhiteLed); App.Status = stGelioHold; break;
        case stGelioHold: Hold(&WhiteLed); break;

        // ==== Device state ====
        case stAccFail:
            RedLed.On(LED_LOW);
            YellowLed.On(LED_LOW);
            chThdSleepMilliseconds(450);
            break;

        case stCharging:
            GreenLed.Off();
            BlueLed.On(LED_LOW);
            chThdSleepMilliseconds(99);
            BlueLed.Off();
            chThdSleepMilliseconds(810);
            break;

        case stChargeCompleted:
            BlueLed.Off();
            GreenLed.On(LED_LOW);
            chThdSleepMilliseconds(450);
            break;
    } // switch
}
//## class Hold
Hold::Hold(IOxfActive* theActiveContext) {
    NOTIFY_REACTIVE_CONSTRUCTOR(Hold, Hold(), 0, Default_Hold_Hold_SERIALIZE);
    setActiveContext(theActiveContext, false);
    itsController = NULL;
    initStatechart();
}