@@ -56,7 +56,7 @@ class VarHandle {
56
56
const std::string& name,
57
57
const platform::DeviceContext* p_ctx = nullptr ,
58
58
const framework::Scope* p_scope = nullptr )
59
- : ok_( kVarHandleDefaultState ) {
59
+ : status_( kDefaultState ) {
60
60
ep_ = ep;
61
61
ctx_ = p_ctx;
62
62
scope_ = p_scope;
@@ -68,27 +68,29 @@ class VarHandle {
68
68
69
69
public:
70
70
bool Wait () {
71
+ int ret = kDefaultState ;
71
72
{
72
73
std::unique_lock<std::mutex> lk (sync_mutex_);
73
- wait_cond_.wait (lk, [this ] { return ok_ != kVarHandleDefaultState ; });
74
+ wait_cond_.wait (lk, [this ] { return status_ != kDefaultState ; });
75
+ ret = status_;
74
76
}
75
- VLOG (7 ) << " VarHandle wait:" << ok_ ;
76
- return ok_ != 0 ;
77
+ VLOG (7 ) << " VarHandle wait:" << ret ;
78
+ return ret != kErrorState ;
77
79
}
78
80
79
81
void Finish (bool ok) {
80
82
{
81
83
std::unique_lock<std::mutex> lk (sync_mutex_);
82
- ok_ = ok;
84
+ status_ = ok ? kFinishState : kErrorState ;
83
85
}
84
86
VLOG (7 ) << " VarHandle finish:" << ok;
85
87
wait_cond_.notify_all ();
86
88
}
87
89
88
90
std::string String () const {
89
91
std::ostringstream s;
90
- s << method_ << " name:[" << name_ << " ], ep:[" << ep_ << " ], ok :[" << ok_
91
- << " ]" ;
92
+ s << method_ << " name:[" << name_ << " ], ep:[" << ep_ << " ], status :["
93
+ << status_ << " ]" ;
92
94
return s.str ();
93
95
}
94
96
@@ -111,9 +113,13 @@ class VarHandle {
111
113
protected:
112
114
std::mutex sync_mutex_;
113
115
std::condition_variable wait_cond_;
114
- int ok_;
115
116
116
- static const int kVarHandleDefaultState = -1 ;
117
+ enum VarHandleStatus {
118
+ kDefaultState = -1 ,
119
+ kErrorState = 0 ,
120
+ kFinishState = 1 ,
121
+ };
122
+ VarHandleStatus status_;
117
123
118
124
private:
119
125
DISABLE_COPY_AND_ASSIGN (VarHandle);
0 commit comments