Exemplo n.º 1
0
void SPEGangContext::Destroy() {
	if(ptr)
		if(( spe_gang_context_destroy(ptr) ) != 0)
			THROW("Error while destroying gang context: ", strerror(errno));
}
Exemplo n.º 2
0
/* Spu control function */
void * spuCtrlFunc(void *arg) {
	int i;
	SpuThreadData * spu_data;
	struct ctrl_thread_args * ctrlArgs = *((struct ctrl_thread_args **) ctrlArgs);
	
	if ((spu_data = (SpuThreadData *) malloc(sizeof(SpuThreadData))) == NULL) {
		perror("Failed to allocate SPU data\n");
	}

	spu_data->boot_record = ctrlArgs->boot_record;
	spu_data->main_boot_record = ctrlArgs->main_boot_record;

	// initialize threads
	startSpuThreads(ctrlArgs->no_spus, spu_data);
	initJavaThreads(spu_data, MAX_JAVA_SPU_THREADS);

	free(ctrlArgs);

	// register interest in events
	registerEventHandlers(spu_data);

	// wait for the threads to signal that they have started
	waitForSpus(spu_data);

	// transfer runtime code to spus
	loadRuntimeOnSpus(spu_data);

	// wait for SPU to transition to Java runtime
	waitForRuntime(spu_data);

	global_spu_data = spu_data;

	// start support threads
	startSpuSupportThreads(spu_data);

	// signal completion of SPU boot process
	spu_data->boot_record->noSubArchProcs = spu_data->no_spu_threads;
	spu_data->boot_record->subArchBootComplete = 1;

	// now sit waiting for the kill signal
	pthread_mutex_lock(&exit_mutex);
	pthread_cond_wait(&exit_signal, &exit_mutex);
  pthread_mutex_unlock(&exit_mutex);

	/* shutdown other threads */		
	for (i=0; i<spu_data->no_spu_threads; i++) {
		if (pthread_cancel (spu_data->spus[i].boot_thread)) {
			perror("Failed to shutdown Cell SPU thread");
			exit (1);
		}
		
		if (pthread_cancel (spu_data->spus[i].support_thread)) {
			perror("Failed to shutdown Cell SPU support thread");
			exit (1);
		}

		// destroy resources
		spe_event_handler_destroy(spu_data->spus[i].evnt_handler);
		spe_context_destroy(spu_data->spus[i].ctx);
	}
	spe_gang_context_destroy(spu_data->gang);
}