Exemplo n.º 1
0
  /*! creates a hardware thread running on specific core */
  thread_t createThread(thread_func f, void* arg, size_t stack_size, ssize_t threadID)
  {
#ifdef __MIC__
    threadID++; // start counting at 1 on MIC
#endif

    /* set stack size */
    pthread_attr_t attr;
    pthread_attr_init(&attr);
    if (stack_size > 0) pthread_attr_setstacksize (&attr, stack_size);

    /* create thread */
    pthread_t* tid = new pthread_t;
    if (pthread_create(tid,&attr,(void*(*)(void*))threadStartup,new ThreadStartupData(f,arg,threadID)) != 0)
      THROW_RUNTIME_ERROR("pthread_create");

    /* attempt to set affinity */
#if defined(__LINUX__)
    if (threadID >= 0) {
      cpu_set_t cset;
      CPU_ZERO(&cset);
      CPU_SET(threadID, &cset);
      pthread_setaffinity_np(*tid,sizeof(cpu_set_t),&cset);
    }
#endif

    return thread_t(tid);
  }
Exemplo n.º 2
0
 /*! creates a hardware thread running on specific core */
 thread_t createThread(thread_func f, void* arg, size_t stack_size, ssize_t threadID)
 {
   HANDLE thread = CreateThread(nullptr, stack_size, (LPTHREAD_START_ROUTINE)threadStartup, new ThreadStartupData(f,arg), 0, nullptr);
   if (thread == nullptr) FATAL("CreateThread failed");
   if (threadID >= 0) setAffinity(thread, threadID);
   return thread_t(thread);
 }
Exemplo n.º 3
0
 /*! creates a hardware thread running on specific core */
 thread_t createThread(thread_func f, void* arg, size_t stack_size, ssize_t threadID)
 {
   HANDLE thread = CreateThread(NULL, stack_size, (LPTHREAD_START_ROUTINE)threadStartup, new ThreadStartupData(f,arg), 0, NULL);
   if (thread == NULL) THROW_RUNTIME_ERROR("cannot create thread");
   if (threadID >= 0) setAffinity(thread, threadID);
   return thread_t(thread);
 }
Exemplo n.º 4
0
  /*! creates a hardware thread running on specific core */
  thread_t createThread(thread_func f, void* arg, size_t stack_size, ssize_t threadID)
  {
    /* set stack size */
    pthread_attr_t attr;
    pthread_attr_init(&attr);
    if (stack_size > 0) pthread_attr_setstacksize (&attr, stack_size);
    
    /* set affinity */
#if defined(__LINUX__)
    if (threadID >= 0) {
      cpu_set_t cset;
      CPU_ZERO(&cset);
      CPU_SET(threadID, &cset);
      pthread_attr_setaffinity_np(&attr,sizeof(cpu_set_t),&cset);
    }
#endif

    /* create thread */
    pthread_t* tid = new pthread_t;
    if (pthread_create(tid,&attr,(void*(*)(void*))threadStartup,new ThreadStartupData(f,arg,threadID)) != 0)
      throw std::runtime_error("pthread_create");

    return thread_t(tid);
  }
Exemplo n.º 5
0
s32 cellMsgDialogOpen2(u32 type, vm::cptr<char> msgString, vm::ptr<CellMsgDialogCallback> callback, vm::ptr<void> userData, vm::ptr<void> extParam)
{
	cellSysutil.Warning("cellMsgDialogOpen2(type=0x%x, msgString=*0x%x, callback=*0x%x, userData=*0x%x, extParam=*0x%x)", type, msgString, callback, userData, extParam);

	if (!msgString || strlen(msgString.get_ptr()) >= 0x200 || type & -0x33f8)
	{
		return CELL_MSGDIALOG_ERROR_PARAM;
	}

	switch (type & CELL_MSGDIALOG_TYPE_BUTTON_TYPE)
	{
	case CELL_MSGDIALOG_TYPE_BUTTON_TYPE_NONE:
	{
		if (type & CELL_MSGDIALOG_TYPE_DEFAULT_CURSOR)
		{
			return CELL_MSGDIALOG_ERROR_PARAM;
		}
		switch (type & CELL_MSGDIALOG_TYPE_PROGRESSBAR)
		{
		case CELL_MSGDIALOG_TYPE_PROGRESSBAR_NONE: break;
		case CELL_MSGDIALOG_TYPE_PROGRESSBAR_SINGLE: break;
		case CELL_MSGDIALOG_TYPE_PROGRESSBAR_DOUBLE: break;
		default: return CELL_MSGDIALOG_ERROR_PARAM;
		}
		break;
	}

	case CELL_MSGDIALOG_TYPE_BUTTON_TYPE_YESNO:
	{
		switch (type & CELL_MSGDIALOG_TYPE_DEFAULT_CURSOR)
		{
		case CELL_MSGDIALOG_TYPE_DEFAULT_CURSOR_YES: break;
		case CELL_MSGDIALOG_TYPE_DEFAULT_CURSOR_NO: break;
		default: return CELL_MSGDIALOG_ERROR_PARAM;
		}
		if (type & CELL_MSGDIALOG_TYPE_PROGRESSBAR)
		{
			return CELL_MSGDIALOG_ERROR_PARAM;
		}
		break;
	}

	case CELL_MSGDIALOG_TYPE_BUTTON_TYPE_OK:
	{
		if (type & CELL_MSGDIALOG_TYPE_DEFAULT_CURSOR)
		{
			return CELL_MSGDIALOG_ERROR_PARAM;
		}
		if (type & CELL_MSGDIALOG_TYPE_PROGRESSBAR)
		{
			return CELL_MSGDIALOG_ERROR_PARAM;
		}
		break;
	}

	default: return CELL_MSGDIALOG_ERROR_PARAM;
	}

	MsgDialogState old = msgDialogNone;
	if (!g_msg_dialog->state.compare_exchange_strong(old, msgDialogInit))
	{
		return CELL_SYSUTIL_ERROR_BUSY;
	}

	g_msg_dialog->wait_until = get_system_time() + 31536000000000ull; // some big value

	switch (type & CELL_MSGDIALOG_TYPE_PROGRESSBAR)
	{
	case CELL_MSGDIALOG_TYPE_PROGRESSBAR_DOUBLE: g_msg_dialog->progress_bar_count = 2; break;
	case CELL_MSGDIALOG_TYPE_PROGRESSBAR_SINGLE: g_msg_dialog->progress_bar_count = 1; break;
	default: g_msg_dialog->progress_bar_count = 0; break;
	}

	switch (type & CELL_MSGDIALOG_TYPE_SE_MUTE) // TODO
	{
	case CELL_MSGDIALOG_TYPE_SE_MUTE_OFF: break;
	case CELL_MSGDIALOG_TYPE_SE_MUTE_ON: break;
	}

	std::string msg = msgString.get_ptr();

	switch (type & CELL_MSGDIALOG_TYPE_SE_TYPE)
	{
	case CELL_MSGDIALOG_TYPE_SE_TYPE_NORMAL: cellSysutil.Warning("%s", msg); break;
	case CELL_MSGDIALOG_TYPE_SE_TYPE_ERROR: cellSysutil.Error("%s", msg); break;
	}

	g_msg_dialog->status = CELL_MSGDIALOG_BUTTON_NONE;

	CallAfter([type, msg]()
	{
		if (Emu.IsStopped())
		{
			g_msg_dialog->state.exchange(msgDialogNone);

			return;
		}

		g_msg_dialog->Create(type, msg);

		g_msg_dialog->state.exchange(msgDialogOpen);
	});

	while (g_msg_dialog->state == msgDialogInit)
	{
		if (Emu.IsStopped())
		{
			if (g_msg_dialog->state != msgDialogNone)
			{
				break;
			}

			CHECK_EMU_STATUS;
		}

		std::this_thread::sleep_for(std::chrono::milliseconds(1)); // hack
	}

	thread_t(WRAP_EXPR("MsgDialog Thread"), [=]()
	{
		while (g_msg_dialog->state == msgDialogOpen || (s64)(get_system_time() - g_msg_dialog->wait_until) < 0)
		{
			if (Emu.IsStopped())
			{
				g_msg_dialog->state = msgDialogAbort;
				break;
			}
			std::this_thread::sleep_for(std::chrono::milliseconds(1)); // hack
		}

		if (callback && g_msg_dialog->state != msgDialogAbort)
		{
			const s32 status = g_msg_dialog->status;

			Emu.GetCallbackManager().Register([=](CPUThread& CPU) -> s32
			{
				callback(static_cast<PPUThread&>(CPU), status, userData);
				return CELL_OK;
			});
		}

		CallAfter([]()
		{
			g_msg_dialog->Destroy();
			g_msg_dialog->state = msgDialogNone;
		});

	}).detach();

	return CELL_OK;
}
void Thread::start()
{
	this->thread = thread_t(&Thread::run, this);
}
Exemplo n.º 7
0
 void AssignThreadsAlgorithm::apply(Stream& stream)
 {            
     const std::vector<Operator*> & operators = stream.initializedOperators();
     if (operators.size() == 0)
         return;
     
     // create the graph
     Graph graph;
     
     std::map<const Operator*, Graph::vertex_descriptor> op2VertexMap;
     
     // fill the maps
     for(std::vector<Operator*>::const_iterator op = operators.begin();
         op != operators.end();
         ++op)
     {
         
         Graph::vertex_descriptor v = boost::add_vertex(graph);
         boost::put(operator_t(), graph, v, *op);
         op2VertexMap[*op] = v;
     }
     
     // iterate over each operator
     for(std::vector<Operator*>::const_iterator op = operators.begin();
         op != operators.end();
         ++op)
     {
         const std::vector<const Description*> & inputs = (*op)->info().inputs();
         for(std::vector<const Description*>::const_iterator input = inputs.begin();
             input != inputs.end();
             ++input)
         {
             Output connector = stream.connectionSource(*op, (*input)->id());
             if(connector.valid())
             {
                 const Operator* source = connector.op();
                 const Operator* target = *op;
                 const Description& output = source->info().output(connector.id());
                 
                 Graph::edge_descriptor e = boost::add_edge(op2VertexMap[source], op2VertexMap[target], graph).first;
                 
                 std::map<Graph::vertex_descriptor, int> operatorThreads;
                 operatorThreads[op2VertexMap[source]] = output.operatorThread();
                 operatorThreads[op2VertexMap[target]] = (*input)->operatorThread();
                 
                 boost::put(operator_thread_t(), graph, e, operatorThreads);
                 boost::put(thread_t(), graph, e, NO_THREAD);
                 boost::put(connector_id_t(), graph, e, (*input)->id());
             }
         }
     }
     
     int numThreads = 0;
     Visitor v(numThreads);
     boost::undirected_dfs<>(graph, root_vertex(Graph::vertex_descriptor(0)).visitor(v)
                             .edge_color_map(get(edge_color, graph)));
     
     // delete all threads
     while(stream.threads().size())
         stream.removeThread(stream.threads().front());
     
     // create threads
     for (int i = 0; i < numThreads; ++i)
         stream.addThread();
         
     // add the inputs to the threads
     graph_traits<Graph>::edge_iterator ei, ei_end;
     for (boost::tie(ei, ei_end) = edges(graph); ei != ei_end; ++ei)
     {
         int thread = boost::get(thread_t(), graph, *ei);
         if (thread == NO_THREAD)
             continue; 
             
         unsigned int id = boost::get(connector_id_t(), graph, *ei);
         Graph::vertex_descriptor v = boost::target(*ei, graph);
         Operator* op = boost::get(operator_t(), graph, v);
         stream.threads()[thread]->addInput(op, id);
     }
 }