示例#1
0
void* _send_buffer_monitor(void* arg) {
	int buf_idx = *(int*)arg;
	Message_t msg;
	Client_t* c;
	for (;;) {
		sem_wait(&g_executor.send_buffer_num_[buf_idx]);
		if (Queue_Pop(g_executor.send_buffer_[buf_idx], &msg) == QUEUE_OK) {
			if ((c = Map_GetPtr(g_executor.clients, &msg.sockfd)) == NULL) {
				//Clients already gone
				Log(LOG_NOTICE,"[SEND FAIL]Client Already Gone");
				ylfree(msg.package);
				continue;
			}
			if (msg.trysend_cnt) {
				usleep(100000);
			}
			int nsend = netWrite(NULL, msg.sockfd, (char*) msg.package, msg.pkg_len);
			if (nsend == ERR_NETWORK_TRY_AGAIN&& ++msg.trysend_cnt < MAX_SEND_TRY) {
				Queue_Push(g_executor.send_buffer_[buf_idx] , &msg);
				sem_post(&g_executor.send_buffer_num_[buf_idx]);
			} else {
				ylfree(msg.package);
			}
		}
	}
	return NULL;
}
示例#2
0
/*******************************************************************************
  * @函数名称		dir_totle
  * @函数说明		计算文件夹的总数,多余的将其删除
  * @输入参数		路径结构体指针、文件信息结构体指针
  * @输出参数		无
  * @返回参数		文件夹的总数
*******************************************************************************/
uint16_t dir_totle(DIR *path, FILINFO* file_info){
    
    uint16_t dir_num = 0;
    static TCHAR *fn;
    while(1){
        
        if(f_readdir(path,file_info) == FR_OK){
            
            if (file_info->fname[0] == 0) break;
            
            if(file_info->fattrib == AM_DIR){
                
                dir_num++;
#if _USE_LFN
                fn = *file_info->lfname ? file_info->lfname : file_info->fname;
#else
                fn = file_info->fname;
#endif
                if(!Queue_Push(&Q_dir,fn)){
                    /* first pop */
                    msg_t *delete_file;
                    delete_file = Queue_Pop(&Q_dir);
                    f_unlink((const TCHAR*)delete_file->buf);
                    memset(delete_file->buf,0,sizeof(delete_file->buf));
                    
                    /* next push */
                    memcpy(Q_dir.m_Msg[Q_dir.rear].buf,fn,C_MAX_BUF_SIZE);
                    Q_dir.next = Q_dir.rear;
                    Q_dir.rear = (Q_dir.rear + 1) % Q_dir.totle_num;
                }
            }
        }
    }
    return dir_num;
}
示例#3
0
void* _recv_buffer_monitor(void* arg) {
	int buf_idx = *(int*)arg;
	Message_t msg;
	for(;;) {
		sem_wait(&g_executor.recv_buffer_num_[buf_idx]);
		if (Queue_Pop(g_executor.recv_buffer_[buf_idx] , &msg) == QUEUE_OK) {
			DistributeMsg(&msg);
			ylfree(msg.package);
		}
	}
	return NULL;
}
AwaError AwaServerSession_DispatchCallbacks(AwaServerSession * session)
{
    AwaError result = AwaError_Unspecified;
    if (session != NULL)
    {
        IPCMessage * notification;
        while (Queue_Pop(session->NotificationQueue, (void **)&notification))
        {
            ServerNotification_Process(session, notification);
            IPCMessage_Free(&notification);
        }
        result = AwaError_Success;
    }
    else
    {
        result = LogErrorWithEnum(AwaError_SessionInvalid, "session is NULL");
    }
    return result;
}
示例#5
0
void* _client_monitor(void* arg) {
	AVOID_NOUSED(arg);
	client_iterator_t iterator;
	iterator.clients_tobe_clear = Queue_Init(sizeof(int));
	for(;;) {
		int interval = 0;
		WRLock_LockR(g_executor.conf_lock_);
		interval = g_executor.pluse_interval_;
		WRLock_UnlockR(g_executor.conf_lock_);
		iterator.pluse_interval = interval;
		iterator.check_time = time(NULL);
		Map_Foreach(g_executor.clients , _foreach_client_ , &iterator);
		int cfd;
		while(Queue_Pop(iterator.clients_tobe_clear , &cfd) == QUEUE_OK) {
			_release_client(cfd , RELEASE_BY_PLUSE);
		}
		sleep(interval);
	}
	return NULL;
}
int main()
{
	system("COLOR 1A");
	Queue *snake = Queue_Init();

	COORD screenResolution = {WIDTH, HEIGHT};
	SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), screenResolution);

	SetConsoleTitle("TU-Snake");

	COORD directions[4] = {
		{0, -1},
		{0, 1},
		{1, 0},
		{-1, 0},
	};

	Direction direction = LEFT;

	unsigned int keyboardInput = 0;
	double snakeSpeed = SnakeSpeed;

	COORD food = {RandomNumber(0, WIDTH), RandomNumber(0, HEIGHT)};
	int centerX = WIDTH / 2;
	int centerY = HEIGHT / 2;

	//InitSnake
	for (int i = 0; i < SnakeInitializeSize; i++)
	{
		COORD position = { centerX - i , centerY};
		Queue_Push(snake, position);
	}

	PrintSnake(snake);

	while (1)
	{
		if (_kbhit() == 1)
		{
			keyboardInput = _getch();

			switch (keyboardInput)
			{
			case 119 : //up
				if (direction != DOWN)
					direction = UP;
				break;
			case 115 : //down
				if (direction != UP)
					direction = DOWN;
				break;
			case 97 : //left
				if (direction != RIGHT)
					direction = LEFT;
				break;
			case 100 : //right
				if (direction != LEFT)
					direction = RIGHT;
				break;
			default:
				break;
			}
		}
		
		COORD snakeHead = Queue_Back(snake);
		COORD nextDirection = directions[direction];
		COORD snakeNewHead = {snakeHead.X + nextDirection.X, snakeHead.Y + nextDirection.Y};

		//check for collisions
		if (snakeNewHead.X < 0 || snakeNewHead.Y < 0 || 
			snakeNewHead.X > WIDTH || snakeNewHead.Y > HEIGHT || Queue_Contains (snake, snakeNewHead))
		{
			char text[] = "!!!Game is over!!!";
			COORD startPoint = {centerX - strlen(text)/2, centerY};
			GoToPosition(startPoint);
			system("COLOR CF");
			printf("%s", text);
			PlaySong();
			break;
		}

		//add new head to snake
		Queue_Push(snake, snakeNewHead);

		//check for grow
		if (snakeNewHead.X == food.X && snakeNewHead.Y == food.Y)
		{
			food.X = RandomNumber(0, WIDTH);
			food.Y = RandomNumber(0, HEIGHT);
			if (snakeSpeed - 1 > 1)
				snakeSpeed--;
		}
		else
		{
			Queue_Pop(snake);	
		}

		PrintSnake(snake);

		GoToPosition(food);
		printf("%c", SnakeFood);


		if (snakeSpeed - 0.1 > 1)
			snakeSpeed -= 0.1;
		Sleep((int)snakeSpeed);
		ClearScreen;
	}

	system("pause > ''");
	return 0;
}
示例#7
0
void Car_QueuePop(void) {
	CarListInit();
	Queue_Pop(CarList);
}