*/
#pragma once
+#include <cstdint>
+
namespace folly { namespace fibers {
/**
/**
* Called when a task is about to start executing.
+ *
+ * @param id Unique id for the fiber which is starting.
+ */
+ virtual void starting(uintptr_t id) noexcept = 0;
+
+ /**
+ * Called when a task is ready to run.
+ *
+ * @param id Unique id for the fiber which is ready to run.
*/
- virtual void starting() noexcept = 0;
+ virtual void runnable(uintptr_t id) noexcept = 0;
/**
* Called just after a task stops executing.
+ *
+ * @param id Unique id for the fiber which is stopping.
*/
- virtual void stopped() noexcept = 0;
+ virtual void stopped(uintptr_t id) noexcept = 0;
};
}} // namespace folly::fibers
data_ = data;
state_ = READY_TO_RUN;
+ if (fiberManager_.observer_) {
+ fiberManager_.observer_->runnable(reinterpret_cast<uintptr_t>(this));
+ }
+
if (LIKELY(threadId_ == localThreadId())) {
fiberManager_.readyFibers_.push_back(*this);
fiberManager_.ensureLoopScheduled();
fiber->state_ == Fiber::READY_TO_RUN);
currentFiber_ = fiber;
if (observer_) {
- observer_->starting();
+ observer_->starting(reinterpret_cast<uintptr_t>(fiber));
}
while (fiber->state_ == Fiber::NOT_STARTED ||
awaitFunc_(*fiber);
awaitFunc_ = nullptr;
if (observer_) {
- observer_->stopped();
+ observer_->stopped(reinterpret_cast<uintptr_t>(fiber));
}
currentFiber_ = nullptr;
} else if (fiber->state_ == Fiber::INVALID) {
}
// Make sure LocalData is not accessible from its destructor
if (observer_) {
- observer_->stopped();
+ observer_->stopped(reinterpret_cast<uintptr_t>(fiber));
}
currentFiber_ = nullptr;
fiber->localData_.reset();
}
} else if (fiber->state_ == Fiber::YIELDED) {
if (observer_) {
- observer_->stopped();
+ observer_->stopped(reinterpret_cast<uintptr_t>(fiber));
}
currentFiber_ = nullptr;
fiber->state_ = Fiber::READY_TO_RUN;
fiber->setFunction(std::move(task->func));
fiber->data_ = reinterpret_cast<intptr_t>(fiber);
+ if (observer_) {
+ observer_->runnable(reinterpret_cast<uintptr_t>(fiber));
+ }
runReadyFiber(fiber);
hadRemoteFiber = true;
}
);
}
+ if (observer_) {
+ for (auto& yielded : yieldedFibers_) {
+ observer_->runnable(reinterpret_cast<uintptr_t>(&yielded));
+ }
+ }
readyFibers_.splice(readyFibers_.end(), yieldedFibers_);
return fibersActive_ > 0;
fiber->data_ = reinterpret_cast<intptr_t>(fiber);
readyFibers_.push_back(*fiber);
+ if (observer_) {
+ observer_->runnable(reinterpret_cast<uintptr_t>(fiber));
+ }
ensureLoopScheduled();
}
fiber->data_ = reinterpret_cast<intptr_t>(fiber);
readyFibers_.push_back(*fiber);
+ if (observer_) {
+ observer_->runnable(reinterpret_cast<uintptr_t>(fiber));
+ }
ensureLoopScheduled();
}