Beispiel #1
0
static void scmdatabase_autostart_services(struct scmdatabase *db)
{
    struct service_entry **services_list;
    unsigned int i = 0;
    unsigned int size = 32;
    struct service_entry *service;

    services_list = HeapAlloc(GetProcessHeap(), 0, size * sizeof(services_list[0]));
    if (!services_list)
        return;

    scmdatabase_lock_shared(db);

    LIST_FOR_EACH_ENTRY(service, &db->services, struct service_entry, entry)
    {
        if (service->config.dwStartType == SERVICE_BOOT_START ||
            service->config.dwStartType == SERVICE_SYSTEM_START ||
            service->config.dwStartType == SERVICE_AUTO_START)
        {
            if (i+1 >= size)
            {
                struct service_entry **slist_new;
                size *= 2;
                slist_new = HeapReAlloc(GetProcessHeap(), 0, services_list, size * sizeof(services_list[0]));
                if (!slist_new)
                    break;
                services_list = slist_new;
            }
            services_list[i] = service;
            service->ref_count++;
            i++;
        }
    }

    scmdatabase_unlock(db);

    size = i;
    for (i = 0; i < size; i++)
    {
        DWORD err;
        const WCHAR *argv[2];
        service = services_list[i];
        argv[0] = service->name;
        argv[1] = NULL;
        err = service_start(service, 1, argv);
        if (err != ERROR_SUCCESS)
            WINE_FIXME("Auto-start service %s failed to start: %d\n",
                       wine_dbgstr_w(service->name), err);
        release_service(service);
    }

    HeapFree(GetProcessHeap(), 0, services_list);
}
Beispiel #2
0
//Sleep until arrival time then populate thread structures
void* thread_control(void *arg) {
	struct timeval t1;
	struct customer_struct *customer = (struct customer_struct *)arg;
	unsigned int sleep = (*customer).a_time * 100000u; 
	double elapsed;

	//Have to accomidate for the time the program has taken to get to this point
	/* Elapsed time */
    gettimeofday(&t1, NULL);
	sleep = ((*customer).a_time * 100000 + (t0.tv_sec-t1.tv_sec)*1000000 - t1.tv_usec + t0.tv_usec);
	if (usleep(sleep) == -1) {
		perror("Error on sleep");
		return;
	}

	//Print arrival
		printf("Customer %2d arrives: arrival time (%.2f), service time (%.1f), priority (%2d). \n", (*customer).customer_no, (*customer).a_time/10.0f, (*customer).s_time/10.0f,(*customer).priority);

	/* Thread structures are populated by the customer_struct */
	request_service(customer);
	pthread_mutex_unlock(&mutex1);

	//Get current customer
	current_cust_no = (*customer).customer_no;

 	/* Elapsed time */
    gettimeofday(&t1, NULL);
	elapsed = ((t1.tv_sec-t0.tv_sec)*1000000 + t1.tv_usec-t0.tv_usec)/1000000.0;
	printf("The clerk starts serving customer %2d at time %.2f. \n", current_cust_no, elapsed);

	//Sleep for the service time;
	sleep = (*customer).s_time * 100000u;
	if (usleep(sleep) == -1) {
		perror("Error on sleep");
	}

	/* This function will make the clerk available again and wake up the waiting threads to again compete for the service*/
	release_service(current_cust_no);
	live_threads--;
	return;
}