Ticket #7422: 7422_trunk.patch

File 7422_trunk.patch, 4.9 KB (added by viboes, 10 years ago)
  • boost/thread/pthread/condition_variable.hpp

     
    5757
    5858    inline void condition_variable::wait(unique_lock<mutex>& m)
    5959    {
     60      if(! m.owns_lock())
     61      {
     62          boost::throw_exception(condition_error(-1, "boost::condition_variable::wait precondition"));
     63      }
    6064        int res=0;
    6165        {
    62             thread_cv_detail::lock_on_exit<unique_lock<mutex> > guard;
    6366#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
     67          thread_cv_detail::lock_on_exit<unique_lock<mutex> > guard;
    6468            detail::interruption_checker check_for_interruption(&internal_mutex,&cond);
    65 #else
    66             boost::pthread::pthread_mutex_scoped_lock check_for_interruption(&internal_mutex);
    67 #endif
    6869            guard.activate(m);
    6970            do {
    7071              res = pthread_cond_wait(&cond,&internal_mutex);
    7172            } while (res == EINTR);
     73#else
     74            //boost::pthread::pthread_mutex_scoped_lock check_for_interruption(&internal_mutex);
     75            pthread_mutex_t* the_mutex = m.mutex()->native_handle();
     76            do {
     77              res = pthread_cond_wait(&cond,the_mutex);
     78            } while (res == EINTR);
     79#endif
    7280        }
    7381#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
    7482        this_thread::interruption_point();
     
    8391                unique_lock<mutex>& m,
    8492                struct timespec const &timeout)
    8593    {
     94#if defined BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED
    8695        if (!m.owns_lock())
    8796        {
    8897            boost::throw_exception(condition_error(EPERM, "condition_variable do_wait_until: mutex not locked"));
    8998        }
    90 
     99#endif
    91100        thread_cv_detail::lock_on_exit<unique_lock<mutex> > guard;
    92101        int cond_res;
    93102        {
    94103#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
    95104            detail::interruption_checker check_for_interruption(&internal_mutex,&cond);
     105            guard.activate(m);
     106            cond_res=pthread_cond_timedwait(&cond,&internal_mutex,&timeout);
    96107#else
    97             boost::pthread::pthread_mutex_scoped_lock check_for_interruption(&internal_mutex);
     108            //boost::pthread::pthread_mutex_scoped_lock check_for_interruption(&internal_mutex);
     109            pthread_mutex_t* the_mutex = m.mutex()->native_handle();
     110            cond_res=pthread_cond_timedwait(&cond,the_mutex,&timeout);
    98111#endif
    99             guard.activate(m);
    100             cond_res=pthread_cond_timedwait(&cond,&internal_mutex,&timeout);
    101112        }
    102113#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
    103114        this_thread::interruption_point();
     
    115126
    116127    inline void condition_variable::notify_one() BOOST_NOEXCEPT
    117128    {
     129#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
    118130        boost::pthread::pthread_mutex_scoped_lock internal_lock(&internal_mutex);
     131#endif
    119132        BOOST_VERIFY(!pthread_cond_signal(&cond));
    120133    }
    121134
    122135    inline void condition_variable::notify_all() BOOST_NOEXCEPT
    123136    {
     137#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
    124138        boost::pthread::pthread_mutex_scoped_lock internal_lock(&internal_mutex);
     139#endif
    125140        BOOST_VERIFY(!pthread_cond_broadcast(&cond));
    126141    }
    127142
  • boost/thread/pthread/condition_variable_fwd.hpp

     
    3232    class condition_variable
    3333    {
    3434    private:
     35//#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
    3536        pthread_mutex_t internal_mutex;
     37//#endif
    3638        pthread_cond_t cond;
    3739
    3840    public:
     
    5355      BOOST_THREAD_NO_COPYABLE(condition_variable)
    5456        condition_variable()
    5557        {
     58#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
    5659            int const res=pthread_mutex_init(&internal_mutex,NULL);
    5760            if(res)
    5861            {
    5962                boost::throw_exception(thread_resource_error(res, "boost:: condition_variable constructor failed in pthread_mutex_init"));
    6063            }
     64#endif
    6165            int const res2=pthread_cond_init(&cond,NULL);
    6266            if(res2)
    6367            {
     68#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
    6469                BOOST_VERIFY(!pthread_mutex_destroy(&internal_mutex));
     70#endif
    6571                boost::throw_exception(thread_resource_error(res2, "boost:: condition_variable constructor failed in pthread_cond_init"));
    6672            }
    6773        }
    6874        ~condition_variable()
    6975        {
    7076            int ret;
     77#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
    7178            do {
    7279              ret = pthread_mutex_destroy(&internal_mutex);
    7380            } while (ret == EINTR);
    7481            BOOST_ASSERT(!ret);
     82#endif
    7583            do {
    7684              ret = pthread_cond_destroy(&cond);
    7785            } while (ret == EINTR);