コード例 #1
0
/* initiate crossing */
void initiateCrossing()
{
	static int debug = 0;
	debug++;
	PrintTextOnPobTerminal("Initiate Crossing Task\n");
	int i=0;
	int action=0;
	int temp=0;
	for(i=0;i<5;i++)
	{
		temp=getCanCross(i);
		if(temp==IDP_6_CIRCLE||temp==IDP_2_KING)
		{
			action=1;
			break;
		}
		if(temp==IDP_5_TRIANGLE||temp==IDP_1_BIGA)
		{
			action=2;
			break;
		}
	}
	if(action==2)
	{
		queueInsert(&avoidRobotTask,aperiodicQ);
	}
	if(action==0)
	{
		queueInsert(&crossTrackTask,sporadicQ);
	}
}
コード例 #2
0
ファイル: main.c プロジェクト: thecodemasters1/Study-Books
void calcChange(int**board, int width, int height, struct Queue* change)
{
	int i, j;
	int x, y;
	int start_x;
	int neighborsCount;
	for ( i = 0; i < height; i++)
	{
		for ( j= 0;  j <width;  j++)
		{
			/*check number of neighbors*/
			neighborsCount = 0;
			y = i - 1;
			if (y<0)
			{
				y = 0;
			}
			start_x = j - 1;
			if (start_x<0)
			{
				start_x = 0;
			}
			for (; y <= i+1 && y<height; y++)
			{
				for (x=start_x; x <= j+1 && x<width; x++)
				{
					neighborsCount += board[y][x];
				}
			}
			neighborsCount -= board[i][j]; /*ignore curretn cell in neighbors count*/
			/*check if cell needs to die or live*/
			switch (board[i][j])
			{
			case 0: 
			{
				if (neighborsCount==3)
				{
					queueInsert(change, i);
					queueInsert(change, j);
				}
				break; 
			}
			case 1:
			{
				if (neighborsCount<2||neighborsCount>3)
				{
					queueInsert(change, i);
					queueInsert(change, j);
				}
				break;
			}
			default:
				break;
			}
		}
	}
}
コード例 #3
0
bool checkDelimiter(int* index, const char* const cmdLine, struct StringBuffer* sb, struct Queue* tokens)
{
	bool delimiter=false;
	int i, j, forwardLen=0;
	char *tmp, *s, *delTmp;

	//Loop through delimiters check if one is the next token in the cmd line
	for (i=0; i<CL_DELIMITER_CNT; i++)
	{
		//Do we have enough chars in the cmd line
		//that is if possible to match the i'th delimiter?
		if ((strlen(cmdLine) - (*index)) >= strlen(CL_DELIMITERS[i]))
		{
			//extract the same number of char's from
			//the cmd line as the length ofthe delimiter
			tmp=(char *)malloc(strlen(CL_DELIMITERS[i])+1);
			for (j=0; j<strlen(CL_DELIMITERS[i]); j++)
			{
				tmp[j]=cmdLine[j+(*index)];
			}
			tmp[j]='\0'; //terminate with null

			//Are they equal?
			if (strcmp(tmp, CL_DELIMITERS[i])==0)
			{
				if (strBufLength(sb)>0)
				{
					s=strBufToString(sb);
					strBufClear(sb);
					queueInsert(tokens, s);
				}

				delimiter=true;
				forwardLen=strlen(CL_DELIMITERS[i])-1;

				if (CL_DELIMITERS_FLAGS[i]==CL_DELIMITER_PUSHABLE)
				{
					delTmp=tmp;
					tmp=trim(tmp);
					free(delTmp);
					queueInsert(tokens, tmp);
				}

				break;
			}
			else
			{
				free(tmp);
			}
		}
	}

	*index+=forwardLen;

	return delimiter;
}
コード例 #4
0
/*
 * Create a new Java thread. The thread is initially suspended.
 */
int
sysThreadCreate(sys_thread_t **tidP, long stack_size,
                void (*proc)(void *), void *arg)
{
    sys_thread_t *tid = allocThreadBlock();
    if (tid == NULL) {
        return SYS_NOMEM;
    }
    tid->state = SUSPENDED;
    tid->start_proc = proc;
    tid->start_parm = arg;

    tid->interrupt_event = CreateEvent(NULL, TRUE, FALSE, NULL);

    /*
     * Start the new thread.
     */
    tid->handle = (HANDLE)_beginthreadex(NULL, stack_size, _start, tid,
                                         CREATE_SUSPENDED, &tid->id);
    if (tid->handle == 0) {
        return SYS_NORESOURCE;  /* Will be treated as though SYS_NOMEM */
    }

    queueInsert(tid);
    *tidP = tid;
    return SYS_OK;
}
コード例 #5
0
/*
 * Allocate and initialize the sys_thread_t structure for an arbitary
 * native thread.
 */
int
sysThreadAlloc(sys_thread_t **tidP)
{
    HANDLE hnd = GetCurrentProcess();
    sys_thread_t *tid = allocThreadBlock();
    if (tid == NULL) {
        return SYS_NOMEM;
    }

    tid->state = RUNNABLE;
    tid->interrupted = FALSE;
    tid->interrupt_event = CreateEvent(NULL, TRUE, FALSE, NULL);
    tid->id = GetCurrentThreadId();
    DuplicateHandle(hnd, GetCurrentThread(), hnd, &tid->handle, 0, FALSE,
                    DUPLICATE_SAME_ACCESS);

    RecordNTTIB(tid);
    /* For the Invocation API:
       We update the thread-specific storage before locking the
       queue because sysMonitorEnter will access sysThreadSelf.
     */
    TlsSetValue(tls_index, tid);

    queueInsert(tid);
    tid->stack_ptr = &tid;
    *tidP = tid;
    return SYS_OK;
}
コード例 #6
0
int P2_MboxSend(int mbox, void *msg, int *size){
	if(mbox < 0 || mbox >= P2_MAX_MBOX || mailboxes[mbox].inUse != 1 || mailboxes[mbox].maximumMessageSize < *size || permissionCheck()){
		return -1;
	}

	mailbox *cur = &(mailboxes[mbox]);
	P1_P(cur->empties);
	P1_P(cur->mutex);
	void *m = malloc(*size);
	memcpy(m,msg,*size);
	queueInsert(m,*size,&(cur->queue));
	cur->activeSlots++;
	P1_V(cur->mutex);
	P1_V(cur->fulls);
	return 0;
}
コード例 #7
0
int qPrint(Queue *q)
{
    int i=getQueueLength(q);
    Customer *c;
    
    clearScreen();
    
    do
    { 
        c = queueRemove(q);
        printBill(c);
        wait();
        
        if(c!=NULL)
                   queueInsert(q, c);
        i--;
    }while(i>0);
}
コード例 #8
0
struct Queue* tokenize(const char* const cmdLine)
{
	struct Queue* tokens=queueCreate();
	struct StringBuffer* sb=strBufCreate();
	char* s;
	int i;
	bool inQuotes=false, delimiter;

	for (i=0; i<strlen(cmdLine); i++)
	{
		delimiter=false;

		if(cmdLine[i]=='\"' || cmdLine[i]=='\'')
		{
			inQuotes=!inQuotes;
		}
		else if (!inQuotes)
		{
			delimiter=checkDelimiter(&i, cmdLine, sb, tokens);

			if (!delimiter)
	                {
				//Non-Delimiter Character
        	                strBufAppendChar(sb, cmdLine[i]);
                	}
		} //End !inQuotes Check
		else
		{
			//inQuotes
			strBufAppendChar(sb, cmdLine[i]);
		}
	}

	if (strBufLength(sb)>0)
	{
		s=strBufToString(sb);
		strBufClear(sb);
		queueInsert(tokens, s);
	}

	strBufDestroy(sb);

	return tokens;
}
コード例 #9
0
int qArrive(Queue *q, productList *products)
{
    int code, quantity;
    char id[10];
    char input;
    Customer *c = newCustomer();
    Product *p;
    basketItem *item;
    
    printf("\n\tEnter customer id:\n\t");
    scanf("%s", id);   
    customerInit(c, id);
    
    clearScreen();

    do
    {
                    clearScreen();
                    
                    printf("\n\tAdd items to bill of '%s'\n", id);
                    
                    printf("\n\t\tEnter product code: \t(0: quit)\n\t\t");
                    scanf("%d", &code);
                    
                    if(code==0)
                               break;
                    
                    p=findProductByCode(code, products);
                    
                    if(p==NULL)
                    {
                               printf("Error: Cannot add item to basket.");
                               wait();
                               continue;
                    }
                    
                    printf("\n\t\tEnter quantity:\n\t\t");
                    scanf("%d", &quantity);
                    
                    
                    
                    addToBasket(c, newBasketItem(p, quantity));
                    
                    printf("\n\t\t%d of %s were added to the basket.", quantity, getProductName(p));
                    printf("\n\n\t\t[backspace: undo  0: done  1: continue]\n\t\t");
                    input = getch();
                    
                    if(input=='\b')
                    {
                                remFromBasket(c);
                                printf("\n\t\tLast item was removed successfully!");
                                wait();
                                continue;
                    }
                    
                    
                    
    }while(input!='0');
    
    queueInsert(q, c);
}