示例#1
0
    void run ()
	{
	    _del_mutex.lock();

	    while ( ! _end )
	    {

            _pool->append_idle( this );

            _work_cond.lock();

            while (( _job == NULL ) && ! _end )
                _work_cond.wait();

            _work_cond.unlock();

            if ( _job != NULL )
            {
                _job->run( _data_ptr );
                _job->unlock();

                if ( _del_job )
                    delete _job;

                _work_cond.lock();
                _job      = NULL;
                _data_ptr = NULL;
                _work_cond.unlock();
            }
	    }

	    _del_mutex.unlock();
	}
示例#2
0
//----------------------------------------------------------------------------
void LockThread(int lock)
{
  static TMutex gcs;
  switch(lock)
  {
    case nsLockThread::eLock:
      gcs.lock();
      break;
    case nsLockThread::eUnlock:
      gcs.unlock();
      break;
  }
}
示例#3
0
        inline bool WaitD(TMutex& lock, TInstant deadLine) throw () {
            if (deadLine == TInstant::Max()) {
                int ret = pthread_cond_wait(&Cond_, (pthread_mutex_t*)lock.Handle());
                VERIFY(ret == 0, "pthread_cond_wait failed: %s", LastSystemErrorText(ret));
                return true;
            } else {
                struct timespec spec;

                Zero(spec);

                spec.tv_sec = deadLine.Seconds();
                spec.tv_nsec = deadLine.NanoSecondsOfSecond();

                int ret = pthread_cond_timedwait(&Cond_, (pthread_mutex_t*)lock.Handle(), &spec);

                VERIFY(ret == 0 || ret == ETIMEDOUT, "pthread_cond_timedwait failed: %s", LastSystemErrorText(ret));

                return ret == 0;
            }
        }
示例#4
0
        inline bool WaitD(TMutex& lock, TInstant deadLine) throw () {
            int ret;

            if (deadLine == TInstant::Max()) {
                ret = pthread_cond_wait(&Cond_, (pthread_mutex_t*)lock.Handle());
            } else {
                struct timespec spec;

                Zero(spec);

                spec.tv_sec = deadLine.Seconds();
                spec.tv_nsec = deadLine.NanoSecondsOfSecond();

                ret = pthread_cond_timedwait(&Cond_, (pthread_mutex_t*)lock.Handle(), &spec);

                YASSERT(ret == 0 || ret == ETIMEDOUT);
            }

            return ret == 0;
        }
示例#5
0
        inline bool WaitD(TMutex& m, TInstant deadLine) throw () {
            TWaitEvent event;

            {
                TGuard<TLock> guard(Lock_);

                Events_.PushBack(&event);
            }

            m.Release();

            const bool signalled = event.WaitD(deadLine);

            m.Acquire();

            {
                TGuard<TLock> guard(Lock_);

                event.Unlink();
            }

            return signalled;
        }