示例#1
0
	static void* execute_thread(void * ptr)
	{
		Runnable* runnable = static_cast<Runnable*>(ptr);
		assert(runnable);
		runnable->run();
		pthread_exit(NULL);
	}
示例#2
0
 void AsyncTaskExecutor::run()
 {
     while(_isRunning)
     {
         std::unique_lock<std::mutex> lock(_mutex);
         if(!_queue.empty())
         {
             Runnable *task = _queue.front();
             _queue.pop_front();
             if(task!=NULL)
             {
                 _isBusy = true;
                 _currentTask = task;
                 lock.unlock();
                 task->run();
                 lock.lock();
                 _currentTask = NULL;
                 if(task->toDelete())
                     delete task;
             }
         }
         else if(_isRunning)
         {
             _isBusy = false;
             _signal.wait(lock);
         }
     }
     return;
 }
示例#3
0
void
RunnableHandler::handleEvent( void * e)
{
    Runnable *r = reinterpret_cast< Runnable * > (e);
    r->run();
    if( d_->del_ )
    {
        delete r;
    }
}
示例#4
0
void *Thread_Unix::thread_main(void *data)
{
	// kill thread immediately - no cancellation point
	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, nullptr);

	Runnable *runnable = (Runnable *)data;
	ThreadLocalStorage tls;
	runnable->run();
	return nullptr;
}
示例#5
0
	virtual void handleMessage(const Message& message) {
		switch (message.what) {
		case 4:
		case 5: {
			Runnable* runnable = (Runnable*) message.obj;
			runnable->run();
			break;
		}
		default:
			Log::i(LOG_TAG, "Handler1::handleMessage 0x%x with ID %d by Looper 0x%x", &message, message.what, Looper::myLooper());
		}
	}
示例#6
0
void ThreadQueue::onStarted()
{
    Runnable* r;

    // qDebug() << "has started";

    while ((r = hasMore()) != NULL)
    {
        //qDebug() << "executing next from list" << r->name();
        QVariant result = r->run();
        emit     finished(r, result);
    }
    thread()->quit();
}
示例#7
0
 void TaskExecutor::executeAll()
 {
     std::lock_guard<std::mutex> lock(_mutex);
     while(!_queue.empty())
     {
         Runnable *task = _queue.front();
         _queue.pop_front();
         if(task!=NULL)
         {
             task->run();
             if(task->toDelete())
                 delete task;
         }
     }
 }
            /**
             * This method encapsulates the runnable.
             */
            void *threadRunner(void *v) {
                pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
                Runnable *runnable = static_cast<Runnable*>(v);

                try {
                    runnable->run();
                } catch (string &s) {
                    clog << "Exception caught at " << __FILE__ << ":" << __LINE__ << ": " << s << endl;
                    throw;
                } catch (...) {
                    clog << "Unknown exception caught at " << __FILE__ << ":" << __LINE__ << "." << endl;
                    throw;
                }

                return NULL;
            }
示例#9
0
void PooledThread::run()
{
	_started.set();
	for (;;)
	{
		_targetReady.wait();
		_mutex.lock();
		if (_pTarget) // a NULL target means kill yourself
		{
			_mutex.unlock();
			try
			{
				_pTarget->run();
			}
			catch (Exception& exc)
			{
				ErrorHandler::handle(exc);
			}
			catch (std::exception& exc)
			{
				ErrorHandler::handle(exc);
			}
			catch (...)
			{
				ErrorHandler::handle();
			}
			FastMutex::ScopedLock lock(_mutex);
			_pTarget  = 0;
#if defined(_WIN32_WCE) && _WIN32_WCE < 0x800
			_idleTime = wceex_time(NULL);
#else
			_idleTime = time(NULL);
#endif	
			_idle     = true;
			_targetCompleted.set();
			ThreadLocalStorage::clear();
			_thread.setName(_name);
			_thread.setPriority(Thread::PRIO_NORMAL);
		}
		else
		{
			_mutex.unlock();
			break;
		}
	}
}
示例#10
0
void PooledThread::run()
{
    m_started.set();
    for (;;)
    {
        m_targetReady.wait();
        m_mutex.lock();
        if (m_pTarget) // a NULL target means kill yourself
        {
            m_mutex.unlock();
            try
            {
                m_pTarget->run();
            }
            catch (const FirteXException&)
            {
                throw;
            }
            catch (const exception& exc)
            {
                FIRTEX_THROW(RuntimeException, "%s", exc.what());
            }
            catch (...)
            {
                FIRTEX_THROW(RuntimeException, "Unknow exception.");
            }
            FastMutex::Guard lock(m_mutex);
            m_pTarget = NULL;
            m_idleTime = time(NULL);
            m_bIdle = true;
            m_targetCompleted.set();
//	    ThreadLocalStorage::clear();
            m_thread.setName(m_sName);
            m_thread.setPriority(Thread::PRIO_NORMAL);

            m_pool.broadcast();
        }
        else
        {
            m_bIdle = true;
            m_mutex.unlock();
            break;
        }
    }
}
示例#11
0
                void threadLogic()
                {
                    try
                    {
                        while(!STOP_FLAG)
                        {
                            Runnable *runnable = workQueue.pull();

                            if(runnable != NULL)
                            {
                                runnable->run();
                                delete runnable;
                            }
                        }
                    }
                    catch(const boost::thread_interrupted&)
                    { }
                }; 
示例#12
0
	/**
	 * システムコールバック用エントリポイント
	 * Mutex作成後にConstructorのcreateOnRunフラグ動作用のMutexを追加して
	 * この関数内の頭に仕込んでおく必要があるな・・・
	 */
	static void* CallbackDispatcher(void* DispatchKey)
	{
		PosixThread* This = reinterpret_cast<PosixThread*>(DispatchKey);
		assert(dynamic_cast<PosixThread*>(This) != NULL);

		// wait for start signal.
		ScopedLock<PosixMutex> lock(This->starter);

		int retValue = 0;

		{
			ScopedLock<PosixMutex> lock(This->statusSync);
			This->isRun = true;
		}

		try 
		{
			Runnable* entry = This->getRunningTarget();
			entry->prepare();
			retValue = entry->run();
			entry->dispose();
		}
		catch (ThreadException& e)
		{
			This->transporter = new ThreadException(e);
			retValue = abort_by_exception;
		}
		catch (...)
		{
			This->transporter =	new ThreadException("unknown exception.");
			retValue = abort_by_exception;
		}

		{
			ScopedLock<PosixMutex> lock(This->statusSync);
			This->isRun = false;
		}

		pthread_exit(reinterpret_cast<void*>(retValue));

		return 0;
	}
示例#13
0
 void
 Thread::Run::exec(void) {
   while (true) {
     // Execute runnable
     {
       Runnable* e;
       m.acquire();
       e=r; r=NULL;
       m.release();
       assert(e != NULL);
       e->run();
       delete e;
     }
     // Put into idle stack
     Thread::m()->acquire();
     n=Thread::idle; Thread::idle=this;
     Thread::m()->release();
     // Wait for next runnable
     e.wait();
   }
 }
示例#14
0
    void run()
    {
        while (true)
        {

            if (mRequest->isEmpty())
            {
                cout << "exiting run()" << endl;
                return;
            }

            // Pull a runnable off the queue
            Runnable *handler;
            mRequest->dequeue(handler);

            // Run the runnable that we pulled off the queue
            handler->run();

            // Delete the runnable we pulled off the queue
            delete handler;

        }
    }
示例#15
0
文件: Thread.cpp 项目: JaonLin/PinPP
VOID Thread::__thr_run (VOID * arg)
{
  // Get the thread object, and update its remaining attributes.
  Thread * thr = reinterpret_cast <Thread *> (arg);
  
  // Set the current thread to the Thread object. This allows the
  // client to access the Thread object via the current () method.
  Thread::current_.set (thr->thr_id_, thr);
  
  do
  {
    Write_Guard <RW_Mutex> guard (thr->rw_mutex_);
    thr->os_thr_id_ = PIN_GetTid ();
    thr->parent_os_thr_id_ = PIN_GetParentTid ();
    
    // Set the state to running.
    thr->state_ = RUNNING;
  } while (0);

  // Determine what run method we should invoke. Either we invoke the run()
  // method on the runnable_ object contained in the thread, or we invoke
  // the run() method on the thread. The runnable_ variable takes precedence
  // over the run() method on the Thread.
  Runnable * runnable = thr->runnable_;

  if (0 == runnable)
    runnable = thr;

  runnable->run ();

  do
  {
    // Reset the thread state.
    Write_Guard <RW_Mutex> guard (thr->rw_mutex_);
    thr->state_ = TERMINATED;
  } while (0);
}
示例#16
0
void ProgressDialog::show(Runnable& r, void* parentWindow)
{
    LOG_ERROR << "ProgressDialog is not implemented on this platform";

    r.run();
}
示例#17
0
bool Thread::cancel() {
#ifdef _WIN32
    if (created_) {
        if (TerminateThread(thread_handle_, -1)) { //This can be unsafe! Use with caution.
#endif
#ifdef __gnu_linux__
    if (created_ && !completed_) {
        if (pthread_cancel(thread_handle_)) {
#endif
            suspended_ = false;
            running_ = false;
            completed_ = true;
            return true;
        }
        return false;
    }
    return true;
}

int32_t Thread::getExitCode() {
    return thread_exit_code_;
}

bool Thread::started() {
    return started_;
}

bool Thread::completed() {
    return completed_;
}

bool Thread::validTarget() {
    return (target_ != NULL);
}

bool Thread::created() {
    return created_;
}

bool Thread::isThreadSuspended() {
    return suspended_;
}

bool Thread::isThreadRunning() {
    return running_;
}

Runnable* Thread::getTarget() {
    return target_;
}

#ifdef _WIN32
bool Thread::create() {
    if (target_ != NULL) {
        DWORD temp;
        thread_handle_ = CreateThread(NULL, 0, &Thread::runLaunchpad, target_, CREATE_SUSPENDED, &temp);
        if (thread_handle_ == NULL)
            return false;
        thread_id_ = static_cast<uint32_t>(temp);
        created_ = true;
        suspended_ = true;

        return true;
    }
    return false;
}
#endif

#ifdef _WIN32
bool Thread::start() {
    if (created_) {
        if (ResumeThread(thread_handle_) == (DWORD)-1) //error condition check
            return false;

        started_ = true;
        running_ = true;
        suspended_ = false;
        return true;
    }
    return false;
}
#endif

#ifdef _WIN32
DWORD Thread::runLaunchpad(void* target_runnable_object) {
    if (target_runnable_object != NULL) {
        Runnable* target = static_cast<Runnable*>(target_runnable_object);
        target->run();
        return 0;
    }
    return 1;
}
#endif

#ifdef __gnu_linux__
void* Thread::runLaunchpad(void* target_runnable_object) {
    int32_t* thread_retval = new int32_t;
    *thread_retval = 1;
    if (target_runnable_object != NULL) {
        Runnable* target = static_cast<Runnable*>(target_runnable_object);
        target->run();
        *thread_retval = 0;
        return static_cast<void*>(thread_retval);
    }
    return static_cast<void*>(thread_retval);
}
示例#18
0
DWORD WINAPI ThreadProc(LPVOID msg) {
    Runnable* task = (Runnable*)msg;
    task->run();
    delete task;
    return 0;
}
示例#19
0
	void * Thread::startThread(void * vself)
	{
		Runnable* pRun = (Runnable*)(vself);	
		pRun->run();
		return 0;
	};
示例#20
0
DWORD WINAPI Thread::entryPoint(LPVOID parameter)
{
    Runnable* runnable = (Runnable*)parameter;
    runnable->run();
    return 666;
}
示例#21
0
void* Thread::_run(void *pthis)
{
  Runnable* r = static_cast<Runnable*>(pthis);
  r->run();
  return NULL;
}
示例#22
0
文件: thread.cpp 项目: courtc/imager
static void __posal_mm_thread_fn(void *data)
{
	Runnable *r = static_cast<Runnable *>(data);

	r->run();
}
示例#23
0
int Runnable::run(void *data) {
    Runnable *runnable = (Runnable *)data;
    runnable->run();
    return 0; //TODO
}