Exemple #1
0
    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;
    }
Exemple #2
0
        void lock(char const* description, error_code& ec = throws)
        {
            HPX_ASSERT(threads::get_self_ptr() != 0);

            HPX_ITT_SYNC_PREPARE(this);
            mutex_type::scoped_lock l(mtx_);

            threads::thread_id_repr_type self_id = threads::get_self_id().get();
            if(owner_id_ == self_id)
            {
                HPX_ITT_SYNC_CANCEL(this);
                HPX_THROWS_IF(ec, deadlock,
                    "mutex::unlock",
                    "The calling thread already owns the mutex");
                return;
            }

            if (owner_id_ != threads::invalid_thread_id_repr)
            {
                cond_.wait(l, ec);
                if (ec) { HPX_ITT_SYNC_CANCEL(this); return; }
            }

            util::register_lock(this);
            HPX_ITT_SYNC_ACQUIRED(this);
            owner_id_ = self_id;
        }
Exemple #3
0
        bool try_lock_until(util::steady_time_point const& abs_time,
            char const* description, error_code& ec = throws)
        {
            HPX_ASSERT(threads::get_self_ptr() != 0);

            HPX_ITT_SYNC_PREPARE(this);
            mutex_type::scoped_lock l(mtx_);

            threads::thread_id_repr_type self_id = threads::get_self_id().get();
            if (owner_id_ != threads::invalid_thread_id_repr)
            {
                threads::thread_state_ex_enum const reason =
                    cond_.wait_until(l, abs_time, ec);
                if (ec) { HPX_ITT_SYNC_CANCEL(this); return false; }

                if (reason == threads::wait_signaled) //-V110
                {
                    HPX_ITT_SYNC_CANCEL(this);
                    return false;
                }
            }

            util::register_lock(this);
            HPX_ITT_SYNC_ACQUIRED(this);
            owner_id_ = self_id;
            return true;
        }
Exemple #4
0
 void lock()
 {
     HPX_ITT_SYNC_PREPARE(this);
     m.lock();
     HPX_ITT_SYNC_ACQUIRED(this);
     util::register_lock(this);
 }
Exemple #5
0
 void lock()
 {
     HPX_ITT_SYNC_PREPARE(&sp_);
     sp_.lock();
     HPX_ITT_SYNC_ACQUIRED(&sp_);
     util::register_lock(&sp_);
 }
Exemple #6
0
        // Note: we deliberately don't register this lock with the lock
        //       tracking to avoid false positives. We know that gid_types need
        //       to be locked while suspension.
        void lock()
        {
            HPX_ITT_SYNC_PREPARE(this);

            for (std::size_t k = 0; !acquire_lock(); ++k)
            {
                lcos::local::spinlock::yield(k);
            }

            HPX_ITT_SYNC_ACQUIRED(this);
        }
Exemple #7
0
        void lock()
        {
            HPX_ITT_SYNC_PREPARE(this);

            for (std::size_t k = 0; !try_lock(); ++k)
            {
            }

            HPX_ITT_SYNC_ACQUIRED(this);
            util::register_lock(this);
        }
Exemple #8
0
 bool try_lock()
 {
     HPX_ITT_SYNC_PREPARE(this);
     if (m.try_lock()) {
         HPX_ITT_SYNC_ACQUIRED(this);
         util::register_lock(this);
         return true;
     }
     HPX_ITT_SYNC_CANCEL(this);
     return false;
 }
Exemple #9
0
        void lock()
        {
            HPX_ITT_SYNC_PREPARE(this);

            for (std::size_t k = 0; !acquire_lock(); ++k)
            {
                spinlock::yield(k);
            }

            HPX_ITT_SYNC_ACQUIRED(this);
            util::register_lock(this);
        }
Exemple #10
0
        bool try_lock()
        {
            HPX_ITT_SYNC_PREPARE(this);

            if (acquire_lock())
            {
                HPX_ITT_SYNC_ACQUIRED(this);
                return true;
            }

            HPX_ITT_SYNC_CANCEL(this);
            return false;
        }
Exemple #11
0
        // Note: we deliberately don't register this lock with the lock
        //       tracking to avoid false positives. We know that gid_types need
        //       to be locked while suspension.
        void lock()
        {
            HPX_ITT_SYNC_PREPARE(this);

            for (std::size_t k = 0; !acquire_lock(); ++k)
            {
                util::detail::yield_k(k, "hpx::naming::gid_type::lock");
            }

            util::register_lock(this);

            HPX_ITT_SYNC_ACQUIRED(this);
        }
Exemple #12
0
        bool try_lock()
        {
            HPX_ITT_SYNC_PREPARE(this);

            bool r = acquire_lock(); //-V707

            if (r) {
                HPX_ITT_SYNC_ACQUIRED(this);
                util::register_lock(this);
                return true;
            }

            HPX_ITT_SYNC_CANCEL(this);
            return false;
        }
Exemple #13
0
        bool try_lock(char const* description, error_code& ec = throws)
        {
            HPX_ASSERT(threads::get_self_ptr() != 0);

            HPX_ITT_SYNC_PREPARE(this);
            mutex_type::scoped_lock l(mtx_);

            threads::thread_id_repr_type self_id = threads::get_self_id().get();
            if (owner_id_ != threads::invalid_thread_id_repr)
            {
                HPX_ITT_SYNC_CANCEL(this);
                return false;
            }

            util::register_lock(this);
            HPX_ITT_SYNC_ACQUIRED(this);
            owner_id_ = self_id;
            return true;
        }
Exemple #14
0
        bool try_lock()
        {
            HPX_ITT_SYNC_PREPARE(this);

#if !defined( BOOST_SP_HAS_SYNC )
            boost::uint64_t r = BOOST_INTERLOCKED_EXCHANGE(&v_, 1);
            BOOST_COMPILER_FENCE
#else
            boost::uint64_t r = __sync_lock_test_and_set(&v_, 1);
#endif

            if (r == 0) {
                HPX_ITT_SYNC_ACQUIRED(this);
                util::register_lock(this);
                return true;
            }

            HPX_ITT_SYNC_CANCEL(this);
            return false;
        }
Exemple #15
0
 void lock()
 {
     HPX_ITT_SYNC_PREPARE(&sp_);
     sp_.lock();
     HPX_ITT_SYNC_ACQUIRED(&sp_);
 }