@@ -138,8 +138,8 @@ void ChannelImpl<T>::Send(T *item) {
138
138
139
139
// If channel is closed, throw exception
140
140
if (closed_) {
141
- lock.unlock ();
142
141
send_return ();
142
+ lock.unlock ();
143
143
PADDLE_THROW (" Cannot send on closed channel" );
144
144
}
145
145
@@ -152,11 +152,9 @@ void ChannelImpl<T>::Send(T *item) {
152
152
if (m != nullptr ) {
153
153
*(m->data ) = std::move (*item);
154
154
m->Notify ();
155
- lock.unlock ();
156
155
send_return ();
157
156
return ;
158
157
} else {
159
- lock.unlock ();
160
158
Send (item);
161
159
send_return ();
162
160
return ;
@@ -169,8 +167,6 @@ void ChannelImpl<T>::Send(T *item) {
169
167
if (buf_.size () < cap_) {
170
168
// Copy to buffer
171
169
buf_.push_back (std::move (*item));
172
- // Release lock and return true
173
- lock.unlock ();
174
170
send_return ();
175
171
return ;
176
172
}
@@ -181,8 +177,8 @@ void ChannelImpl<T>::Send(T *item) {
181
177
sendq.push_back (m);
182
178
m->Wait (lock);
183
179
if (m->chan_closed ) {
184
- lock.unlock ();
185
180
send_return ();
181
+ lock.unlock ();
186
182
PADDLE_THROW (" Cannot send on closed channel" );
187
183
}
188
184
send_return ();
@@ -195,10 +191,7 @@ bool ChannelImpl<T>::Receive(T *item) {
195
191
196
192
// If channel is closed and buffer is empty or
197
193
// channel is unbuffered
198
- if (closed_ && buf_.empty ()) {
199
- lock.unlock ();
200
- return recv_return (false );
201
- }
194
+ if (closed_ && buf_.empty ()) return recv_return (false );
202
195
203
196
// If there is a sender, directly receive the value we want
204
197
// from the sender. In case of a buffered channel, read from
@@ -229,7 +222,6 @@ bool ChannelImpl<T>::Receive(T *item) {
229
222
} else
230
223
return recv_return (Receive (item));
231
224
}
232
- lock.unlock ();
233
225
return recv_return (true );
234
226
}
235
227
@@ -238,8 +230,7 @@ bool ChannelImpl<T>::Receive(T *item) {
238
230
// Directly read from buffer
239
231
*item = std::move (buf_.front ());
240
232
buf_.pop_front ();
241
- // Release lock and return true
242
- lock.unlock ();
233
+ // return true
243
234
return recv_return (true );
244
235
}
245
236
0 commit comments