| 183 | |
| 184 | public: |
| 185 | void ComputeAsync(OpKernelContext* c, DoneCallback done) override { |
| 186 | Mutex* mutex = nullptr; |
| 187 | OP_REQUIRES_OK_ASYNC( |
| 188 | c, |
| 189 | LookupOrCreateResource<Mutex>(c, HandleFromInput(c, 0), &mutex, |
| 190 | [c](Mutex** ptr) { |
| 191 | *ptr = new Mutex( |
| 192 | c, HandleFromInput(c, 0).name()); |
| 193 | return Status::OK(); |
| 194 | }), |
| 195 | done); |
| 196 | |
| 197 | Tensor* variant; |
| 198 | OP_REQUIRES_OK_ASYNC(c, c->allocate_output(0, TensorShape({}), &variant), |
| 199 | done); |
| 200 | |
| 201 | mutex->AcquireAsync( |
| 202 | c, std::bind( |
| 203 | [c, variant, mutex](DoneCallback done_, |
| 204 | // End of bound arguments. |
| 205 | const Status& s, |
| 206 | Mutex::SharedLockReleaser&& lock) { |
| 207 | VLOG(2) << "Finished locking mutex " << mutex |
| 208 | << " with lock: " << lock.shared_lock.get() |
| 209 | << " status: " << s.ToString(); |
| 210 | if (s.ok()) { |
| 211 | variant->scalar<Variant>()() = std::move(lock); |
| 212 | } else { |
| 213 | c->SetStatus(s); |
| 214 | } |
| 215 | mutex->Unref(); |
| 216 | done_(); |
| 217 | }, |
| 218 | std::move(done), std::placeholders::_1, std::placeholders::_2)); |
| 219 | } |
| 220 | }; |
| 221 | |
| 222 | class ConsumeMutexLockOp : public OpKernel { |
nothing calls this directly
no test coverage detected