示例#1
0
/**
 * fetch a players order
 * and creates corresponding fleets
 * This function is a possible exit point if orders from players are incorrects
 */
void *fetch_player_orders(void *args)
{
    char line[LINE_SIZE];
    struct ARGS *arg = args;
	
    fgets(line, LINE_SIZE, arg->P->in);
    while (strcmp(line, "go\n") != 0) {
        struct fleet *f = malloc(sizeof(*f));
        fgets(line, LINE_SIZE, arg->P->in);
        sscanf(line, "%d %d %d", &f->src, &f->dst, &f->nb_ships);
        pthread_mutex_lock(arg->mutex);
        if (*(arg->stop)) {
            pthread_mutex_unlock(arg->mutex);
            free(f);
            pthread_exit((void*) 1);
        }
        nqueue_push(arg->order_queue, f);
        pthread_mutex_unlock(arg->mutex);
    }

    pthread_mutex_lock(arg->mutex);
    (*(arg->count))++;
    if (*(arg->count) >= arg->nb_players)
        pthread_cond_signal(arg->cond);
    pthread_mutex_unlock(arg->mutex);
    pthread_exit((void*) 0);
}
示例#2
0
文件: global.c 项目: easymc/easymc
static void global_init(void){
	int index = 0;
	if(!self.initialized){
#if defined (EMC_WINDOWS)
		WSADATA	wsaData = {0};
		WSAStartup(MAKEWORD(2, 2), &wsaData);
#endif
		self.devices = hashmap_new(GLOBAL_DEVICE_DEFAULT);
		self.plugs = hashmap_new(EMC_MAX_PLUG);
		self.mg = merger_new(EMC_SOCKETS_DEFAULT);
		self.upk = unpack_new(EMC_SOCKETS_DEFAULT);
		self.id_allocator = create_nqueue();
		for(index = 0; index < EMC_SOCKETS_DEFAULT; index ++){
			nqueue_push(self.id_allocator, index);
		}
		self.sq = create_sendqueue();
		self.rcmq = create_map(EMC_MAX_PLUG);
		srand((uint)time(NULL));
		self.treconnect = emc_thread(global_reconnect_cb, NULL);
		self.initialized = 1;
	}
}
示例#3
0
文件: global.c 项目: easymc/easymc
void global_idle_connect_id(int id){
	nqueue_push(self.id_allocator, id);
}