예제 #1
0
bool interprocess_mutex::lock_slow(boost::detail::winapi::HANDLE_ abort_handle)
{
    uint32_t old_state = m_shared_state->m_lock_state.load(boost::memory_order_relaxed);
    mark_waiting_and_try_lock(old_state);

    if ((old_state & lock_flag_value) != 0u) try
    {
        do
        {
            if (!m_event.wait(abort_handle))
            {
                // Wait was interrupted
                m_shared_state->m_lock_state.fetch_sub(1u, boost::memory_order_acq_rel);
                return false;
            }

            clear_waiting_and_try_lock(old_state);
        }
        while ((old_state & lock_flag_value) != 0u);
    }
    catch (...)
    {
        m_shared_state->m_lock_state.fetch_sub(1u, boost::memory_order_acq_rel);
        throw;
    }

    return true;
}
예제 #2
0
파일: mutex.cpp 프로젝트: qiutaoleo/hpx
    bool mutex::timed_lock(::boost::system_time const& wait_until)
    {
        HPX_ITT_SYNC_PREPARE(this);
        if (try_lock_internal()) {
            HPX_ITT_SYNC_ACQUIRED(this);
            util::register_lock(this);
            return true;
        }

        boost::uint32_t old_count =
            active_count_.load(boost::memory_order_acquire);
        mark_waiting_and_try_lock(old_count);

        if (old_count & lock_flag_value)
        {
            // wait for lock to get available
            bool lock_acquired = false;
            do {
                if (wait_for_single_object(wait_until))
                {
                    // if this timed out, just return false
                    --active_count_;
                    HPX_ITT_SYNC_CANCEL(this);
                    return false;
                }
                clear_waiting_and_try_lock(old_count);
                lock_acquired = !(old_count & lock_flag_value);
            } while (!lock_acquired);
        }
        HPX_ITT_SYNC_ACQUIRED(this);
        util::register_lock(this);
        return true;
    }
예제 #3
0
void interprocess_mutex::lock_slow()
{
    uint32_t old_state = m_shared_state->m_lock_state.load(boost::memory_order_relaxed);
    mark_waiting_and_try_lock(old_state);

    if ((old_state & lock_flag_value) != 0u) try
    {
        do
        {
            m_event.wait();
            clear_waiting_and_try_lock(old_state);
        }
        while ((old_state & lock_flag_value) != 0u);
    }
    catch (...)
    {
        m_shared_state->m_lock_state.fetch_sub(1u, boost::memory_order_acq_rel);
        throw;
    }
}