Esempio n. 1
0
	virtual void tick() {
		switch( style ) {
			case 0: {	// divizion by zero
				int a = 10;
				int b = 3;
				b-=3;
				a /= b;
				break;
					}
			case 1: {	// throw (int) exception
				throw 0;
				break;
					}

			case 2: {	// NULL pointer with vtable
				IThread *thread = NULL;
				thread->isActive();
				break;
					}

			case 3: {	// invalid pointer with vtable
				IThread *thread = (IThread *)0x335337L;
				thread->isActive();
				break;
					}

			case 4: {
				mykillingstackmachine(1, 2, 3, 4, 5, 6);
				break;
					}
		}
	}
Esempio n. 2
0
UTILSRUNTIME_API ITimer* Utils::Thread::CreateTimer(unsigned long millisec_interval, bool bEnable/* = true*/)
{
	IThread *pThread = Utils::Thread::GetCurrentThread();
	if (pThread == NULL)
		throw std::runtime_error("No thread object detected.");
	return pThread->NewTimer(millisec_interval, bEnable);
}
Esempio n. 3
0
TEST(IThread, Test1) {
  class ThreadHandle: public IThread {
   public:
    ThreadHandle():num(1) {}
    virtual ~ThreadHandle() {}
   private:
   public:
    virtual void run() {
      ASSERT_EQ(num, 1u);
      num = 2;
    }
   public:
    size_t num;
  };
  {
    ThreadHandle thr;
    thr.start();
    thr.join();
    ASSERT_EQ(thr.num, 2u);
  }
  {
    IThread* ptr = new ThreadHandle();
    ptr->start();
    ptr->join();
    delete ptr;
  }
}
Esempio n. 4
0
int main(int argc, char* argv[])
{
  try
    {
      IThread* serverThread = new Thread;
      IThread* clientThread = new Thread;

      ServerData sdata;
      sdata.isServer = (argc >= 2);
      sdata.serverThread = serverThread;
      serverThread->run(serverCallback, &sdata);

      ClientData cdata;
      cdata.isServer = (argc >= 2);
      cdata.login = "******";
      if (argc >= 2)
	cdata.login = argv[1];
      cdata.clientThread = clientThread;
      if (sdata.isServer)
	sleep(2);
      clientThread->run(clientCallback, &cdata);

      clientThread->wait();
      delete clientThread;
      delete serverThread;
    }
  catch (IThread::Exception& e)
    {
      std::cerr << "Babel error: " << e.what() << std::endl; 
    }
  std::cout << "Bye" << std::endl;
  return 0;
}
Esempio n. 5
0
unsigned int BaseWorker::RunFrame()
{
	unsigned int done = 0;
	unsigned int max = GetMaxThreadsPerFrame();
	SWThreadHandle *swt = NULL;
	IThread *pThread = NULL;

	while (done < max)
	{
		if ((swt=PopThreadFromQueue()) == NULL)
		{
			break;
		}
		pThread = swt->pThread;
		swt->m_state = Thread_Running;
		pThread->RunThread(swt);
		swt->m_state = Thread_Done;
		pThread->OnTerminate(swt, false);
		if (swt->m_params.flags & Thread_AutoRelease)
		{
			delete swt;
		}
		done++;
	}

	return done;
}
Esempio n. 6
0
void Server::stop() {
	IThread* pThread = getThreadThrowIfNotStarted();
	if ( ! pThread->isAlive() ) {
		cleanUp();
	} else {
		runnable->getWindowController()->close();
	}
}
Esempio n. 7
0
void*
Thread_wrapper( void* self )
{
	IThread* ithread = (IThread*) self;
	LPTHREAD_START_ROUTINE callback = (LPTHREAD_START_ROUTINE) ithread->callback;

	ithread->ret = (DWORD) ithread->callback( ithread->arg );
	ExitThread( ithread->ret );
}
Esempio n. 8
0
int main(int /*argc*/, char* /*argv*/ [])
{
  IThread* mainThread = IThread::createThread(mainProc, (void*)"main");
  mainThread->run();
  mainThread->join();
  printf("main end\n");
  IThread::deleteThread(mainThread);
  return 0;
}
Esempio n. 9
0
THREADPROC IThread::__ThreadProc(void* lParam) 
{
    srand( (unsigned)time( NULL ) + (unsigned)IThread::s_ThreadCount );
    IThread* pThread = (IThread *)lParam;
    IThread::s_ThreadCount++;
    pThread->_Run();
    pThread->OnExit();
    IThread::s_ThreadCount--;
    return NULL;
}
void startStatThread()
{
	if(startStat)
	{
		curl_global_init(CURL_GLOBAL_ALL);
		//nlinfo("startStatThread");
		CStatThread *statThread = new CStatThread();
		IThread	*thread = IThread::create (statThread);
		nlassert (thread != NULL);
		thread->start ();
	}
}
void startWebigNotificationThread()
{
	static bool startedWebigNotificationThread = false;
	if(!startedWebigNotificationThread)
	{
		curl_global_init(CURL_GLOBAL_ALL);
		//nlinfo("startStatThread");
		CWebigNotificationThread *webigThread = new CWebigNotificationThread();
		IThread	*thread = IThread::create (webigThread);
		nlassert (thread != NULL);
		thread->start ();
		startedWebigNotificationThread = true;
	}
}
Esempio n. 12
0
IThread *ThreadHolder::current()
{
	init();

	IThread * thread = m_currentThread;
	if (thread == NULL)
		return DummySphereThread::getInstance();

#ifdef _WIN32
	ASSERT(thread->getId() == ::GetCurrentThreadId());
#else
	ASSERT(thread->getId() == (unsigned)pthread_self());
#endif
	return thread;
}
Esempio n. 13
0
ThreadPool::ThreadPool(int const nbThread)
{
    IThread *thread;
    for (unsigned int i=0; i < nbThread; ++i)
    {
#ifdef _WIN32
		thread = new ThreadWin();
#else
		thread = new Thread();
#endif
        GameEngine *engine = new GameEngine();
        thread->create(reinterpret_cast<void *>(&launchGameEngine), engine);
        _pool.push_back(std::pair<IThread*, GameEngine *>(thread, engine));
    }
}
Esempio n. 14
0
/*
 * 1 scénario / niveau (map)
 * 
 * Scénario:
 * Type obj, cycle, coord
 * 
 * Script obj:
 * debut cycle, fin cycle, coord vecteur directeur, 
 * 
 * type tir, frequence
 * 
 * scenario contient par cycle le niveau
 * 
 */
int main(int argc, char** argv)
{
	(void)argc;
	(void)argv;
#ifdef WIN32
	std::cout << "Win32" << std::endl;
#elif _WIN32
	std::cout << "_Win32" << std::endl;
#elif __WIN32
	std::cout << "__Win32" << std::endl;
#elif __CYGWIN__
	std::cout << "cygwin" << std::endl;
#else
	std::cout << "Autre" << std::endl;
#endif
//	GameObject* gg = new GameObject;
	IThread *thread = new Thread();
    IThread *manag = new Thread();
    IServer *server = new ServerTCP();
	
	thread->create(reinterpret_cast<void*>(&launchServer), server);
    manag->create(reinterpret_cast<void*>(&launchManager), server);
    manag->join();
	
//	CrossLoader *loader = new CrossLoader();
//		
//	try
//	{
//		loader->checkLibraries();
//	}
//	catch (std::exception &e)
//	{
//		std::cout << e.what() << std::endl;
//	}
//	loader->LoadLibrary("tim.dll");
//	loader->LoadSymbole();
//	loader->CloseLibrary();
//	Parser *parser = new Parser();
//	try
//	{
//		parser->load("Starwars");
//	}
//	catch (std::exception &e)
//	{
//		std::cout << e.what() << std::endl;
//	}
	return 0;
}
Esempio n. 15
0
// starts a thread
static void* start_thread(void* param)
{
    KLKASSERT(param != NULL);

    IThread* thread = static_cast<IThread*>(param);
    if (thread == NULL)
    {
        KLKASSERT(thread != NULL);
        return NULL;
    }

    // ignore several signals in threads
    sigset_t sigset;
    sigemptyset(&sigset);
    sigaddset(&sigset, SIGTERM);
    sigaddset(&sigset, SIGINT);
    sigaddset(&sigset, SIGPIPE);
    pthread_sigmask(SIG_SETMASK, &sigset, NULL);

    try
    {
        // all threads should be able to communicate with db
        // check thread safety
        BOOST_ASSERT(mysql_thread_safe() == 1);

        if (mysql_thread_init() != 0)
        {
            throw Exception(__FILE__, __LINE__,
                            "Error in mysql_thread_init()");
        }

        thread->start();
    }
    catch(const std::exception& err)
    {
        klk_log(KLKLOG_ERROR, "Got an exception during thread execution: %s",
                err.what());
    }
    catch(...)
    {
        klk_log(KLKLOG_ERROR,
                "Got an unknown exception during thread execution");
    }
    mysql_thread_end();

    return NULL;
}
 bool SimpleThreadpoolBehaviour::clean()
 {
     ThreadCollectionIter aIter = _pool.begin();
     IThread * aTemp = 0;
     for(;aIter != _pool.end(); aIter++)
     {
         aTemp = (*aIter);
         if(aTemp)
         {
             aTemp->stop();
             delete aTemp;
             (*aIter) = 0;
             aTemp = 0;
         }
     }
     return true;
 }
Esempio n. 17
0
extern "C" void RISCV_break_simulation() {
    AttributeType t1;
    IThread *ith;
    RISCV_get_services_with_iface(IFACE_THREAD, &t1);

    for (unsigned i = 0; i < t1.size(); i++) {
        ith = static_cast<IThread *>(static_cast<IThread *>(t1[i].to_iface()));
        ith->breakSignal();
    }

    IHap *ihap;
    for (unsigned i = 0; i < listHap_.size(); i++) {
        ihap = static_cast<IHap *>(listHap_[i].to_iface());
        if (ihap->getType() == HAP_BreakSimulation) {
            ihap->hapTriggered(HAP_BreakSimulation);
        }
    }
}
Esempio n. 18
0
void			ThreadsManager::newThread(void *(*p_func)(void *), void *p_data)
{
    struct thread_data_container	*bullshit = new struct thread_data_container;
    IThread							*newElem;

    bullshit->data = p_data;
    bullshit->function = p_func;
    bullshit->locker = this->_vectorMutex;
#ifndef	_WIN32
    newElem = new UThread(&ThreadsManager::launcher, (void *)bullshit);
#else
    newElem = new WThread(&ThreadsManager::launcher, (void *)bullshit);
#endif
    bullshit->threads = &this->_threads;
    bullshit->me = newElem;
    newElem->startThread();
    this->_threads.push_back(newElem);
}
Esempio n. 19
0
	static void *(entry_point)(void *_this)
	{
		IThread *self = static_cast<IThread<T, U> *>(_this);

		self->setStatus(Running);
		self->_func_ptr(self->getId(), self->getParameter());
		self->setStatus(Stopped);
		MutexVault::getMutexVault()->remove(self->getId());
		return (NULL);
	}
Esempio n. 20
0
void * IThread::threadfunc( void * arg )
{
    IThread * thread = (IThread *)arg;

    sigset_t mask;
    sigfillset(&mask);
    pthread_sigmask(SIG_SETMASK, &mask, NULL);

    // 线程开始
    if ( thread->onStart() )
    {
        while ( thread->isRunning() )
        {
            thread->onExecute();
        }
    }

    // 线程停止了
    thread->onStop();

    // 通知调用者, 线程已经停止了
    thread->notify();

    return NULL;
}
Esempio n. 21
0
void	ManageRoom::handleCreateGame(void *buffer, Client *cl)
{
	t_TCPCreate *create;
	create = (t_TCPCreate *)buffer;

	Room *room = new Room;

	room->setGameId(this->currentGameId);
	room->setNbMax(create->nb_max);
	room->setName(create->name_game);
	std::cout << "Creating room=" << room->getName() << std::endl;
	char id = room->addClient(cl);
	std::cout << (int)id  << std::endl;
	this->listRoom[this->currentGameId++] = room;
	int i = 0;
	int len;
	const char *str = cl->getName().c_str();
	ISocket *sock;
	t_TCPPlayer Player;

	//On prépare le packet pour prévenir le joueur de sa connection à la partie créée

	while (str[i])
		Player.name[i] = str[i++];
	Player.name[i] = '\0';
	Player.player_id = id;
	Player.status = NOT_READY;
	Player.header.packetSize = sizeof(Player);
	Player.header.type = PLAYER;

	sock = cl->getSocket();
	this->_access[sock->getIp()] = room;
	IThread *th = new WinThread;

	std::cout <<"LOOOOOOOOOOOL" << std::endl;
	th->create(initGame, room);
	std::cout << "LOOOL2"<< std::endl;
	if ((len = sock->sendBinary(&Player, sizeof(Player))) < 0)
		std::cout << "Error while sending Create" << std::endl;
}
Esempio n. 22
0
	//--------------------------------------------------------------------
	void IThread::run(void* _mythread)
	{
		// try to cast the given parameter to IThread pointer
		IThread* mythread = static_cast<IThread*>(_mythread);
		if (mythread == NULL)
		{
			NR_Log(Log::LOG_KERNEL, Log::LL_ERROR, "IThread: not valid parameter was specified for IThread::run(void*) method");
			return;
		}
		
		// now loop the thread until some messages occurs
		bool run = true;
		while (run){

			// kernel requested to suspend the thread
			if (mythread->mThreadState == THREAD_NEXT_SUSPEND)
			{
				// notice about suspending and go into sleep mode
				mythread->changeState(THREAD_SLEEPING);
				mythread->_noticeSuspend();

			// kernel requested to resume the execution
			}else if (mythread->mThreadState == THREAD_NEXT_RESUME)
			{
				// notice about resuming the work and start it again
				mythread->changeState(THREAD_RUNNING);
				mythread->_noticeResume();

			// kernel does not requested anything, so run the task
			}else if (mythread->mThreadState == THREAD_RUNNING)
			{
				mythread->_noticeUpdate();
			}

			// check for the stop message, then stop the thread
			// this is a reading mutex, so do not have to lock it
			run = mythread->mThreadState != THREAD_STOP;

			// we now yield the used timeslice for another threads
			yield(mythread);
		}
		
		// notice to stop the underlying task
		mythread->_noticeStop();

		// exit the thread
		//return NULL;
	}
Esempio n. 23
0
void testThreadsRunningAndTerminating() {
	// ONE stopped, TWO stopped
	IThread *one = new ThreadSimple();
	IThread *two = new ThreadSimple();

	assert(one->getId() == 0);
	assert(!one->isActive());
	assert(two->getId() == 0);
	assert(!two->isActive());
	assert(ThreadHolder::getActiveThreads() == 0);

	// ONE started, TWO started
	one->start();
	two->start();

	assert(one->getId() != 0);
	assert(one->isActive());
	assert(two->getId() != 0);
	assert(two->isActive());
	assert(ThreadHolder::getActiveThreads() == 2);

	Sleep(USUAL_DELAY);

	// ONE stopped, TWO started
	one->terminate();

	assert(one->getId() == 0);
	assert(!one->isActive());
	assert(two->getId() != 0);
	assert(two->isActive());
	assert(ThreadHolder::getActiveThreads() == 1);

	Sleep(USUAL_DELAY);

	// ONE started, TWO started
	one->start();

	assert(one->getId() != 0);
	assert(one->isActive());
	assert(two->getId() != 0);
	assert(two->isActive());
	assert(ThreadHolder::getActiveThreads() == 2);

	Sleep(USUAL_DELAY);

	// ONE stopped, TWO stopped
	one->terminate();
	two->terminate();

	assert(one->getId() == 0);
	assert(!one->isActive());
	assert(two->getId() == 0);
	assert(!two->isActive());
	assert(ThreadHolder::getActiveThreads() == 0);

	delete one;
	delete two;
}
Esempio n. 24
0
static void*	runCallback(void* arg)
{
  IThread* thread = (IThread*) arg;
  thread->getTask()->operator()();
  thread->setRunning(false);
}
Esempio n. 25
0
static void CreateHookWindow(void)
{
	hookWindowThread.Start(HookWindowThread);
}
Esempio n. 26
0
int main(int argc, char* argv[]) {
    int cfgsz = 0;
    char path[1024];
    bool loadConfig = true;
    bool disableSim = true;
    AttributeType scriptFile("");

    // Parse arguments:
    if (argc > 1) {
        for (int i = 1; i < argc; i++) {
            if (strcmp(argv[i], "-nocfg") == 0) {
                loadConfig = false;
            } else if (strcmp(argv[i], "-sim") == 0) {
                disableSim = false;
            } else if (strcmp(argv[i], "-script") == 0) {
                i++;
                scriptFile.make_string(argv[i]);
            }
        }
    }

    // Select configuration input (default/stored file):
    RISCV_init();
    RISCV_get_core_folder(path, sizeof(path));
    std::string cfg_filename = std::string(path) 
                    + std::string(JSON_CONFIG_FILE);

    if (loadConfig) {
        cfgsz = RISCV_read_json_file(cfg_filename.c_str(), cfgbuf, 
                                    static_cast<int>(sizeof(cfgbuf)));
    }

    // Convert string to attribute:
    if (cfgsz == 0) {
        Config.from_config(default_config);
    } else {
        Config.from_config(cfgbuf);
    }

    // Enable/Disable simulator option:
    Config["GlobalSettings"]["SimEnable"].make_boolean(!disableSim);
    //scriptFile.make_string("");
    Config["GlobalSettings"]["ScriptFile"] = scriptFile;

    RISCV_set_configuration(&Config);
   
    // Connect simulator to the EDCL debugger if enabled:
    if (!disableSim) {
        IUdp *iudp1 = static_cast<IUdp *>
                (RISCV_get_service_iface("udpboard", IFACE_UDP));
        IUdp *iudp2 = static_cast<IUdp *>
                (RISCV_get_service_iface("udpedcl", IFACE_UDP));

        AttributeType t1 = iudp1->getConnectionSettings();
        iudp2->setTargetSettings(&t1);
        t1 = iudp2->getConnectionSettings();
        iudp1->setTargetSettings(&t1);
    }

    void *obj = glip_tcp_create(PORT, WIDTH);

    // Working cycle with console:
    IThread *in = static_cast<IThread *>(RISCV_get_service_iface("console0", IFACE_THREAD));
    edcl_itap = static_cast<ITap *>(RISCV_get_service_iface("edcltap", IFACE_TAP));

    if (in) {
        while (in->isEnabled()) {
	  //            RISCV_sleep_ms(100);
	    glip_tcp_toplevel(obj);
        }
    }

    /*
    const char *t1 = RISCV_get_configuration();
    RISCV_write_json_file(cfg_filename.c_str(), t1);
    */

    RISCV_cleanup();
	return 0;
}
Esempio n. 27
0
void Server::join() {
	IThread* pThread = getThreadThrowIfNotStarted();
	pThread->join();
	cleanUp();
}
Esempio n. 28
0
void* CG_CALLBACK IThread::ThreadFunction(void* pParam)
{
    IThread* pThis = (IThread*)pParam;
    return (void*)pThis->Run();
}
Esempio n. 29
0
 static void * Worker(void * data) {
   IThread * ptr = (IThread* ) data;
   ptr->Run();
   return NULL;
 }