2
0
mirror of https://github.com/boostorg/fiber.git synced 2026-02-21 15:02:29 +00:00

enable/disable atomic<> with BOOST_FIBERS_THREADSAFE

This commit is contained in:
Oliver Kowalke
2015-06-16 18:49:28 +02:00
parent 61dc492f31
commit 2002dba9d3
19 changed files with 284 additions and 23 deletions

View File

@@ -80,7 +80,6 @@ fiber_manager::next_wakeup() {
if ( wqueue_.empty() ) {
return std::chrono::high_resolution_clock::now() + wait_interval_;
} else {
//FIXME: search for the closest time_point to now() in waiting-queue
std::chrono::high_resolution_clock::time_point wakeup( wqueue_.top()->time_point() );
if ( (std::chrono::high_resolution_clock::time_point::max)() == wakeup) {
return std::chrono::high_resolution_clock::now() + wait_interval_;
@@ -129,16 +128,18 @@ fiber_manager::run() {
}
}
#if defined(BOOST_FIBERS_THREADSAFE)
void
fiber_manager::wait( std::unique_lock< detail::spinlock > & lk) {
wait_until(
std::chrono::high_resolution_clock::time_point( (std::chrono::high_resolution_clock::duration::max)() ),
std::chrono::high_resolution_clock::time_point(
(std::chrono::high_resolution_clock::duration::max)() ),
lk);
}
bool
fiber_manager::wait_until( std::chrono::high_resolution_clock::time_point const& timeout_time,
std::unique_lock< detail::spinlock > & lk) {
std::unique_lock< detail::spinlock > & lk) {
BOOST_ASSERT( active_fiber_->is_running() );
// set active-fiber to state_waiting
@@ -154,6 +155,30 @@ fiber_manager::wait_until( std::chrono::high_resolution_clock::time_point const&
return std::chrono::high_resolution_clock::now() < timeout_time;
}
#else
void
fiber_manager::wait() {
wait_until(
std::chrono::high_resolution_clock::time_point(
(std::chrono::high_resolution_clock::duration::max)() ) );
}
bool
fiber_manager::wait_until( std::chrono::high_resolution_clock::time_point const& timeout_time) {
BOOST_ASSERT( active_fiber_->is_running() );
// set active-fiber to state_waiting
active_fiber_->set_waiting();
// push active-fiber to wqueue_
active_fiber_->time_point( timeout_time);
wqueue_.push( active_fiber_);
// switch to another fiber
run();
// fiber is resumed
return std::chrono::high_resolution_clock::now() < timeout_time;
}
#endif
void
fiber_manager::yield() {