コード例 #1
0
void SC_LanguageClient::tick()
{
    if (trylock()) {
		if (isLibraryCompiled()) {
			::runLibrary(s_tick);
		}
		unlock();
    }
    flush();
}
コード例 #2
0
	bool Conditional::isLocked()
	{
		try {
			trylock();
			leave();
			return false;
		} catch (const ibrcommon::MutexException&) {
			return true;
		}
	}
コード例 #3
0
bool PIpcBuffer::trylock2()
{
	if (!isValid())
		return false;

	PIpcBufferHeader* h = (PIpcBufferHeader*) m_data;
	pthread_mutex_t* mutex2 = &h->mutex2;

	return trylock(mutex2, m_lockCount2);
}
コード例 #4
0
inline
void
Consumer::consume(unsigned D)
{
  /**
   * This is the equivalent of do_send(must_send = 1)
   */
  m_force_send = 1;

  do
  {
    if (trylock(&m_send_lock) != 0)
    {
      /* Other thread will send for us as we set m_force_send. */
      return;
    }

    /**
     * Now clear the flag, and start sending all data available to this node.
     *
     * Put a memory barrier here, so that if another thread tries to grab
     * the send lock but fails due to us holding it here, we either
     * 1) Will see m_force_send[nodeId] set to 1 at the end of the loop, or
     * 2) We clear here the flag just set by the other thread, but then we
     * will (thanks to mb()) be able to see and send all of the data already
     * in the first send iteration.
     */
    m_force_send = 0;
    mb();

    /**
     * This is the equivalent of link_thread_send_buffers
     */
    for (unsigned i = 0; i < cnt_threads; i++)
    {
      val[i] = rep.t[i].t.p.val[D];
    }

    /**
     * Do a syscall...which could have affect on barriers...etc
     */
    if (DO_SYSCALL)
    {
      NdbTick_getCurrentTicks();
    }

    unlock(&m_send_lock);

#if BUGGY_VERSION
#else
    mb();
#endif
  }
  while (m_force_send != 0);
}
コード例 #5
0
ファイル: Thread.cpp プロジェクト: mickelfeng/qt-threads
void Thread::run()
{
  // The idea here is that if another thread locks this thread, that this loop
  // should terminate, thus terminating the execution of this thread.
  while(trylock())
  {
    m_runner->run();
    sleep(1);
    unlock();
  }
}
コード例 #6
0
// Called by RT control loop to send oob data
void EthercatOobCom::tx()
{
  if (!trylock(__LINE__))
    return;

  if (state_ == READY_TO_SEND) {
    // Packet is in need of being sent
    assert(frame_!=NULL);
    handle_ = ni_->tx(frame_, ni_);
    state_ = WAITING_TO_RECV;
    pthread_cond_signal(&busy_cond_);
  } 

  unlock(__LINE__);  
}
コード例 #7
0
ファイル: Mutex.C プロジェクト: makamuy/frob
/* Convenience method */
Mutex::TRY_LOCK_STATUS_T
Mutex::trylock ( const char * theErrorLocation )
{
    Mutex::TRY_LOCK_STATUS_T returnValue = trylock();

    if ( returnValue == Mutex::FAILURE )
    {
        if ( theErrorLocation == (const char *) NULL )
            theErrorLocation = "";

        FLUSHALL();
        cerr << "[" << theErrorLocation << "]  Error:  "
             << "Problems while trylock()'ing mutex." << endl;
    }

    return returnValue;
}
コード例 #8
0
//----------------------------------------------------------------------------
// only allow one thread to execute any of these methods at a time
//----------------------------------------------------------------------------
inline int boost::stm::transaction::dir_tx_conflicting_lock_pthread_trylock_mutex(Mutex *mutex)
{
   //--------------------------------------------------------------------------
   throw "might not be possible to implement trylock for this";

   bool txIsIrrevocable = false;

   int val = trylock(mutex);
   if (0 != val) return val;

   lock(&latmMutex_);

   if (transaction* t = get_inflight_tx_of_same_thread(false))
   {
      txIsIrrevocable = true;
      t->must_be_in_conflicting_lock_set(mutex);
      t->make_irrevocable();
      t->add_to_obtained_locks(mutex); 
   }

   try 
   { 
      //-----------------------------------------------------------------------
      // if !core done, since trylock, we cannot stall & retry - just exit
      //-----------------------------------------------------------------------
      if (!dir_do_core_tx_conflicting_lock_pthread_lock_mutex(mutex, 0, 0, txIsIrrevocable)) 
      {
         unlock(mutex);
         unlock(&latmMutex_);
         return -1;
      }
   }
   catch (...)
   {
      unlock(mutex);
      unlock(&latmMutex_);
      throw;
   }

   latmLockedLocksOfThreadMap_[mutex] = THREAD_ID;
   unlock(&latmMutex_);

   // note: we do not release the transactionsInFlightMutex - this will prevents 
   // new transactions from starting until this lock is released
   return 0;
}
コード例 #9
0
ファイル: Mutex.cpp プロジェクト: caocf/workspace-kepler
  bool timedlock(int64_t milliseconds) const {
#if defined(_POSIX_TIMEOUTS) && _POSIX_TIMEOUTS >= 200112L
    PROFILE_MUTEX_START_LOCK();

    struct timespec ts;
    Util::toTimespec(ts, milliseconds);
    int ret = pthread_mutex_timedlock(&pthread_mutex_, &ts);
    if (ret == 0) {
      PROFILE_MUTEX_LOCKED();
      return true;
    }

    PROFILE_MUTEX_NOT_LOCKED();
    return false;
#else
    // If pthread_mutex_timedlock isn't supported, the safest thing to do
    // is just do a nonblocking trylock.
    return trylock();
#endif
  }
コード例 #10
0
ファイル: Engine.C プロジェクト: elthariel/non-daw
/* THREAD: RT */
int
Engine::process ( nframes_t nframes )
{
    /* FIXME: wrong place for this */
    _thread.set( "RT" );

    if ( ! trylock() )
    {
        /* the data structures we need to access here (tracks and
         * their ports, but not track contents) may be in an
         * inconsistent state at the moment. Just punt and drop this
         * buffer. */
        ++_buffers_dropped;
        return 0;
    }

    _process_callback(nframes, _process_callback_user_data);

    unlock();

    return 0;
}
コード例 #11
0
ファイル: Mutex.C プロジェクト: makamuy/frob
BOOLEAN
Mutex::isLocked()
{
    Mutex::TRY_LOCK_STATUS_T  tryLockStatus;
    switch ( tryLockStatus = trylock() )
    {
    case Mutex::SUCCESS:
        /* We just locked ourself.  If unlock fails... *
         * Well, we are locked...  And probably hosed. */
        switch ( unlock() )
        {
        case ::SUCCESS:
            return FALSE;

        /* If this happens, something truly odd is going on... */
        case ::FAILURE:
        default:
            FLUSHALL();
            cerr << "[Mutex:isLocked]  Internal Failure:  "
                 << "trylock() returned SUCCESS.   unlock() returned FAILURE.  "
                 << "(So we've just locked the mutex.)" << endl;
            return TRUE;
        }

    case Mutex::FAILURE:
        return FALSE;

    case Mutex::ALREADY_LOCKED:
        return TRUE;

    default:
        FLUSHALL();
        cerr << "[Mutex:isLocked]  Impossible Error: tryLock() returned: "
             << int4(tryLockStatus) << ".  Assuming we are locked..." << endl;
        return TRUE; /* Worst case scenario: Assume we are locked. */
    }
}
コード例 #12
0
ファイル: pipe.c プロジェクト: johneh/libmill_worker
static int pipe_read(struct mill_pipe_s *mp, void *ptr) {
    unsigned size = mp->sz;
    int n, total = 0;
    while (1) {
        if (trylock(mp)) {
again:
            n = (int) read(mp->fd[0], (char *) ptr + total, size - total);
            if (mill_slow(n == 0)) {
                /* done */
                mill_assert(total == 0);
                unlock(mp);
                return 0;
            }
            if (n > 0) {
                total += n;
                if (mill_fast(total == size)) {
                    unlock(mp);
                    return total;
                }
                goto again;
            }
            /* n == -1 */
            if (errno == EINTR)
                goto again;
            if (errno == EAGAIN) {
                mill_fdevent(mp->fd[0], FDW_IN, -1);
                goto again;
            }
            unlock(mp);
            break;
        }

        mill_fdevent(mp->fd[0], FDW_IN, -1);
        /* Multiple threads may receive notification. Race for the lock. */
    }
    return -1;
}
コード例 #13
0
ファイル: l4d2.cpp プロジェクト: EarlOfWenc/mumble
static int trylock1() {
	return trylock(std::multimap<std::wstring, unsigned long long int>());
}
コード例 #14
0
ファイル: sync.c プロジェクト: WareX97/K2
void lock(struct lock* m) {
#if SYNC
	task_loop(trylock(m) == -1);
#endif
}