コード例 #1
0
void CudaWorkerThread::execute()
{
	WorkerMessage* message = 0;
	
	report("CUDAWorker thread is alive, waiting for command.");
	
	threadReceive(message);
	while(message->type != WorkerMessage::Kill)
	{
		report(" Received message " << message << ", type " << message->type);
		try
		{
			switch(message->type)
			{
			case WorkerMessage::Wait:
			{
				report(" Waiting for all kernels to finish "
					<< " on thread " << id() << ".");
				while(!_launches.empty())
				{
					_launchNext();
				}

				threadSend(message);
				break;
			}
			case WorkerMessage::Launch:
			{
				report(" Received kernel launch message.");
				_launches.push(*message->launch);

				delete message->launch;
				delete message;
				break;
			}
			default: assertM(false, "Invalid message type.");
			}
		}
		catch(const hydrazine::Exception& e)
		{
			report("Operation failed, replying with exception.");
			assertM(false, "Multi-threaded exeptions not supported.");
		}
		
		if(!_launches.empty())
		{
			_launchNext();
		}
		
		threadReceive(message);
	}

	report("Received kill command, joining.");
	threadSend(message);
}
コード例 #2
0
void LLVMWorkerThread::execute()
{
	WorkerMessage*             message;
	LLVMCooperativeThreadArray cta(this);
	
	report("LLVMWorker thread is alive, waiting for command.");
	
	threadReceive(message);
	while(message->type != WorkerMessage::Kill)
	{
		try
		{
			switch(message->type)
			{
			case WorkerMessage::LaunchCta:
			{
				report(" Launching CTA " << message->ctaId 
					<< " on thread " << id() << ".");
				cta.executeCta(message->ctaId);
				threadSend(message);
			}
			break;
			case WorkerMessage::SetupCta:
			{
				report(" Setting up CTA for kernel '" << message->kernel->name 
					<< "' on thread " << id() << ".");
				cta.setup(*message->kernel);
				threadSend(message);
			}
			break;
			case WorkerMessage::FlushCta:
			{
				report(" Flushing translation cache on thread " << id() << ".");
				cta.flushTranslatedKernels();
				threadSend(message);
			}
			break;
			default: assertM(false, "Invalid message type.");
			}
		}
		catch(const hydrazine::Exception& e)
		{
			report("Operation failed, replying with exception.");
			message->type         = WorkerMessage::Exception;
			message->errorMessage = e.what();
			threadSend(message);
		}
		threadReceive(message);
	}

	report("Received kill command, joining.");
	threadSend(message);
}
コード例 #3
0
ファイル: CurlTest.cpp プロジェクト: Group2/The-New-Lines
void CurlTest::recv(CCObject* pSender)
{
    CCLOG("waiting for connection");
    ENetEvent event;

    while (enet_host_service (server, & event, 10000) > 0) {
        if(event.type==ENET_EVENT_TYPE_CONNECT) {
            CCLOG("connected %x:%u.\n",
                  event.peer -> address.host,
                  event.peer -> address.port);
            char* temp;
            temp = "Client";
            event.peer -> data = temp;
            peer = event.peer;
            initStartGame();

            std::thread threadRecv(ThreadRecv);
            std::thread threadSend(ThreadSend);
            return;
            /*				pthread_t threadRecv;
            				pthread_t threadSend;
            				pthread_create(&threadRecv, NULL, &ThreadRecv, NULL);
            				pthread_create(&threadSend, NULL, &ThreadSend, NULL);	*/
        }
        if(event.type==ENET_EVENT_TYPE_DISCONNECT) {
            CCLOG("%s disconected.\n", event.peer -> data);
            enet_peer_reset (peer);
        }
    }
    pLabel-> setString("time out");
}
コード例 #4
0
ファイル: CurlTest.cpp プロジェクト: Group2/The-New-Lines
void CurlTest::send(CCObject* pSender)
{
    ENetAddress address;
    ENetEvent event;
    char ip[50];
    strcpy(ip, pTextField->getString ());
    /* Connect to IP:1234. */
    CCLOG("ip: %s", ip);
    enet_address_set_host (& address, ip);
    address.port = 1234;
    /* Initiate the connection, allocating the two channels 0 and 1. */
    peer = enet_host_connect (server, & address, 1, 0);
    if (peer == NULL) {
        CCLOG("No available peers for initiating an ENet connection.\n");
        return;
    }
    /* Wait up to 5 seconds for the connection attempt to succeed. */
    if (enet_host_service (server, & event, 5000) > 0 && event.type == ENET_EVENT_TYPE_CONNECT)
    {
        CCLOG ("Connection to IP:1234 succeeded.");
        initStartGame();
    }
    else
    {
        CCLOG ("Connection to host:1234 failed.");
        enet_peer_reset (peer);
        pLabel-> setString("connect fail");
        return;
    }

    std::thread threadRecv(ThreadRecv);
    std::thread threadSend(ThreadSend);

    /*	pthread_t threadRecv;
    	pthread_t threadSend;
    	pthread_create(&threadRecv, NULL, &ThreadRecv, NULL);
    	pthread_create(&threadSend, NULL, &ThreadSend, NULL);	*/
}
コード例 #5
0
LLVMModuleManager::FunctionId LLVMWorkerThread::getFunctionId(
	const std::string& moduleName, const std::string& functionName)
{
	LLVMModuleManager::GetFunctionMessage message;
	
	message.type       = LLVMModuleManager::DatabaseMessage::GetId;
	message.moduleName = moduleName;
	message.kernelName = functionName;
	
	threadSend(&message, LLVMModuleManager::id());
	
	LLVMModuleManager::GetFunctionMessage* reply = 0;
	threadReceive(reply);
	assert(reply == &message);
	
	if(message.type == LLVMModuleManager::DatabaseMessage::Exception)
	{
		report("Re-throwing exception");
		throw hydrazine::Exception(message.errorMessage);
	}
	
	return message.id;
}
コード例 #6
0
LLVMModuleManager::MetaData* LLVMWorkerThread::getFunctionMetaData(
	const LLVMModuleManager::FunctionId& id)
{
	LLVMModuleManager::GetFunctionMessage message;
	
	message.type = LLVMModuleManager::DatabaseMessage::GetFunction;
	message.id   = id;
	
	threadSend(&message, LLVMModuleManager::id());
	
	LLVMModuleManager::GetFunctionMessage* reply = 0;
	threadReceive(reply);
	assert(reply == &message);
	
	if(message.type == LLVMModuleManager::DatabaseMessage::Exception)
	{
		report("Re-throwing exception");
		throw hydrazine::Exception(message.errorMessage);
	}
	
	assert(message.type == LLVMModuleManager::DatabaseMessage::GetFunction);
	
	return message.metadata;
}