yannan-wyn commented on code in PR #3270:
URL: https://github.com/apache/brpc/pull/3270#discussion_r3090599130
##########
src/bthread/task_control.cpp:
##########
@@ -689,4 +749,117 @@ std::vector<bthread_t> TaskControl::get_living_bthreads()
{
return living_bthread_ids;
}
+void TaskControl::push_priority_queue(bthread_tag_t tag, bthread_t tid) {
+ if (!_enable_priority_queue || _priority_shards[tag].empty()) {
+ fallback_enqueue(tag, tid);
+ return;
+ }
+ auto& shards = _priority_shards[tag];
+ const size_t nshard = shards.size();
+
+ // thread_local round-robin, zero contention
+ static BAIDU_THREAD_LOCAL size_t tl_rr = 0;
+ size_t start = tl_rr++ % nshard;
+
+ // Prefer shards that have an active owner (not draining)
+ for (size_t i = 0; i < nshard; ++i) {
+ size_t idx = (start + i) % nshard;
+ if (shards[idx]->owner.load(butil::memory_order_relaxed) != NULL &&
+ !shards[idx]->draining.load(butil::memory_order_relaxed)) {
+ shards[idx]->inbound.Enqueue(tid);
+ return;
+ }
+ }
+
+ // All shards ownerless, fallback to round-robin pick
+ shards[start]->inbound.Enqueue(tid);
Review Comment:
if no active owner , just fallback to regular queue
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]