MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / ChangeState

Method ChangeState

tensorflow/lite/experimental/ruy/thread_pool.cc:60–100  ·  view source on GitHub ↗

Changes State; may be called from either the worker thread or the master thread; however, not all state transitions are legal, which is guarded by assertions. The Task argument is to be used only with new_state==HasWork. It specifies the Task being handed to this Thread.

Source from the content-addressed store, hash-verified

58 // The Task argument is to be used only with new_state==HasWork.
59 // It specifies the Task being handed to this Thread.
60 void ChangeState(State new_state, Task* task = nullptr) {
61 state_mutex_.lock();
62 State old_state = state_.load(std::memory_order_relaxed);
63 RUY_DCHECK(old_state != new_state);
64 switch (old_state) {
65 case State::Startup:
66 RUY_DCHECK(new_state == State::Ready);
67 break;
68 case State::Ready:
69 RUY_DCHECK(new_state == State::HasWork ||
70 new_state == State::ExitAsSoonAsPossible);
71 break;
72 case State::HasWork:
73 RUY_DCHECK(new_state == State::Ready ||
74 new_state == State::ExitAsSoonAsPossible);
75 break;
76 default:
77 abort();
78 }
79 switch (new_state) {
80 case State::Ready:
81 if (task_) {
82 // Doing work is part of reverting to 'ready' state.
83 task_->Run();
84 task_ = nullptr;
85 }
86 break;
87 case State::HasWork:
88 RUY_DCHECK(!task_);
89 task_ = task;
90 break;
91 default:
92 break;
93 }
94 state_.store(new_state, std::memory_order_relaxed);
95 state_cond_.notify_all();
96 state_mutex_.unlock();
97 if (new_state == State::Ready) {
98 counter_to_decrement_when_ready_->DecrementCount();
99 }
100 }
101
102 static void ThreadFunc(Thread* arg) { arg->ThreadFuncImpl(); }
103

Callers

nothing calls this directly

Calls 6

notify_allMethod · 0.80
lockMethod · 0.45
loadMethod · 0.45
RunMethod · 0.45
unlockMethod · 0.45
DecrementCountMethod · 0.45

Tested by

no test coverage detected