Ticket #7238: 7238.patch

File 7238.patch, 1.7 KB (added by viboes, 10 years ago)

Please, could you try this patch?

  • pthread/thread.cpp

     
    432432        sleep_for(const chrono::nanoseconds& ns)
    433433        {
    434434            using namespace chrono;
    435             if (ns >= nanoseconds::zero())
     435            boost::detail::thread_data_base* const thread_info=boost::detail::get_current_thread_data();
     436
     437            if(thread_info)
    436438            {
     439              unique_lock<mutex> lk(thread_info->sleep_mutex);
     440              while(cv_status::no_timeout==thread_info->sleep_condition.wait_for(lk,ns)) {}
     441            }
     442            else
     443            {
     444              if (ns >= nanoseconds::zero())
     445              {
     446
     447  #   if defined(BOOST_HAS_PTHREAD_DELAY_NP)
    437448                timespec ts;
    438449                ts.tv_sec = static_cast<long>(duration_cast<seconds>(ns).count());
    439450                ts.tv_nsec = static_cast<long>((ns - seconds(ts.tv_sec)).count());
    440 
    441 #   if defined(BOOST_HAS_PTHREAD_DELAY_NP)
    442451                BOOST_VERIFY(!pthread_delay_np(&ts));
    443 #   elif defined(BOOST_HAS_NANOSLEEP)
     452  #   elif defined(BOOST_HAS_NANOSLEEP)
     453                timespec ts;
     454                ts.tv_sec = static_cast<long>(duration_cast<seconds>(ns).count());
     455                ts.tv_nsec = static_cast<long>((ns - seconds(ts.tv_sec)).count());
    444456                //  nanosleep takes a timespec that is an offset, not
    445457                //  an absolute time.
    446458                nanosleep(&ts, 0);
    447 #   else
     459  #   else
    448460                mutex mx;
    449461                mutex::scoped_lock lock(mx);
    450462                condition_variable cond;
    451463                cond.wait_for(lock, ns);
    452 #   endif
     464  #   endif
     465              }
    453466            }
    454467        }
    455468#endif