示例#1
0
void run_airline(Airline* self, ipc_t conn) {

    mprintf("Dude\n");
    ipcConn = conn;
    me = self;

    register_exit_function(NULL);
    //redirect_signals();

    Vector* threads = bootstrap_planes(self, conn);
    planeThreads = threads;

    listen(threads);

    // If we got here, it means we recieved an end message
    struct Message msg;
    msg.type = MessageTypeEnd;
    broadcast(threads, msg);

    for (size_t i = 0; i < self->numberOfPlanes; i++) {
        struct PlaneThread* t = getFromVector(threads, i);
        pthread_join(t->thread, NULL);
        message_queue_destroy(t->queue);
        free(t);
    }

    destroyVector(threads);
    mprintf("Out of run_airline\n");
}
示例#2
0
BOOL initialise_direct_sound ( void )
{

	static int
		direct_sound_initialised = FALSE;

	if ( !direct_sound_initialised )
	{

		if ( dsound_initialise () )
		{

			register_exit_function ( dsound_release_objects );

			register_post_activate_message_function ( dsound_restore_objects );

			direct_sound_initialised = TRUE;

			set_fpu_rounding_mode_zero ();

			return ( TRUE );
		}
		else
		{

			return ( FALSE );
		}
	}

	return ( TRUE );
}
示例#3
0
BOOL initialise_file_system ( void )
{

	int
		count;

	file_maps = safe_malloc ( sizeof ( filemap ) * MAX_NUMBER_FILES );

	for ( count = 0; count < MAX_NUMBER_FILES; count++ )
	{

		file_maps[count].used = FALSE;
		file_maps[count].hFile = 0;
		file_maps[count].hMap = 0;
		file_maps[count].data = NULL;
	}

	register_exit_function ( deinitialise_file_system );

	return ( TRUE );
}
示例#4
0
static void internal_initialise_input_system ( void )
{

	unsigned int
		ret;

	//
	// We always need to create the DirectInput device - the joystick always uses it.
	//
#ifdef _WIN32
	ret = DirectInputCreateEx ( application_instance, DIRECTINPUT_VERSION, &IID_IDirectInput7, &direct_input, NULL );

	if ( ret != DI_OK )
	{

		debug_fatal ( "Unable to create DirectInput" );
	}
#endif
	initialise_keyboard ();

	initialise_mouse ();

	register_exit_function ( deinitialise_input_system );
}
示例#5
0
int
measure_system_wide(pfmon_ctx_t *ctx, char **argv)
{
	void *retval;
	unsigned long i, j, num_cpus;
	int ret;

	master_tid       = gettid();
	master_thread_id = pthread_self();

printf("sizeof=%zu %zu\n", sizeof(syswide_barrier_t), sizeof(barrier.pad));

	setup_global_signals();

	if (options.opt_aggr) {
		/*
		 * used by syswide_aggregate_results()
		 */
		pfmon_clone_sets(options.sets, &sdesc_sys_aggr);

		if (pfmon_setup_aggr_sampling_output(&sdesc_sys_aggr) == -1) 
			return -1;
	}

	session_state = SESSION_INIT;

	num_cpus = options.selected_cpus;

	vbprintf("system wide session on %lu processor(s)\n", num_cpus);

	pthread_barrier_init(&barrier.barrier, NULL, num_cpus+1);

	pthread_key_create(&param_key, NULL);

	register_exit_function(exit_system_wide);

	for(i=0, j=0; num_cpus; i++) {
		
		if (pfmon_bitmask_isset(options.virt_cpu_mask, i) == 0) continue;

		thread_desc[j].id    = j;
		thread_desc[j].cpu   = i;

		thread_desc[j].thread_state = THREAD_STARTED;
		thread_desc[j].ctx   = ctx;

		ret = pthread_create(&thread_desc[j].thread_id, 
				     NULL, 
				     (void *(*)(void *))do_measure_one_cpu, 
				     thread_desc+j);

		if (ret != 0) goto abort;

		DPRINT(("created thread[%u], %d\n", j, thread_desc[j].thread_id));

		num_cpus--;
		j++;
	}

	/* reload number of cpus */
	num_cpus = options.selected_cpus;

	for (j=0; j < num_cpus;) {
		DPRINT(("nthread_ok=%d ncpus=%d\n", j, num_cpus));
		/*
		 * poll thread state for errors
		 */
		for(i=0, j=0; i < num_cpus; i++) {
			if (thread_desc[i].thread_state == THREAD_ERROR)
				goto abort;
			if (thread_desc[i].thread_state == THREAD_RUN)
				j++;
		}
	}
	session_state = SESSION_RUN;

	if (delimit_session(argv) == -1) goto abort;

	/*
	 * set end of session and unblock all threads
	 */
	session_state = SESSION_STOP;

	/*
	 * get worker thread out of their mainloop
	 */
	for (i=0; i < num_cpus; i++) {
		if (thread_desc[i].thread_state != THREAD_ERROR)
			pthread_kill(thread_desc[i].thread_id, SIGUSR1);
	}

	DPRINT(("main thread after session stop\n"));

	for(i=0; i< num_cpus; i++) {
		ret = pthread_join(thread_desc[i].thread_id, &retval);
		if (ret !=0) warning("cannot join thread %u\n", i);
		DPRINT(("CPU%-4u session exited with value %ld\n", thread_desc[i].cpu, (unsigned long)retval));
	}

	if (options.opt_aggr) {
		print_results(&sdesc_sys_aggr); /* mask taken from options.virt_cpu_mask */
		if (options.opt_use_smpl)
			pfmon_close_aggr_sampling_output(&sdesc_sys_aggr);
	}

	pthread_key_delete(param_key);

	register_exit_function(NULL);

	if (options.opt_verbose && options.opt_use_smpl) {
		num_cpus = options.selected_cpus;
		for(i=0; num_cpus; i++) { 
			if (pfmon_bitmask_isset(options.virt_cpu_mask, i)) {
				vbprintf("CPU%-4u %"PRIu64" sampling buffer overflows\n", i, ovfl_cnts[i]);
				num_cpus--;
			}
		}
	}

	return 0;
abort:
	session_state = SESSION_ABORTED;

	if (session_state == SESSION_RUN) 
		for (i=0; i < num_cpus; i++)
			if (thread_desc[i].thread_id) {
				DPRINT(("killing thread %d\n", i));
				pthread_kill(thread_desc[i].thread_id, SIGUSR1);
			}

	num_cpus = options.selected_cpus;
	vbprintf("aborting %lu sessions\n", num_cpus);

	for(i=0; i < num_cpus; i++) {
		DPRINT(("cancelling on CPU%lu\n", i));
		pthread_cancel(thread_desc[i].thread_id);
	}

	for(i=0; i < num_cpus; i++) {
		ret = pthread_join(thread_desc[i].thread_id, &retval);
		if (ret != 0) warning("cannot join thread %i\n", i);
		DPRINT(("CPU%-3d thread exited with value %ld\n", thread_desc[i].cpu, (unsigned long)retval));
	}

	pthread_key_delete(param_key);

	register_exit_function(NULL);

	return -1;
}
示例#6
0
文件: cdrom.c 项目: Comanche93/eech
int capture_cd_audio_device ( void )
{

	DWORD
		value;

	char
		cdrom_element_name[4];

	DWORD
		dwFlags;

	MCI_OPEN_PARMS
		open_parameters;

	memset ( &open_parameters, 0, sizeof ( MCI_OPEN_PARMS ) );

	open_parameters.lpstrDeviceType = ( LPTSTR ) MCI_DEVTYPE_CD_AUDIO;

	if ( cdrom_file_drive_index != -1 )
	{

		//
		// We found a CD drive which we want to use for music
		//

		sprintf ( cdrom_element_name, "%c:", cdrom_drives[cdrom_file_drive_index] );

		open_parameters.lpstrElementName = cdrom_element_name;
	
		open_parameters.lpstrAlias = "CD Apache Havoc";
	
		dwFlags = MCI_OPEN_ELEMENT | MCI_OPEN_SHAREABLE | MCI_OPEN_ALIAS | MCI_OPEN_TYPE | MCI_OPEN_TYPE_ID | MCI_WAIT;
	}
	else
	{

		//
		// We haven't looked for a CD drive - just use the standard cdaudio
		//

		dwFlags = MCI_OPEN_TYPE | MCI_OPEN_TYPE_ID | MCI_OPEN_SHAREABLE;
	}

	value = mciSendCommand ( 0, MCI_OPEN, dwFlags, ( DWORD ) ( LPVOID ) &open_parameters );

	if ( value )
	{

		debug_log ( "Unable to capture cd audio" );

		return ( FALSE );
	}
	else
	{

		MCI_SET_PARMS
			set_parameters;

		//
		// Get the device ID.
		//

		cdrom_device_id = open_parameters.wDeviceID;

		//
		// Set the cdrom format to tracks/minutes/seconds/frames
		//

		set_parameters.dwTimeFormat = MCI_FORMAT_TMSF;

		value = mciSendCommand ( cdrom_device_id, MCI_SET, MCI_SET_TIME_FORMAT, ( DWORD ) ( LPVOID ) &set_parameters );

		if ( value )
		{

			//
			// Release the device - it can't handle us!
			//

			debug_log ( "Unable to set cd audio format" );

			mciSendCommand ( cdrom_device_id, MCI_CLOSE, 0, 0 );

			return ( FALSE );
		}

		cdrom_device_captured = TRUE;

		register_exit_function ( release_cd_audio_device );

		return ( TRUE );
	}
}