MCPcopy Create free account
hub / github.com/alibaba/PhotonLibOS / AtomicRunQ

Class AtomicRunQ

thread/thread.cpp:624–720  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

622 struct Switch { thread *from, *to; };
623
624 class AtomicRunQ : public RunQ {
625 public:
626 vcpu_t* vcpu;
627 mutable asymmetric_spinLock* plock;
628 AtomicRunQ(const RunQ& runq = RunQ()) : RunQ(runq) {
629 vcpu = current->get_vcpu();
630 (plock = &vcpu->runq_lock) -> foreground_lock();
631 }
632 mutable bool update_current = false;
633 void set_current(thread* th) const {
634 current = th;
635 update_current = true;
636 }
637 ~AtomicRunQ() {
638 if (update_current)
639 *pc = current;
640 plock->foreground_unlock();
641 }
642 static void prefetch_context(thread* from, thread* to)
643 {
644#ifdef CONTEXT_PREFETCHING
645 const int CACHE_LINE_SIZE = 64;
646 auto f = *from->stack.pointer_ref();
647 __builtin_prefetch(f, 1);
648 // __builtin_prefetch((char*)f + CACHE_LINE_SIZE, 1);
649 auto t = *to->stack.pointer_ref();
650 __builtin_prefetch(t, 0);
651 // __builtin_prefetch((char*)t + CACHE_LINE_SIZE, 0);
652#endif
653 }
654 Switch remove_current(states new_state) const {
655 assert(!current->single());
656 auto from = current;
657 auto to = from->remove_from_list();
658 set_current(to);
659 prefetch_context(from, to);
660 from->state = new_state;
661 to->state = states::RUNNING;
662 return {from, to};
663 }
664 Switch _do_goto(thread* to) const {
665 auto from = current;
666 prefetch_context(from, to);
667 from->state = states::READY;
668 to->state = states::RUNNING;
669 set_current(to);
670 return {from, to};
671 }
672 Switch goto_next() const {
673 assert(!current->single());
674 return _do_goto(current->next());
675 }
676 Switch try_goto(thread* th) const {
677 assert(th->vcpu == vcpu);
678 th->remove_from_list();
679 current->insert_after(th);
680 return _do_goto(th);
681 }

Callers 14

dieMethod · 0.85
resume_threads_inlinedFunction · 0.85
thread_yieldFunction · 0.85
thread_yield_fastFunction · 0.85
thread_yield_toFunction · 0.85
prepare_usleepFunction · 0.85
thread_usleep_deferFunction · 0.85
stack_pages_gcFunction · 0.85
idlerFunction · 0.85
wait_allFunction · 0.85
defer_migrate_currentFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected