static gpointer sync_thread_func(gpointer data)
{
    EeeAccountsManager *mgr = data;
    int i;

    g_return_val_if_fail(IS_EEE_ACCOUNTS_MANAGER(mgr), NULL);

    while (TRUE)
    {
loop:
        switch (g_atomic_int_get(&mgr->priv->sync_request))
        {
        case SYNC_REQ_PAUSE:
            g_usleep(1000000);
            g_thread_yield();
            break;

        case SYNC_REQ_START:
            g_usleep(5000000);
            g_atomic_int_set(&mgr->priv->sync_request, SYNC_REQ_RESTART);
            break;

        case SYNC_REQ_RUN:
            for (i = 0; i < 30; i++)
            {
                g_usleep(1000000);
                if (g_atomic_int_get(&mgr->priv->sync_request) != SYNC_REQ_RUN)
                {
                    goto loop;
                }
            }

        case SYNC_REQ_RESTART:
            g_atomic_int_set(&mgr->priv->sync_request, SYNC_REQ_RUN);
            run_idle(sync_starter, mgr);
            if (g_atomic_int_get(&mgr->priv->sync_request) != SYNC_REQ_RUN)
            {
                break;
            }
            eee_accounts_manager_sync_phase1(mgr);
            if (g_atomic_int_get(&mgr->priv->sync_request) != SYNC_REQ_RUN)
            {
                break;
            }
            run_idle(sync_completer, mgr);
            break;

        case SYNC_REQ_STOP:
            return NULL;
        }
    }

    return NULL;
}
Example #2
0
int main()
{
	int end_time;
	int queue_limit;
	int flight_number=0;
	double arrival_rate,departure_rate;
	initialize(end_time,queue_limit,arrival_rate,departure_rate);
	Random variable(false);
	Runway small_airport(queue_limit);
	for(int current_time=0;current_time<end_time;current_time++){
		int number_arrivals=variable.poisson(arrival_rate);
		for(int i=0;i<number_arrivals;i++){
			Plane current_plane(flight_number++,current_time,arriving);
			if(small_airport.can_land(current_plane)!=true)current_plane.refuse();
		}
		int number_departures=variable.poisson(departure_rate);
		for(int j=0;j<number_departures;j++){
			Plane current_plane(flight_number++,current_time,departing);
			if(small_airport.can_depart(current_plane)!=true)current_plane.refuse();
		}
		Plane moving_plane;
		switch(small_airport.activity(current_time,moving_plane)){
			case lands:
				moving_plane.land(current_time);
				break;
			case takeoffs:
				moving_plane.fly(current_time);
				break;
			case idle:
				run_idle(current_time);
		}
	}
	small_airport.shut_down(end_time);
	system("pause");
	return 0;
}
Example #3
0
/* Program extracts from Chapter 3 of
int main() // Airport simulation program
/*
 Pre: The user must supply the number of time intervals the simulation is to run
 , the expected number of planes arriving, the expected number of planes
 departing per time interval, and the maximum allowed size for runway queues.
 Post: The program performs a random simulation of the airport, showing the
 status of the runway at each time interval, and prints out a summary of airport
 operation at the conclusion.
 Uses: Classes Runway, Plane, Random and functions run_idle, initialize.
 */
{
    int end_time;       // time to run simulation
    int queue_limit;    // size of Runway queues
    int flight_number = 0;
	bool used = false;
	bool fall = false;
    double arrival_rate, departure_rate, fuel_rate;
    initialize(end_time, queue_limit, arrival_rate, departure_rate, fuel_rate);
    Random variable;
    Runway small_airport(queue_limit);
    for (int current_time = 0; current_time < end_time; current_time++) {
		used = false;
		fall = false;
        // loop over time intervals
        int number_arrivals = variable.poisson(arrival_rate);
		//int number_arrivals;
		//std::cout << current_time <<":input ARRIVALS plane number:";
		//std::cin >> number_arrivals;
		//std::cout << std::endl;
        // current arrival requests
        for(int i = 0; i < number_arrivals; i++) {
			int fuel = variable.poisson(fuel_rate);
            Plane current_plane(flight_number++, current_time, fuel, arriving);
            if (small_airport.can_land(current_plane, used, current_time) != success)
                current_plane.refuse();
        }
		//int number_departures;
		//std::cout << current_time << ":input DEPARTURES plane number:";
		//std::cin >> number_departures;
		//std::cout << std::endl;
        int number_departures = variable.poisson(departure_rate);
        // current departure requests
        for (int j = 0; j < number_departures; j++) {
			int fuel = variable.poisson(fuel_rate);
            Plane current_plane(flight_number++, current_time, fuel, departing);
            if (small_airport.can_depart(current_plane) != success)
                current_plane.refuse();
        }
        Plane moving_plane;
		if (!used)
        switch (small_airport.activity(current_time, moving_plane)) {
            // Let at most one Plane onto the Runway at current_time.
            case land:
				fall = false;
                moving_plane.land(current_time, fall);
				if (fall) {
					small_airport.shut_down(current_time);
					return 0;
				}
				used = true;
				break;
            case takeoff:
                moving_plane.fly(current_time);
				used = true;
                break;
            case idle:
                run_idle(current_time);
        }
    }
    small_airport.shut_down(end_time);
}